]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/cmsenc_sc.try
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / tcl_tests / cmsenc_sc.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_1/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 cmsencCA-2012}
100                 * {set ::test::ca cmsencCA}
101         }
102
103 if {[string length $crypt_param]} {
104         set env(CRYPT_PARAMS) $crypt_param
105 } else {
106         if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
107 }
108
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"]
113         close $res
114 } 0 ""
115
116 #if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
117
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
122 } 0 1
123
124 if {[string length $crypt_param]} {
125         set env(CRYPT_PARAMS) $crypt_param
126 } else {
127         if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
128 }
129
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"]
134         close $res
135 } 0 ""
136
137 #if {[info exists env(CRYPT_PARAMS)]} {unset env(CRYPT_PARAMS)}
138
139
140
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
145 } 0 1
146
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
151 } 0 1
152
153 }
154
155 foreach enc_tuple $enc_list {
156         if {![regexp {^([^:]*:[^:]*):(.*)$} $enc_tuple -> alg crypt_param]} {
157                 set alg $enc_tuple
158                 set crypt_param {}
159         }
160         set alg_fn [make_fn $enc_tuple]
161         set username U_cms_enc_$alg_fn
162
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"]
168         close $res
169 } 0 ""
170         
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
175 } 0 1
176
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
181 } 0 1
182
183 }
184
185 restore_env2 {OPENSSL_CONF CRYPT_PARAMS}
186 }
187
188
189
190 end_tests