2 lappend auto_path [file dirname [info script]]
3 package require ossltest
6 set testname [file rootname [file tail $::argv0]]
8 start_tests "Тесты на cms -encrypt с участием эталонных серверов (шифрование на эталонниках)"
10 return [string map {":" "_"} $alg]
16 lappend result [subst $str]
21 if {![file exist encrypt.dat]} {
22 makeFile encrypt.dat [string repeat "Test data to encrypt.\n" 100]
25 #if {![info exist env(/NO_RSA)]} {
26 #test "Creating RSA CA" {
27 # makeCA ${testname}CA-RSA rsa:512
31 #set ::test::ca cmsencCA-RSA
33 #foreach user {U_cms_enc_rsa_1 U_cms_enc_rsa_2} {
34 #test "Make registered user $user" {
35 # makeRegisteredUser $user rsa:512 CAname ${testname}CA-RSA
39 #set hosts tls-ref-cp21
40 #foreach hstname $hosts {
42 #test -createsfiles cms_enc_rsa.msg "RSA User 1 encrypts message for RSA user 2" {
43 # openssl "cms -encrypt -in encrypt.dat -des -out cms_enc_rsa.msg U_cms_enc_rsa_2/cert.pem"
44 # file isfile cms_enc_rsa.msg
47 #test "RSA User 1 cannot decrypt message for RSA user 2" {
48 # grep "Error" [openssl_remote "cms_enc_rsa.msg U_cms_enc_rsa_1" "$hstname" "cms -decrypt -in TESTPATH/cms_enc_rsa.msg -recip TESTPATH/U_cms_enc_rsa_1/cert.pem -inkey TESTPATH/U_cms_enc_rsa_1/seckey.pem" "rsa"]
49 #} 1 {Error decrypting CMS}
51 #test -skip {![file exists cms_decrypt.rsa]} "RSA User 2 (with cert) can decrypt message for RSA user 2" {
52 # set expected [getFile encrypt.dat]
53 # openssl_remote "U_cms_enc_rsa_2" "$hstname" "cms -decrypt -in TESTPATH/cms_enc_rsa.msg -recip TESTPATH/U_cms_enc_rsa_2/cert.pem -inkey TESTPATH/U_cms_enc_rsa_1/seckey.pem -out TESTPATH/cms_decrypt.rsa" "rsa"
54 # set result [getFile cms_decrypt.rsa]
55 # string eq $expected $result
58 #test -skip{![file exists cms_decrypt_nocert.rsa]} "RSA User 2 (without cert) can decrypt message for RSA user 2" {
59 # set expected [getFile encrypt.dat]
60 # openssl_remote "$hstname" "cms -decrypt -in TESTPATH/cms_enc_rsa.msg -inkey TESTPATH/U_cms_enc_rsa_2/seckey.pem -out TESTPATH/cms_decrypt_nocert.rsa" "rsa"
61 # set result [getFile cms_decrypt_nocert.rsa]
62 # string eq $expected $result
66 #test "Creating CA 2001" {
67 # makeCA ${testname}CA gost2001:A
70 #test "Creating CA 2012" {
75 set hosts [list tls-ref-cp21 tls-ref-cp20]
76 foreach hstname $hosts {
78 if {[info exist env(ENC_LIST)]} {
79 set enc_list $env(ENC_LIST)
81 switch -exact [engine_name] {
82 "ccore" {set enc_list {gost2001:XA:1.2.643.2.2.31.3 gost2001:XB:1.2.643.2.2.31.4 }}
83 "open" {set enc_list {gost2001:XA:1.2.643.2.2.31.3 gost2001:XB:1.2.643.2.2.31.4 }}
87 save_env2 {OPENSSL_CONF CRYPT_PARAMS}
88 makeFile cmsenc1.cnf [regsub -all "\n\\s*CRYPT_PARAMS\\s*=\[\^\n]*" [getConfig] ""]
89 set ::env(OPENSSL_CONF) [file join [pwd] cmsenc1.cnf]
91 foreach enc_tuple $enc_list {
92 if {![regexp {^([^:]*:[^:]*):(.*)$} $enc_tuple -> alg crypt_param]} {
96 set alg_fn [make_fn $enc_tuple]
97 set username U_cms_enc_$alg_fn
99 gost2012* {set ::test::ca cmsencCA-2012}
100 * {set ::test::ca cmsencCA}
103 if {[string length $crypt_param]} {
104 set env(CRYPT_PARAMS) $crypt_param
106 if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
109 test -createsfiles cms_enc_sc_$alg_fn.msg "Encrypting for $username" {
110 file mkdir 1_$hstname/$alg_fn
111 set res [open 1_$hstname/$alg_fn/cms_enc_sc_$alg_fn.msg w]
112 puts $res [openssl_remote "encrypt.dat $username $::test::ca" "$hstname" "cms -encrypt -in TESTPATH/encrypt.dat -gost89 TESTPATH/$username/cert.pem" "$testname"]
116 #if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
118 test "Decrypting file encrypted for $username" {
119 set expected [getFile encrypt.dat]
120 set result [openssl "cms -decrypt -in 1_$hstname/$alg_fn/cms_enc_sc_$alg_fn.msg -recip $username/cert.pem -inkey $username/seckey.pem"]
121 string eq $expected $result
124 if {[string length $crypt_param]} {
125 set env(CRYPT_PARAMS) $crypt_param
127 if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
130 test -createsfiles cms_enc_t_$alg_fn.msg "Encrypting for $username - text format" {
131 file mkdir 2_$hstname/$alg_fn
132 set res [open 2_$hstname/$alg_fn/cms_enc_sc_t_$alg_fn.msg w]
133 puts $res [openssl_remote "encrypt.dat $username $::test::ca" "$hstname" "cms -encrypt -text -in TESTPATH/encrypt.dat -gost89 TESTPATH/$username/cert.pem" "$testname"]
137 #if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
141 test "Decrypting file text-encrypted for $username" {
142 set expected [getFile encrypt.dat]
143 set result [openssl "cms -decrypt -text -in 2_$hstname/$alg_fn/cms_enc_sc_t_$alg_fn.msg -recip $username/cert.pem -inkey $username/seckey.pem"]
144 string eq $expected $result
147 test "Decrypting file text-encrypted for $username without cert" {
148 set expected [getFile encrypt.dat]
149 set result [openssl "cms -decrypt -text -in 2_$hstname/$alg_fn/cms_enc_sc_t_$alg_fn.msg -inkey $username/seckey.pem"]
150 string eq $expected $result
155 foreach enc_tuple $enc_list {
156 if {![regexp {^([^:]*:[^:]*):(.*)$} $enc_tuple -> alg crypt_param]} {
160 set alg_fn [make_fn $enc_tuple]
161 set username U_cms_enc_$alg_fn
163 # Не мапится $a, потому отваливаются тесты. Выяснить, почему
164 test "Encrypt for all" {
165 file mkdir 3_$hstname/$alg_fn
166 set res [open 3_$hstname/$alg_fn/cms_enc_4all_old.msg w]
167 puts $res [openssl_remote "encrypt.dat $username $::test::ca" "$hstname" "cms -encrypt -in TESTPATH/encrypt.dat -gost89 [map {TESTPATH/U_cms_enc_[make_fn $a]/cert.pem} $enc_list]" "$testname"]
171 test -skip {![file exists cms_enc_4all_old.msg]} "Decrypting gost-encrypted file, recipient $alg_fn" {
172 set expected [getFile encrypt.dat]
173 set result [openssl "cms -decrypt -in 3_$hstname/$alg_fn/cms_enc_4all_old.msg -recip $username/cert.pem -inkey $username/seckey.pem"]
174 string eq $expected $result
177 test -skip {![file exists cms_enc_4all_old.msg]} -createsfiles cms_decrypt_4all_nocert.$alg_fn "Decrypting gost-encrypted file without cert, recipient $alg_fn" {
178 set expected [getFile encrypt.dat]
179 set result [openssl "cms -decrypt -in 3_$hstname/$alg_fn/cms_enc_4all_old.msg -inkey $username/seckey.pem"]
180 string eq $expected $result
185 restore_env2 {OPENSSL_CONF CRYPT_PARAMS}