]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/pkcs12.try
tcl_tests: Add TCL tests files
[openssl-gost/engine.git] / tcl_tests / pkcs12.try
1 #!/usr/bin/tclsh
2 # -*- coding: cp1251 -*-
3 lappend auto_path [file dirname [info script]]
4 package require ossltest
5 cd $::test::dir
6
7 start_tests "Тесты на команду pkcs12" 
8
9 if {[info exists env(ALG_LIST)]} {
10         set alg_list $env(ALG_LIST)
11 } else {
12         switch -exact [engine_name] {
13                 "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}}
14                 "open" {set alg_list {gost2001:A gost2001:B gost2001:C gost2012_256:A gost2001:XA gost2001:XB gost2012_256:B gost2012_256:C gost2012_256:XA gost2012_256:XB gost2012_512:A gost2012_512:B}}
15         }
16 }
17
18 foreach alg $alg_list {
19         set alg_fn [string map {":" "_"} $alg]
20         set username U_pkcs12_$alg_fn
21         switch -glob $alg {
22                 gost2012_512:* {set hash_alg md_gost12_512}
23                 gost2012_256:* {set hash_alg md_gost12_256}
24                 default {set hash_alg md_gost94}
25         }
26         
27 test -createsfiles [list $username/sscert.pem $username/sskey.pem]\
28   "Генерируем сертификат и секретный ключ $alg" {
29         makeSecretKey $username $alg
30         makeFile $username/req.conf [makeConf]
31         openssl "req -new -x509 -config $username/req.conf -key $username/seckey.pem -out $username/cert.pem"   
32         expr {[file size $username/cert.pem] > 0}
33 } 0 1
34
35 test -createsfiles {$username/pkcs12.p12} "Собираем pkcs12 с алгоритмом $alg" {
36         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"
37         file exists $username/pkcs12.p12
38 } 0 1
39
40 test -skip {![file exists $username/pkcs12.p12]} -createsfiles [list $username/extracted_cert.pem $username/extracted_key.pem] "Разбираем pkcs12 c алгоритмом $alg" {
41         openssl "pkcs12 -in $username/pkcs12.p12 -nodes -out $username/dump.pem -password pass:12345"
42         set dump [getFile $username/dump.pem]
43         set lextr [regexp -all -inline "\n-----BEGIN .*?\n-----END \[^\n\]+-----\n" $dump]
44         
45         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"]"}]    
46         
47 } 0 {2 1 1}
48
49
50 #./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
51 #./load_engine pkcs12 -in mycert.p12 -out mycert.pem 
52
53 }
54
55 end_tests