Index: tests/badssl.csv ================================================================== --- tests/badssl.csv +++ tests/badssl.csv @@ -3,11 +3,30 @@ ,,,,,,,,,, command,# Constraints,,,,,,,,, command,source [file join [file dirname [info script]] common.tcl],,,,,,,,, ,,,,,,,,,, command,# Helper functions,,,,,,,,, -command,"proc badssl {url} {set port 443;lassign [split $url "":""] url port;if {$port eq """"} {set port 443};set cmd [list tls::socket -autoservername 1 -require 1];if {[info exists ::env(SSL_CERT_FILE)]} {lappend cmd -cafile $::env(SSL_CERT_FILE)};lappend cmd $url $port;set ch [eval $cmd];if {[catch {tls::handshake $ch} err]} {close $ch;return -code error $err} else {close $ch}}",,,,,,,,, +command,"proc badssl {url} { + set port 443 + lassign [split $url "":""] url port + if {$port eq """"} { + set port 443 + } + set cmd [list tls::socket -autoservername 1 -require 1] + if {[info exists ::env(SSL_CERT_FILE)]} { + lappend cmd -cafile $::env(SSL_CERT_FILE) + } + lappend cmd $url $port + set ch [eval $cmd] + if {[catch {tls::handshake $ch} err]} { + close $ch + return -code error $err + } else { + close $ch + } +} +",,,,,,,,, ,,,,,,,,,, command,# BadSSL.com Tests,,,,,,,,, BadSSL,1000-sans,,,badssl 1000-sans.badssl.com,,,"handshake failed: certificate verify failed due to ""certificate has expired""",,,1 BadSSL,10000-sans,,,badssl 10000-sans.badssl.com,,,handshake failed: excessive message size,,,1 BadSSL,3des,,,badssl 3des.badssl.com,,glob,handshake failed: * alert handshake failure,,,1 Index: tests/badssl.test ================================================================== --- tests/badssl.test +++ tests/badssl.test @@ -12,11 +12,30 @@ # Constraints source [file join [file dirname [info script]] common.tcl] # Helper functions -proc badssl {url} {set port 443;lassign [split $url ":"] url port;if {$port eq ""} {set port 443};set cmd [list tls::socket -autoservername 1 -require 1];if {[info exists ::env(SSL_CERT_FILE)]} {lappend cmd -cafile $::env(SSL_CERT_FILE)};lappend cmd $url $port;set ch [eval $cmd];if {[catch {tls::handshake $ch} err]} {close $ch;return -code error $err} else {close $ch}} +proc badssl {url} { + set port 443 + lassign [split $url ":"] url port + if {$port eq ""} { + set port 443 + } + set cmd [list tls::socket -autoservername 1 -require 1] + if {[info exists ::env(SSL_CERT_FILE)]} { + lappend cmd -cafile $::env(SSL_CERT_FILE) + } + lappend cmd $url $port + set ch [eval $cmd] + if {[catch {tls::handshake $ch} err]} { + close $ch + return -code error $err + } else { + close $ch + } +} + # BadSSL.com Tests test BadSSL-1.1 {1000-sans} -body { Index: tests/digest.csv ================================================================== --- tests/digest.csv +++ tests/digest.csv @@ -4,13 +4,40 @@ command,# Constraints,,,,,,,,, command,"::tcltest::testConstraint md4 [expr {""md4"" in [::tls::digests]}]",,,,,,,,, command,catch {tls::provider legacy},,,,,,,,, ,,,,,,,,,, command,# Helper functions - See common.tcl,,,,,,,,, -command,proc digest_read_chan {cmd filename args} {;set ch [open $filename rb];set bsize [fconfigure $ch -buffersize];set new [$cmd {*}$args -chan $ch];while {![eof $new]} {set md [read $new $bsize]};close $new;return $md},,,,,,,,, -command,proc digest_write_chan {cmd filename data args} {;set ch [open $filename wb];set new [$cmd {*}$args -chan $ch];puts -nonewline $new $data;flush $new;close $new;set ch [open $filename rb];set md [read $ch];close $ch;return $md},,,,,,,,, -command,proc digest_accumulate {string args} {;set cmd [{*}$args -command dcmd]; $cmd update [string range $string 0 20];$cmd update [string range $string 21 end];return [$cmd finalize]},$cmd update [string range $string 0 20];$cmd update [string range $string 21 end];return [$cmd finalize]},,,,,,,, +command,"proc digest_read_chan {cmd filename args} { + set ch [open $filename rb] + set bsize [fconfigure $ch -buffersize] + set new [$cmd {*}$args -chan $ch] + while {![eof $new]} { + set md [read $new $bsize] + } + close $new + return $md +} +",,,,,,,,, +command,"proc digest_write_chan {cmd filename data args} { + set ch [open $filename wb] + set new [$cmd {*}$args -chan $ch] + puts -nonewline $new $data + flush $new + close $new + set ch [open $filename rb] + set md [read $ch] + close $ch + return $md +} +",,,,,,,,, +command,"proc digest_accumulate {string args} { + set cmd [{*}$args -command dcmd] + $cmd update [string range $string 0 20] + $cmd update [string range $string 21 end] + return [$cmd finalize] +} +",,,,,,,, ,,,,,,,,,, command,"set test_data ""Example string for message digest tests.\n""",,,,,,,,, command,"set test_file ""md_data.dat""",,,,,,,,, command,"set test_alt_file ""md_alt_data.dat""",,,,,,,,, command,"set test_key ""Example key""",,,,,,,,, Index: tests/digest.test ================================================================== --- tests/digest.test +++ tests/digest.test @@ -13,13 +13,40 @@ # Constraints ::tcltest::testConstraint md4 [expr {"md4" in [::tls::digests]}] catch {tls::provider legacy} # Helper functions - See common.tcl -proc digest_read_chan {cmd filename args} {;set ch [open $filename rb];set bsize [fconfigure $ch -buffersize];set new [$cmd {*}$args -chan $ch];while {![eof $new]} {set md [read $new $bsize]};close $new;return $md} -proc digest_write_chan {cmd filename data args} {;set ch [open $filename wb];set new [$cmd {*}$args -chan $ch];puts -nonewline $new $data;flush $new;close $new;set ch [open $filename rb];set md [read $ch];close $ch;return $md} -proc digest_accumulate {string args} {;set cmd [{*}$args -command dcmd]; $cmd update [string range $string 0 20];$cmd update [string range $string 21 end];return [$cmd finalize]} +proc digest_read_chan {cmd filename args} { + set ch [open $filename rb] + set bsize [fconfigure $ch -buffersize] + set new [$cmd {*}$args -chan $ch] + while {![eof $new]} { + set md [read $new $bsize] + } + close $new + return $md +} + +proc digest_write_chan {cmd filename data args} { + set ch [open $filename wb] + set new [$cmd {*}$args -chan $ch] + puts -nonewline $new $data + flush $new + close $new + set ch [open $filename rb] + set md [read $ch] + close $ch + return $md +} + +proc digest_accumulate {string args} { + set cmd [{*}$args -command dcmd] + $cmd update [string range $string 0 20] + $cmd update [string range $string 21 end] + return [$cmd finalize] +} + set test_data "Example string for message digest tests.\n" set test_file "md_data.dat" set test_alt_file "md_alt_data.dat" set test_key "Example key" Index: tests/encrypt.csv ================================================================== --- tests/encrypt.csv +++ tests/encrypt.csv @@ -1,14 +1,55 @@ # Group,Name,Constraints,Setup,Body,Cleanup,Match,Result,Output,Error Output,Return Codes command,package require tls,,,,,,,,, ,,,,,,,,,, command,# Helper functions - See common.tcl,,,,,,,,, -command,"proc read_chan {filename args} {set ch [open $filename rb];set bsize [fconfigure $ch -buffersize];set new [{*}$args -chan $ch];set dat """";while {![eof $new]} {append dat [read $new $bsize]};close $new;return $dat}",,,,,,,,, -command,proc write_chan {filename data args} {set ch [open $filename wb];set new [{*}$args -chan $ch];puts -nonewline $new $data;flush $new;close $new;set ch [open $filename rb];set dat [read $ch];close $ch;return $dat},,,,,,,,, -command,"proc accumulate {string args} {set cmd [{*}$args -command dcmd];set ::dat """";append ::dat [$cmd update [string range $string 0 20]];append ::dat [$cmd update [string range $string 21 end]];append ::dat [$cmd finalize]}",$cmd update [string range $string 0 20];$cmd update [string range $string 21 end];return [$cmd finalize]},,,,,,,, -command,proc get_file_hex {filename} {set ch [open $filename rb];set data [read $ch];close $ch;return [binary encode hex $data]},,,,,,,,, -command,proc get_file_text {filename} {set ch [open $filename r];set data [read $ch];close $ch;return $data},,,,,,,,, +command,"proc read_chan {filename args} { + set ch [open $filename rb] + set bsize [fconfigure $ch -buffersize] + set new [{*}$args -chan $ch] + set dat """" + while {![eof $new]} { + append dat [read $new $bsize] + } + close $new + return $dat +} +",,,,,,,,, +command,"proc write_chan {filename data args} { + set ch [open $filename wb] + set new [{*}$args -chan $ch] + puts -nonewline $new $data + flush $new + close $new + set ch [open $filename rb] + set dat [read $ch] + close $ch + return $dat +} +",,,,,,,,, +command,"proc accumulate {string args} { + set cmd [{*}$args -command dcmd] + set ::dat """" + append ::dat [$cmd update [string range $string 0 20]] + append ::dat [$cmd update [string range $string 21 end]] + append ::dat [$cmd finalize] +} +",,,,,,,, +command,"proc get_file_hex {filename} { + set ch [open $filename rb] + set data [read $ch] + close $ch + return [binary encode hex $data] +} +",,,,,,,,, +command,"proc get_file_text {filename} { + set ch [open $filename r] + set data [read $ch] + close $ch + return $data +} +",,,,,,,,, ,,,,,,,,,, command,"set test_data ""Example string for message digest tests.\n""",,,,,,,,, command,"set unencrypted_file ""unencrypted_data.dat""",,,,,,,,, command,"set encrypted_file ""encrypted_data.dat""",,,,,,,,, command,"set alt_file ""result_data.dat""",,,,,,,,, Index: tests/encrypt.test ================================================================== --- tests/encrypt.test +++ tests/encrypt.test @@ -9,15 +9,56 @@ set auto_path [concat [list [file dirname [file dirname [info script]]]] $auto_path] package require tls # Helper functions - See common.tcl -proc read_chan {filename args} {set ch [open $filename rb];set bsize [fconfigure $ch -buffersize];set new [{*}$args -chan $ch];set dat "";while {![eof $new]} {append dat [read $new $bsize]};close $new;return $dat} -proc write_chan {filename data args} {set ch [open $filename wb];set new [{*}$args -chan $ch];puts -nonewline $new $data;flush $new;close $new;set ch [open $filename rb];set dat [read $ch];close $ch;return $dat} -proc accumulate {string args} {set cmd [{*}$args -command dcmd];set ::dat "";append ::dat [$cmd update [string range $string 0 20]];append ::dat [$cmd update [string range $string 21 end]];append ::dat [$cmd finalize]} -proc get_file_hex {filename} {set ch [open $filename rb];set data [read $ch];close $ch;return [binary encode hex $data]} -proc get_file_text {filename} {set ch [open $filename r];set data [read $ch];close $ch;return $data} +proc read_chan {filename args} { + set ch [open $filename rb] + set bsize [fconfigure $ch -buffersize] + set new [{*}$args -chan $ch] + set dat "" + while {![eof $new]} { + append dat [read $new $bsize] + } + close $new + return $dat +} + +proc write_chan {filename data args} { + set ch [open $filename wb] + set new [{*}$args -chan $ch] + puts -nonewline $new $data + flush $new + close $new + set ch [open $filename rb] + set dat [read $ch] + close $ch + return $dat +} + +proc accumulate {string args} { + set cmd [{*}$args -command dcmd] + set ::dat "" + append ::dat [$cmd update [string range $string 0 20]] + append ::dat [$cmd update [string range $string 21 end]] + append ::dat [$cmd finalize] +} + +proc get_file_hex {filename} { + set ch [open $filename rb] + set data [read $ch] + close $ch + return [binary encode hex $data] +} + +proc get_file_text {filename} { + set ch [open $filename r] + set data [read $ch] + close $ch + return $data +} + set test_data "Example string for message digest tests.\n" set unencrypted_file "unencrypted_data.dat" set encrypted_file "encrypted_data.dat" set alt_file "result_data.dat" Index: tests/info.csv ================================================================== --- tests/info.csv +++ tests/info.csv @@ -22,11 +22,14 @@ } } return [list ""missing"" $m ""unexpected"" $u] } ",,,,,,,,, -command,proc exec_get {delim args} {return [split [exec openssl {*}$args] $delim]},,,,,,,,, +command,"proc exec_get {delim args} { + return [split [exec openssl {*}$args] $delim] +} +",,,,,,,,, command,"proc exec_get_ciphers {} { set list [list] set data [exec openssl list -cipher-algorithms] foreach line [split $data ""\n""] { set line [string trim $line] @@ -61,11 +64,14 @@ lappend list [string trim $line] } return $list } ",,,,,,,,, -command,proc exec_get_macs {} {return [list cmac hmac]},,,,,,,,, +command,"proc exec_get_macs {} { + return [list cmac hmac] +} +",,,,,,,,, command,"proc list_tolower {list} { set result [list] foreach element $list { lappend result [string tolower $element] } Index: tests/info.test ================================================================== --- tests/info.test +++ tests/info.test @@ -31,11 +31,14 @@ } } return [list "missing" $m "unexpected" $u] } -proc exec_get {delim args} {return [split [exec openssl {*}$args] $delim]} +proc exec_get {delim args} { + return [split [exec openssl {*}$args] $delim] +} + proc exec_get_ciphers {} { set list [list] set data [exec openssl list -cipher-algorithms] foreach line [split $data "\n"] { set line [string trim $line] @@ -70,11 +73,14 @@ lappend list [string trim $line] } return $list } -proc exec_get_macs {} {return [list cmac hmac]} +proc exec_get_macs {} { + return [list cmac hmac] +} + proc list_tolower {list} { set result [list] foreach element $list { lappend result [string tolower $element] } Index: tests/make_test_files.tcl ================================================================== --- tests/make_test_files.tcl +++ tests/make_test_files.tcl @@ -72,10 +72,11 @@ set in [open $filename r] array set cases [list] # Open output test file set out [open [format %s.test [file rootname $filename]] w] + fconfigure $out -encoding utf-8 -translation {auto lf} array set cases [list] # Add setup commands to test file puts $out [format "# Auto generated test cases for %s" [file tail $filename]] #puts $out [format "# Auto generated test cases for %s created on %s" [file tail $filename] [clock format [clock seconds]]]