Index: tests/digest.test ================================================================== --- tests/digest.test +++ tests/digest.test @@ -12,32 +12,13 @@ # Constraints source common.tcl # 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" ADDED tests/encrypt.csv Index: tests/encrypt.csv ================================================================== --- /dev/null +++ tests/encrypt.csv @@ -0,0 +1,47 @@ +# Group,Name,Constraints,Setup,Body,Cleanup,Match,Result,Output,Error Output,Return Codes +command,package require tls,,,,,,,,, +,,,,,,,,,, +command,# Constraints,,,,,,,,, +command,source common.tcl,,,,,,,,, +,,,,,,,,,, +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,"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""",,,,,,,,, +command,"set test_key ""Example key""",,,,,,,,, +command,"set test_iv ""Example iv""",,,,,,,,, +command,::tcltest::makeFile $test_data $unencrypted_file,,,,,,,,, + ,,,,,,,,,, +command,# Test encrypt data,,,,,,,,, +command,set cipher aes-128-cbc,,,,,,,,, +command,"set hex_string ""3cea034398de64507abbc7bcf6acba55c7011100c9015c22b3c9c331d18479fed5e542ce02a3b89a0f750daf8e2a494e""",,,,,,,,, +Encrypt Decrypt Data,Encrypt aes-138-cbc,,,binary encode hex [set data [tls::encrypt -cipher $cipher -key $test_key -iv $test_iv -data $test_data]],,,$hex_string,,, +Encrypt Decrypt Data,Decrypt aes-128-cbc,,,tls::decrypt -cipher $cipher -key $test_key -iv $test_iv -data $data,,,$test_data,,, + ,,,,,,,,,, +command,# Test encrypt file,,,,,,,,, +Encrypt Decrypt File,Encrypt aes-138-cbc,,,tls::encrypt -cipher $cipher -key $test_key -iv $test_iv -infile $unencrypted_file -outfile $encrypted_file;get_file_hex $encrypted_file,,,$hex_string,,, +Encrypt Decrypt File,Decrypt aes-128-cbc,,,tls::decrypt -cipher $cipher -key $test_key -iv $test_iv -infile $encrypted_file -outfile $alt_file;get_file_text $alt_file,,,$test_data,,, + ,,,,,,,,,, +command,# Test encrypt using object command,,,,,,,,, +Encrypt Decrypt Command,Encrypt aes-138-cbc,,,accumulate $test_data tls::encrypt -cipher $cipher -key $test_key -iv $test_iv;binary encode hex $::dat,,,$hex_string,,, +Encrypt Decrypt Command,Decrypt aes-128-cbc,,,accumulate $::dat tls::decrypt -cipher $cipher -key $test_key -iv $test_iv;set ::dat,,,$test_data,,, + ,,,,,,,,,, +command,# Test encrypt using read channel,,,,,,,,, +Encrypt Decrypt Channel Read,Encrypt aes-138-cbc,,,binary encode hex [read_chan $unencrypted_file tls::encrypt -cipher $cipher -key $test_key -iv $test_iv],,,$hex_string,,, +Encrypt Decrypt Channel Read,Decrypt aes-138-cbc,,,read_chan $encrypted_file tls::decrypt -cipher $cipher -key $test_key -iv $test_iv,,,$test_data,,, + ,,,,,,,,,, +command,# Test encrypt using write channel,,,,,,,,, +Encrypt Decrypt Channel Write,Encrypt aes-138-cbc,,,binary encode hex [set data [write_chan $encrypted_file $test_data tls::encrypt -cipher $cipher -key $test_key -iv $test_iv]],,,$hex_string,,, +Encrypt Decrypt Channel Write,Decrypt aes-138-cbc,,,write_chan $alt_file $data tls::decrypt -cipher $cipher -key $test_key -iv $test_iv,,,$test_data,,, +,,,,,,,,,, +command,# Cleanup,,,,,,,,, +command,::tcltest::removeFile $unencrypted_file,,,,,,,,, +command,::tcltest::removeFile $encrypted_file,,,,,,,,, +command,::tcltest::removeFile $alt_file,,,,,,,,, ADDED tests/encrypt.test Index: tests/encrypt.test ================================================================== --- /dev/null +++ tests/encrypt.test @@ -0,0 +1,99 @@ +# Auto generated test cases for encrypt.csv + +# Load Tcl Test package +if {[lsearch [namespace children] ::tcltest] == -1} { + package require tcltest + namespace import ::tcltest::* +} + +set auto_path [concat [list [file dirname [file dirname [info script]]]] $auto_path] + +package require tls + +# Constraints +source common.tcl + +# 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} + +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" +set test_key "Example key" +set test_iv "Example iv" +::tcltest::makeFile $test_data $unencrypted_file + +# Test encrypt data +set cipher aes-128-cbc +set hex_string "3cea034398de64507abbc7bcf6acba55c7011100c9015c22b3c9c331d18479fed5e542ce02a3b89a0f750daf8e2a494e" + + +test Encrypt_Decrypt_Data-1.1 {Encrypt aes-138-cbc} -body { + binary encode hex [set data [tls::encrypt -cipher $cipher -key $test_key -iv $test_iv -data $test_data]] + } -result $hex_string + +test Encrypt_Decrypt_Data-1.2 {Decrypt aes-128-cbc} -body { + tls::decrypt -cipher $cipher -key $test_key -iv $test_iv -data $data + } -result $test_data + +# Test encrypt file + + +test Encrypt_Decrypt_File-2.1 {Encrypt aes-138-cbc} -body { + tls::encrypt -cipher $cipher -key $test_key -iv $test_iv -infile $unencrypted_file -outfile $encrypted_file + get_file_hex $encrypted_file + } -result $hex_string + +test Encrypt_Decrypt_File-2.2 {Decrypt aes-128-cbc} -body { + tls::decrypt -cipher $cipher -key $test_key -iv $test_iv -infile $encrypted_file -outfile $alt_file + get_file_text $alt_file + } -result $test_data + +# Test encrypt using object command + + +test Encrypt_Decrypt_Command-3.1 {Encrypt aes-138-cbc} -body { + accumulate $test_data tls::encrypt -cipher $cipher -key $test_key -iv $test_iv + binary encode hex $::dat + } -result $hex_string + +test Encrypt_Decrypt_Command-3.2 {Decrypt aes-128-cbc} -body { + accumulate $::dat tls::decrypt -cipher $cipher -key $test_key -iv $test_iv + set ::dat + } -result $test_data + +# Test encrypt using read channel + + +test Encrypt_Decrypt_Channel_Read-4.1 {Encrypt aes-138-cbc} -body { + binary encode hex [read_chan $unencrypted_file tls::encrypt -cipher $cipher -key $test_key -iv $test_iv] + } -result $hex_string + +test Encrypt_Decrypt_Channel_Read-4.2 {Decrypt aes-138-cbc} -body { + read_chan $encrypted_file tls::decrypt -cipher $cipher -key $test_key -iv $test_iv + } -result $test_data + +# Test encrypt using write channel + + +test Encrypt_Decrypt_Channel_Write-5.1 {Encrypt aes-138-cbc} -body { + binary encode hex [set data [write_chan $encrypted_file $test_data tls::encrypt -cipher $cipher -key $test_key -iv $test_iv]] + } -result $hex_string + +test Encrypt_Decrypt_Channel_Write-5.2 {Decrypt aes-138-cbc} -body { + write_chan $alt_file $data tls::decrypt -cipher $cipher -key $test_key -iv $test_iv + } -result $test_data + +# Cleanup +::tcltest::removeFile $unencrypted_file +::tcltest::removeFile $encrypted_file +::tcltest::removeFile $alt_file + +# Cleanup +::tcltest::cleanupTests +return Index: tests/info.test ================================================================== --- tests/info.test +++ tests/info.test @@ -15,28 +15,17 @@ # Constraints source common.tcl # Helper functions -proc lcompare {list1 list2} {set m "" - set u "" - foreach i $list1 {if {$i ni $list2} {lappend m $i}} - foreach i $list2 {if {$i ni $list1} {lappend u $i}} - return [list "missing" $m "unexpected" $u]} +proc lcompare {list1 list2} {set m "";set u "";foreach i $list1 {if {$i ni $list2} {lappend m $i}};foreach i $list2 {if {$i ni $list1} {lappend u $i}};return [list "missing" $m "unexpected" $u]} 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"] {foreach {cipher null alias} [split [string trim $line]] {lappend list [string tolower $cipher]}} - return [lsort -unique $list]} -proc exec_get_digests {} {set list [list] - set data [exec openssl dgst -list] - foreach line [split $data "\n"] {foreach digest $line {if {[string match "-*" $digest]} {lappend list [string trimleft $digest "-"]}}} - return [lsort $list]} +proc exec_get_ciphers {} {set list [list];set data [exec openssl list -cipher-algorithms];foreach line [split $data "\n"] {foreach {cipher null alias} [split [string trim $line]] {lappend list [string tolower $cipher]}};return [lsort -unique $list]} +proc exec_get_digests {} {set list [list];set data [exec openssl dgst -list];foreach line [split $data "\n"] {foreach digest $line {if {[string match "-*" $digest]} {lappend list [string trimleft $digest "-"]}}};return [lsort $list]} +proc exec_get_pks {} {set list [list];set data [exec openssl list -public-key-methods];foreach line [split $data "\n"] {if {![string match "*Type:*" $line]} {lappend list [string trim $line]}};return $list} proc exec_get_macs {} {return [list cmac hmac]} -proc list_tolower {list} {set result [list] - foreach element $list {lappend result [string tolower $element]} - return $result} +proc list_tolower {list} {set result [list];foreach element $list {lappend result [string tolower $element]};return $result} # Test list ciphers test Ciphers_List-1.1 {All} -body { Index: tests/make_test_files.tcl ================================================================== --- tests/make_test_files.tcl +++ tests/make_test_files.tcl @@ -72,11 +72,15 @@ set prev $group puts $out "" } # Test case - set buffer [format "\ntest %s-%d.%d {%s}" $group $test [incr cases($group)] $name] + if {[string index $name 0] ne {$}} { + set buffer [format "\ntest %s-%d.%d {%s}" $group $test [incr cases($group)] $name] + } else { + set buffer [format "\ntest %s-%d.%d %s" $group $test [incr cases($group)] $name] + } foreach opt [list -constraints -setup -body -cleanup -match -result -output -errorOutput -returnCodes] { set cmd [string trim [set [string trimleft $opt "-"]]] if {$cmd ne ""} { if {$opt in [list -setup -body -cleanup]} { append buffer " " $opt " \{\n"