]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/cmsenc_cs.try
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / tcl_tests / cmsenc_cs.try
1 #!/usr/bin/tclsh
2 lappend auto_path [file dirname [info script]]
3 package require ossltest
4 package require test
5 cd $::test::dir
6 set testname [file rootname [file tail $::argv0]]
7
8 start_tests "Тесты на cms -encrypt с участием эталонных серверов" 
9 proc make_fn {alg} {
10         return [string map {":" "_"} $alg]
11 }
12
13 proc map {str list} {
14         set result {}
15         foreach a $list {
16                 lappend result [subst $str]
17         }
18         return $result
19 }
20         
21 if {![file exist encrypt.dat]} {
22         makeFile encrypt.dat [string repeat "Test data to encrypt.\n" 100] 
23 }
24
25 #if {![info exist env(/NO_RSA)]} {
26 #test "Creating RSA CA" {
27 #       makeCA ${testname}CA-RSA rsa:512
28 #} 0 1
29 #
30
31 set ::test::ca cmsencCA-RSA
32
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
36 #} 0 1
37 #}
38
39 set hosts tls-ref-cp21
40 foreach hstname $hosts {
41
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
45 #} 0 1
46
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}
50
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_2/seckey.pem -out TESTPATH/cms_decrypt.rsa" "rsa"
54         set result [getFile cms_decrypt.rsa]
55         string eq $expected $result
56 } 0 1
57
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
63 } 0 1
64 }
65
66 #test "Creating CA 2001" {
67 #       makeCA ${testname}CA gost2001:A
68 #} 0 1
69
70 #test "Creating CA 2012" {
71 #       makeCA
72 #} 0 1
73 #
74
75 set hosts [list tls-ref-cp21 tls-ref-cp20]
76 foreach hstname $hosts {
77
78 if {[info exist env(ENC_LIST)]} {
79         set enc_list $env(ENC_LIST)
80 } else {
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 }}
84         }
85 }
86
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]
90
91 foreach enc_tuple $enc_list {
92         if {![regexp {^([^:]*:[^:]*):(.*)$} $enc_tuple -> alg crypt_param]} {
93                 set alg $enc_tuple
94                 set crypt_param {}
95         }
96         set alg_fn [make_fn $enc_tuple]
97         set username U_cms_enc_$alg_fn
98         switch -glob $alg {
99                 gost2012* {set ::test::ca cmsCA-2012}
100                 * {set ::test::ca cmsCA}
101         }
102
103 #test "Creating user $username with key $alg" {
104 #       makeRegisteredUser $username $alg
105
106 #       if {![file exists $username/req.pem]&&[file exists $username/cert.pem]} {
107 #               file delete $username/cert.pem
108 #       }       
109 #       file exists $username/cert.pem
110 #} 0 1
111
112 if {[string length $crypt_param]} {
113         set env(CRYPT_PARAMS) $crypt_param
114 } else {
115         if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
116 }
117
118 #test -createsfiles cms_enc_$alg_fn.msg "Encrypting for $username" {
119 #       grep "rror" [openssl "cms -encrypt -in encrypt.dat -gost89 -out cms_enc_$alg_fn.msg U_cms_enc_$alg_fn/cert.pem"]
120 #} 0 ""
121
122 if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
123
124 #test -createsfiles cms_enc_$alg_fn.pem "Extracting CMS from encrypted structure for $username" {
125 #       openssl "cms -cmsout -out cms_enc_$alg_fn.pem -outform PEM -in cms_enc_$alg_fn.msg"
126 #       file isfile cms_enc_$alg_fn.pem
127 #} 0 1
128
129 #test -skip {![file exists cms_enc_$alg_fn.pem]} "Checking oids in pkcs7 structure for $username" {
130 #       extract_oids cms_enc_$alg_fn.pem PEM
131 #} 0 [mkObjList [alg_id $alg] [param_pubkey $alg] [param_hash $alg] crypt89_cc [param_encr $crypt_param]]
132
133 #test "Decrypting file encrypted for $username" {
134 #       set expected [getFile encrypt.dat]
135 #       openssl_remote "$username U_cms_enc_$alg_fn cms_enc_$alg_fn.msg" "$hstname" "cms -decrypt -in TESTPATH/cms_enc_$alg_fn.msg -recip TESTPATH/U_cms_enc_$alg_fn/cert.pem -inkey TESTPATH/U_cms_enc_$alg_fn/seckey.pem -out TESTPATH/cms_decrypt.$alg_fn" "$testname"
136 #       set result [getRemoteFile "$hstname" "TESTPATH/cms_decrypt.$alg_fn" "$testname"]
137 #       string eq $expected $result
138 #} 0 1
139
140 test "Decrypting file encrypted for $username" {
141     set expected [getFile encrypt.dat]
142     set result [openssl_remote "$username U_cms_enc_$alg_fn cms_enc_$alg_fn.msg" "$hstname" "cms -decrypt -in TESTPATH/cms_enc_$alg_fn.msg -recip TESTPATH/U_cms_enc_$alg_fn/cert.pem -inkey TESTPATH/U_cms_enc_$alg_fn/seckey.pem" "$testname"]
143     string eq $expected $result
144 } 0 1
145
146 if {[string length $crypt_param]} {
147         set env(CRYPT_PARAMS) $crypt_param
148 } else {
149         if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
150 }
151
152 #test -createsfiles cms_enc_t_$alg_fn.msg "Encrypting for $username - text format" {
153 #       grep "rror" [openssl "cms -encrypt -text -in encrypt.dat -gost89 -out cms_enc_t_$alg_fn.msg U_cms_enc_$alg_fn/cert.pem"]
154 #} 0 ""
155
156 if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
157
158 test -createsfiles cms_decrypt_t.$alg_fn "Decrypting file text-encrypted for $username" {
159         set expected [getFile encrypt.dat]
160         set result [openssl_remote "cms_enc_t_$alg_fn.msg U_cms_enc_$alg_fn" "$hstname" "cms -decrypt -text -in TESTPATH/cms_enc_t_$alg_fn.msg -recip TESTPATH/U_cms_enc_$alg_fn/cert.pem -inkey TESTPATH/U_cms_enc_$alg_fn/seckey.pem" "$testname"]
161         string eq $expected $result
162 } 0 1
163
164 test -createsfiles cms_decrypt_t_nocert.$alg_fn "Decrypting file text-encrypted for $username without cert" {
165         set expected [getFile encrypt.dat]
166         set result [openssl_remote "cms_enc_t_$alg_fn.msg U_cms_enc_$alg_fn" "$hstname" "cms -decrypt -text -in TESTPATH/cms_enc_t_$alg_fn.msg -inkey TESTPATH/U_cms_enc_$alg_fn/seckey.pem" "$testname"]
167         string eq $expected $result
168 } 0 1
169
170 }
171
172
173 #test -createfiles cms_enc_4all_old "Encrypt for all" {
174 #       puts stdout $enc_list
175 #       grep "rror" [openssl "cms -encrypt -in encrypt.dat -gost89 -out cms_enc_4all_old.msg [map {U_cms_enc_[make_fn $a]/cert.pem} $enc_list]"]
176 #} 0 ""
177
178 foreach enc_tuple $enc_list {
179         if {![regexp {^([^:]*:[^:]*):(.*)$} $enc_tuple -> alg crypt_param]} {
180                 set alg $enc_tuple
181                 set crypt_param {}
182         }
183         set alg_fn [make_fn $enc_tuple]
184         set username U_cms_enc_$alg_fn
185
186 if {[string length $crypt_param]} {
187         set env(CRYPT_PARAMS) $crypt_param
188 } else {
189         if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
190 }
191
192 test -createfiles cms_enc_4all_old "Encrypt for all" {
193         grep "rror" [openssl "cms -encrypt -in encrypt.dat -gost89 -out cms_enc_4all_old.msg [map {U_cms_enc_[make_fn $a]/cert.pem} $enc_list]"]
194 } 0 ""
195         
196 test -skip {![file exists cms_enc_4all_old.msg]} "Decrypting gost-encrypted file, recipient $alg_fn" {
197         set expected [getFile encrypt.dat]
198         set result [openssl_remote "cms_enc_4all_old.msg $username" "$hstname" "cms -decrypt -in TESTPATH/cms_enc_4all_old.msg -recip TESTPATH/$username/cert.pem -inkey TESTPATH/$username/seckey.pem" "$testname"]
199         string eq $expected $result
200 } 0 1
201
202 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" {
203         set expected [getFile encrypt.dat]
204         set result [openssl_remote "cms_enc_4all_old.msg $username" "$hstname" "cms -decrypt -in TESTPATH/cms_enc_4all_old.msg -inkey TESTPATH/$username/seckey.pem" "$testname"]
205         string eq $expected $result
206 } 0 1
207
208 }
209
210 restore_env2 {OPENSSL_CONF CRYPT_PARAMS}
211 }
212
213
214 end_tests