2 lappend auto_path [file dirname [info script]]
3 package require ossltest
6 start_tests "Тесты на команду pkcs12"
8 if {[info exists env(ALG_LIST)]} {
9 set alg_list $env(ALG_LIST)
11 switch -exact [engine_name] {
12 "ccore" {set alg_list {gost2001:A gost2001:B gost2001:C gost2001:XA gost2001:XB gost2012_256:A gost2012_256:B gost2012_256:C gost2012_256:XA gost2012_256:XB gost2012_512:A gost2012_512:B}}
15 gost2001:A gost2001:B gost2001:C
16 gost2001:XA gost2001:XB
17 gost2012_256:A gost2012_256:B gost2012_256:C
18 gost2012_256:XA gost2012_256:XB
19 gost2012_256:TCA gost2012_256:TCB gost2012_256:TCC gost2012_256:TCD
20 gost2012_512:A gost2012_512:B gost2012_512:C
26 foreach alg $alg_list {
27 set alg_fn [string map {":" "_"} $alg]
28 set username U_pkcs12_$alg_fn
30 gost2012_512:* {set hash_alg md_gost12_512}
31 gost2012_256:* {set hash_alg md_gost12_256}
32 default {set hash_alg md_gost94}
35 test -createsfiles [list $username/sscert.pem $username/sskey.pem]\
36 "Генерируем сертификат и секретный ключ $alg" {
37 makeSecretKey $username $alg
38 makeFile $username/req.conf [makeConf]
39 openssl "req -new -x509 -config $username/req.conf -key $username/seckey.pem -out $username/cert.pem"
40 expr {[file size $username/cert.pem] > 0}
43 test -createsfiles {$username/pkcs12.p12} "Собираем pkcs12 с алгоритмом $alg" {
44 openssl "pkcs12 -export -inkey $username/seckey.pem -in $username/cert.pem -out $username/pkcs12.p12 -password pass:12345 -keypbe gost89 -certpbe gost89 -macalg $hash_alg"
45 file exists $username/pkcs12.p12
48 test -skip {![file exists $username/pkcs12.p12]} -createsfiles [list $username/extracted_cert.pem $username/extracted_key.pem] "Разбираем pkcs12 c алгоритмом $alg" {
49 openssl "pkcs12 -in $username/pkcs12.p12 -nodes -out $username/dump.pem -password pass:12345"
50 set dump [getFile $username/dump.pem]
51 set lextr [regexp -all -inline "\n-----BEGIN .*?\n-----END \[^\n\]+-----\n" $dump]
53 list [llength $lextr] [expr {[lindex $lextr 0] eq "\n[getFile $username/cert.pem]"}] [expr {[lindex $lextr 1] eq "\n[openssl "pkcs8 -nocrypt -topk8 -in $username/seckey.pem"]"}]
58 #./load_engine pkcs12 -export -in t/z/U_enc_gost94_/cert.pem -inkey t/z/U_enc_gost94_/seckey.pem -certfile t/z/testCA/cacert.pem -name "CERTIFICATE" -out mycert.p12 -password pass:12345
59 #./load_engine pkcs12 -in mycert.p12 -out mycert.pem