4 return [string map {":" "_"} $alg]
6 if {[info exists env(PKG_PATH)]} {
7 lappend auto_path $env(PKG_PATH)
9 lappend auto_path [file dirname [info script]]
11 if {![info exists env(OTHER_DIR)]} {
12 puts stderr "Environment variable OTHER_DIR not set"
15 set data_dir $env(OTHER_DIR)
17 if {[file normalize $data_dir] == "[pwd]"} {
19 } elseif {[file normalize $data_dir] == [file normalize [pwd]/../OtherVersion]} {
24 package require ossltest
26 set ::test::suffix $suffix
28 start_tests "Интероперабельность, сравнение с $data_dir"
30 if {[info exists env(ALG_LIST)]} {
31 set alg_list $env(ALG_LIST)
33 set alg_list {gost2001:A gost2001:B gost2001:C gost2012_256:A gost2012_256:B gost2012_256:C gost2012_512:A gost2012_512:B}
35 if {[info exist env(ENC_LIST)]} {
36 set enc_list $env(ENC_LIST)
38 set enc_list {gost2001:XA:1.2.643.2.2.31.3 gost2001:XB:1.2.643.2.2.31.4 gost2001:XA: gost2012_256:XA:1.2.643.2.2.31.1 gost2012_256:XB:1.2.643.7.1.2.5.1.1 gost2012_256:XA: gost2012_512:A:1.2.643.2.2.31.3 gost2012_512:B:1.2.643.7.1.2.5.1.1 gost2012_512:A:}
41 test -createsfiles cfb2.$suffix\
42 "Расшифрование текста, зашифрованного на пароле в режиме CFB" {
43 set plain [getFile $data_dir/enc2.dat]
44 openssl "enc -gost89 -d -in $data_dir/cfb2.enc -out cfb2.$suffix -k 1234567890 -p"
45 set result [getFile cfb2.$suffix]
46 expr {[string equal $plain $result]?1:$result}
49 test -createsfiles cnt2.$suffix\
50 "Расшифрование текста, зашифрованного на пароле в режиме CNT" {
51 set plain [getFile $data_dir/enc2.dat]
52 openssl "enc -gost89-cnt -d -in $data_dir/cnt2.enc -out cnt2.$suffix -k 1234567890 -p"
53 set result [getFile cnt2.$suffix]
54 expr {[string equal $plain $result]?1:$result}
57 test -createsfiles cbc2.$suffix\
58 "Расшифрование текста, зашифрованного на пароле в режиме CBC" {
59 set plain [getFile $data_dir/enc2.dat]
60 openssl "enc -gost89-cbc -d -in $data_dir/cbc2.enc -out cbc2.$suffix -k 1234567890 -p"
61 set result [getFile cbc2.$suffix]
62 expr {[string equal $plain $result]?1:$result}
65 save_env2 {CRYPT_PARAMS}
66 test -createsfiles cbc3.$suffix\
67 "Расшифрование текста, зашифрованного в режиме CBC с параметрами РИК 1" {
68 set plain [getFile $data_dir/enc2.dat]
69 set env(CRYPT_PARAMS) "id-Gost28147-89-CryptoPro-RIC-1-ParamSet"
70 openssl "enc -gost89-cbc -d -in $data_dir/cbc3.enc -out cbc3.$suffix -k 1234567890 -p"
71 set result [getFile cbc3.$suffix]
72 expr {[string equal $plain $result]?1:$result}
74 restore_env2 {CRYPT_PARAMS}
77 foreach alg $alg_list {
78 set alg_fn [string map {":" "_"} $alg]
79 set username $data_dir/U_smime_$alg_fn
80 set userdir $data_dir/U_smime_${alg_fn}
82 gost2012* {set CA_dir_suffix CA-2012}
83 * {set CA_dir_suffix CA}
87 test "Проверка заявки $alg" {
88 grep "verif" [openssl "req -verify -in $username/req.pem"]
92 test "Проверка сертификата $alg" {
93 grep "cert.pem" [openssl "verify -CAfile $data_dir/smime$CA_dir_suffix/cacert.pem $userdir/cert.pem"]
94 } 0 "$userdir/cert.pem: OK
98 grep verify [openssl "crl -in $data_dir/test.crl -noout -CAfile $data_dir/test_crl_cacert.pem"]
102 test "Проверка документа, подписанного $alg, smime" {
103 grep Veri [openssl "smime -verify -text -in $data_dir/sign_$alg_fn.msg -out verified.$suffix -CAfile $data_dir/smime$CA_dir_suffix/cacert.pem -certfile $username/cert.pem"]
104 } 0 "Verification successful
107 set username $data_dir/U_cms_$alg_fn
108 test "Проверка документа, подписанного $alg, cms" {
109 grep Veri [openssl "cms -verify -text -in $data_dir/cms_sign_$alg_fn.msg -out cms_verified.$suffix -CAfile $data_dir/cms$CA_dir_suffix/cacert.pem -certfile $username/cert.pem"]
110 } 0 "Verification successful
113 test -createsfiles [list extracted_cert.pem.$suffix extracted_key.pem.$suffix] "Разбираем pkcs12 c алгоритмом $alg" {
114 openssl "pkcs12 -in $data_dir/U_pkcs12_$alg_fn/pkcs12.p12 -nodes -out dump.pem.$suffix -password pass:12345"
115 set dump [getFile dump.pem.$suffix]
116 set lextr [regexp -all -inline "\n-----BEGIN .*?\n-----END \[^\n\]+-----\n" $dump]
118 list [llength $lextr] [expr {[lindex $lextr 0] eq "\n[getFile $data_dir/U_pkcs12_$alg_fn/cert.pem]"}] [expr {[lindex $lextr 1] eq "\n[openssl "pkcs8 -nocrypt -topk8 -in $data_dir/U_pkcs12_$alg_fn/seckey.pem"]"}]
125 save_env2 {CRYPT_PARAMS}
126 foreach enc_tuple $enc_list {
127 if {![regexp {^([^:]*:[^:]*):(.*)$} $enc_tuple -> alg crypt_param]} {
131 if {[string length $crypt_param]} {
132 set env(CRYPT_PARAMS) $crypt_param
134 if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
136 set alg_fn [make_fn $enc_tuple]
137 set username U_enc_$alg_fn
139 test "Расшифрование документа на keyexchange $alg, smime" {
140 set expected [getFile $data_dir/encrypt.dat]
141 openssl "smime -decrypt -in $data_dir/enc_${alg_fn}.msg -recip $data_dir/U_enc_${alg_fn}/cert.pem -inkey $data_dir/U_enc_${alg_fn}/seckey.pem -out decrypt1.$alg_fn.$suffix"
142 set result [getFile decrypt1.$alg_fn.$suffix]
143 string eq $expected $result
146 test "Расшифрование документа на keyexchange $alg, cms" {
147 set expected [getFile $data_dir/encrypt.dat]
148 openssl "cms -decrypt -in $data_dir/cms_enc_${alg_fn}.msg -recip $data_dir/U_cms_enc_${alg_fn}/cert.pem -inkey $data_dir/U_cms_enc_${alg_fn}/seckey.pem -out cms_decrypt1.$alg_fn.$suffix"
149 set result [getFile cms_decrypt1.$alg_fn.$suffix]
150 string eq $expected $result
155 restore_env2 {CRYPT_PARAMS}