Diff

Differences From Artifact [7abebb7019]:

To Artifact [b3fa4d9f22]:


21
22
23
24
25
26
27

28
29
30
31
32
33
34
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35







+







# 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 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]}
command,proc exec_get_macs {} {return [list cmac hmac]},,,,,,,,,
proc read_chan {md filename args} {set ch [open $filename rb];fconfigure $ch -translation binary;set bsize [fconfigure $ch -buffersize];set new [tls::digest $md {*}$args -chan $ch];while {![eof $new]} {set result [read $new $bsize]};close $new;return $result}
proc accumulate {md string args} {set cmd [tls::digest $md {*}$args -command dcmd];$cmd update [string range $string 0 20];$cmd update [string range $string 21 end];return [$cmd finalize]}
# Test list ciphers


test Ciphers_List-1.1 {All} -body {
	lcompare [lsort [exec_get_ciphers]] [list_tolower [lsort [::tls::ciphers]]]
    } -result {missing {rc5 rc5-cbc rc5-cfb rc5-ecb rc5-ofb} unexpected {aes-128-ccm aes-128-gcm aes-192-ccm aes-192-gcm aes-256-ccm aes-256-gcm}}
# Test list ciphers for protocols
227
228
229
230
231
232
233






























234
235
236
237

238
239
240
241

242
243
244
245

246
247
248
249

250
251
252
253
254
255

256
257
258
259
260
261

262
263
264
265
266
267

268
269
270
271

272
273
274
275
276
277
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267

268
269
270
271

272
273
274
275

276
277
278
279

280
281
282
283
284
285

286
287
288
289
290
291

292
293
294
295
296
297

298
299
300
301

302
303
304
305
306
307
308







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
+



-
+



-
+



-
+





-
+





-
+





-
+



-
+






test Digest_Chan-9.6 {md5 bin} -body {
	string toupper [binary encode hex [read_chan md5 md_data.dat -bin]]
    } -result {CCB1BE2E11D8183E843FF73DA8C6D206}

test Digest_Chan-9.7 {md5 hex} -body {
	read_chan md5 md_data.dat -hex
    } -result {CCB1BE2E11D8183E843FF73DA8C6D206}
# Test digest command for accumulator command


test Digest_Command-10.1 {md4} -body {
	accumulate md4 "Example string for message digest tests."
    } -result {181CDCF9DB9B6FA8FC0A3BF9C34E29D9}

test Digest_Command-10.2 {md5} -body {
	accumulate md5 "Example string for message digest tests."
    } -result {CCB1BE2E11D8183E843FF73DA8C6D206}

test Digest_Command-10.3 {sha1} -body {
	accumulate sha1 "Example string for message digest tests."
    } -result {3AEFE840CA492C387E903F15ED6019E7AD833B47}

test Digest_Command-10.4 {sha256} -body {
	accumulate sha256 "Example string for message digest tests."
    } -result {B7DFDDEB0314A74FF56A8AC1E3DC57DF09BB52A96DA50F6549EB62CA61A0A491}

test Digest_Command-10.5 {sha512} -body {
	accumulate sha512 "Example string for message digest tests."
    } -result {B56EC55E33193E17B61D669FB7B04AD2483DE93FE847C411BBEAE6440ECEA6C7CFDD2E6F35A06CB189FC62D799E785CDB7A23178323789D001BC8E44A0B5907F}

test Digest_Command-10.6 {md5 bin} -body {
	string toupper [binary encode hex [accumulate md5 "Example string for message digest tests." -bin]]
    } -result {CCB1BE2E11D8183E843FF73DA8C6D206}

test Digest_Command-10.7 {md5 hex} -body {
	accumulate md5 "Example string for message digest tests." -hex
    } -result {CCB1BE2E11D8183E843FF73DA8C6D206}
# Test HMAC


test Digest_HMAC-10.1 {data} -body {
test Digest_HMAC-11.1 {data} -body {
	tls::digest md5 -key "Example key" -data "Example string for message digest tests."
    } -result {901DA6E6976A71650C77443C37FF9C7F}

test Digest_HMAC-10.2 {file} -body {
test Digest_HMAC-11.2 {file} -body {
	tls::digest md5 -key "Example key" -file md_data.dat
    } -result {901DA6E6976A71650C77443C37FF9C7F}

test Digest_HMAC-10.3 {channel} -body {
test Digest_HMAC-11.3 {channel} -body {
	read_chan md5 md_data.dat -key "Example key"
    } -result {901DA6E6976A71650C77443C37FF9C7F}

test Digest_HMAC-10.4 {data bin} -body {
test Digest_HMAC-11.4 {data bin} -body {
	string toupper [binary encode hex [tls::digest md5 -bin -key "Example key" -data "Example string for message digest tests."]]
    } -result {901DA6E6976A71650C77443C37FF9C7F}
# Test list MACs


test MAC_List-11.1 {All} -body {
test MAC_List-12.1 {All} -body {
	lcompare [exec_get_macs] [tls::macs]
    } -result {missing {} unexpected {}}
# Test list protocols


test Protocols-12.1 {All} -body {
test Protocols-13.1 {All} -body {
	lcompare $protocols [::tls::protocols]
    } -result {missing {ssl2 ssl3} unexpected {}}
# Test show version


test Version-13.1 {All} -body {
test Version-14.1 {All} -body {
	::tls::version
    } -match {glob} -result {*}

test Version-13.2 {OpenSSL} -constraints {OpenSSL} -body {
test Version-14.2 {OpenSSL} -constraints {OpenSSL} -body {
	::tls::version
    } -match {glob} -result {OpenSSL*}

# Cleanup
::tcltest::cleanupTests
return