]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/cms2.try
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / tcl_tests / cms2.try
1 #!/usr/bin/tclsh
2 lappend auto_path [file dirname [info script]]
3 package require ossltest
4 cd $::test::dir
5 start_tests "Тесты на команду cms - вторая подпись" 
6
7 test "Creating CA" {
8         makeCA
9 } 0 1
10
11 makeFile cms_signed2.dat "Test data for 2 signatures"
12
13
14 foreach length {256 512} {
15
16 test "Creating users $length" {
17         makeRegisteredUser U_cms_1_$length gost2012_$length:A CN USER1_$length emailAddress test@cryptocom.ru
18         makeRegisteredUser U_cms_2_$length gost2012_$length:A CN USER2_$length emailAddress test@cryptocom.ru
19 } 0 1
20
21 test -createsfiles cms_signed2_1_$length.asn "Signing in DER format with 1st signature" {
22         openssl "cms -sign -binary -outform der -inform der -nodetach -inkey U_cms_1_$length/seckey.pem -signer U_cms_1_$length/cert.pem -in cms_signed2.dat -out cms_signed2_1_$length.asn"
23         file isfile cms_signed2_1_$length.asn
24 } 0 1
25
26 test -createsfiles cms_signed2_2_$length.asn "Signing in DER format with 2nd signature" {
27         openssl "cms -resign -binary -outform der -inform der -nodetach -inkey U_cms_2_$length/seckey.pem -signer U_cms_2_$length/cert.pem -in cms_signed2_1_$length.asn -out cms_signed2_2_$length.asn"
28         file isfile cms_signed2_2_$length.asn
29 } 0 1
30
31 test -createsfiles {was_signed.dat signer.certs} "Verifying signature in DER format" {
32         grep "Verif" [openssl "cms -verify -inform der -in cms_signed2_2_$length.asn -noverify -signer signer.certs -out was_signed.dat"]
33 } 0 {CMS Verification successful
34 }
35
36 test "Signed data is extracted correctly" {
37         string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
38 } 0 1
39
40 ### Test extracted sertificates
41
42 test "Extracting signer certificates" {
43         set i 0
44         set subjs {}
45         set certs [regexp -all -inline -- {-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----} [getFile signer.certs]]
46         foreach cert $certs {
47                 makeFile cert[incr i].pem $cert
48                 lappend subjs [regsub -all " = " [grep subject [openssl "x509 -in cert$i.pem -subject -noout"]] "=" ]
49         }
50         lsort $subjs
51 } 0  "{subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER1_$length, emailAddress=test@cryptocom.ru
52 } {subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER2_$length, emailAddress=test@cryptocom.ru
53 }"
54
55 test -createsfiles cms_signed2_1_$length\_op.msg "Signing opaque in S/MIME format with 1st signature" {
56         openssl "cms -sign -binary -inform der -nodetach -inkey U_cms_1_$length/seckey.pem -signer U_cms_1_$length/cert.pem -in cms_signed2.dat -out cms_signed2_1_$length\_op.msg"
57         file isfile cms_signed2_1_$length\_op.msg
58 } 0 1
59
60 test -createsfiles cms_signed2_2_$length\_op.msg "Signing opaque in S/MIME format with 2nd signature" {
61         openssl "cms -resign -binary -nodetach -inkey U_cms_2_$length/seckey.pem -signer U_cms_2_$length/cert.pem -in cms_signed2_1_$length\_op.msg -out cms_signed2_2_$length\_op.msg"
62         file isfile cms_signed2_2_$length\_op.msg
63 } 0 1
64
65 test -createsfiles {was_signed.dat signer.certs} "Verifying opaque signature in S/MIME format" {
66         grep "Verif" [openssl "cms -verify -in cms_signed2_2_$length\_op.msg -noverify -signer signer.certs -out was_signed.dat"]
67 } 0 {CMS Verification successful
68 }
69
70 test "Signed data is extracted correctly" {
71         string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
72 } 0 1
73
74 ### Test extracted sertificates
75
76 test "Extracting signer certificates" {
77         set i 0
78         set subjs {}
79         set certs [regexp -all -inline -- {-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----} [getFile signer.certs]]
80         foreach cert $certs {
81                 makeFile cert[incr i].pem $cert
82                 lappend subjs [regsub -all " = " [grep subject [openssl "x509 -in cert$i.pem -subject -noout"]] "=" ]
83         }
84         lsort $subjs
85 } 0 "{subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER1_$length, emailAddress=test@cryptocom.ru
86 } {subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER2_$length, emailAddress=test@cryptocom.ru
87 }"
88
89 test -createsfiles cms_signed2_1_$length\_det.asn "Signing detached in DER format with 1st signature" {
90         openssl "cms -sign -binary -outform der -inkey U_cms_1_$length/seckey.pem -signer U_cms_1_$length/cert.pem -in cms_signed2.dat -out cms_signed2_1_$length\_det.asn"
91         file isfile cms_signed2_1_$length\_det.asn
92 } 0 1
93
94 test -createsfiles cms_signed2_2_$length\_det.asn "Signing detached in DER format with 2nd signature" {
95         openssl "cms -resign -binary -inkey U_cms_2_$length/seckey.pem -signer U_cms_2_$length/cert.pem -in cms_signed2_1_$length\_det.asn -content cms_signed2.dat -inform der -outform der -out cms_signed2_2_$length\_det.asn"
96         file isfile cms_signed2_2_$length\_det.asn
97 } 0 1
98
99 test -createsfiles {was_signed.dat signer.certs} "Verifying detached signature in DER format" {
100         grep "Verif" [openssl "cms -verify -in cms_signed2_2_$length\_det.asn -noverify -signer signer.certs -out was_signed.dat -content signed2.dat -inform der"]
101 } 0 {CMS Verification successful
102 }
103
104 test "Signed data is extracted correctly" {
105         string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
106 } 0 1
107
108 ### Test extracted sertificates
109
110 test "Extracting signer certificates" {
111         set i 0
112         set subjs {}
113         set certs [regexp -all -inline -- {-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----} [getFile signer.certs]]
114         foreach cert $certs {
115                 makeFile cert_asn[incr i].pem $cert
116                 lappend subjs [regsub -all " = " [grep subject [openssl "x509 -in cert$i.pem -subject -noout"]] "=" ]
117         }
118         lsort  $subjs
119 } 0  "{subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER1_$length, emailAddress=test@cryptocom.ru
120 } {subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER2_$length, emailAddress=test@cryptocom.ru
121 }"
122
123 test -createsfiles cms_signed2_1_$length.msg "Signing in S/MIME format with 1st signature" {
124         openssl "cms -sign -binary -inform der -inkey U_cms_1_$length/seckey.pem -signer U_cms_1_$length/cert.pem -in cms_signed2.dat -out cms_signed2_1_$length.msg"
125         file isfile cms_signed2_1_$length.msg
126 } 0 1
127
128 test -createsfiles cms_signed2_2_$length.msg "Signing in S/MIME format with 2nd signature" {
129         grep "SMIME" [openssl "cms -resign -binary -inkey U_cms_2_$length/seckey.pem -signer U_cms_2_$length/cert.pem -in cms_signed2_1_$length.msg -inform smime -out cms_signed2_2_$length.msg"]
130 } 0 ""
131
132 test -createsfiles {was_signed.dat  signer.certs} "Verifying signature in S/MIME format" {
133         grep "Verif" [openssl "cms -verify -in cms_signed2_2_$length.msg -noverify -signer signer.certs -out was_signed.dat -inform smime"]
134 } 0 {CMS Verification successful
135 }
136
137 test "Signed data is extracted correctly" {
138         string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
139 } 0 1
140
141 ### Test extracted sertificates
142
143 test "Extracting signer certificates" {
144         set i 0
145         set subjs {}
146         set certs [regexp -all -inline -- {-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----} [getFile signer.certs]]
147         foreach cert $certs {
148                 makeFile cert_cms[incr i].pem $cert
149                 lappend subjs [regsub -all " = " [grep subject [openssl "x509 -in cert$i.pem -subject -noout"]] "=" ]
150         }
151         lsort $subjs
152 } 0  "{subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER1_$length, emailAddress=test@cryptocom.ru
153 } {subject=C=RU, O=Cryptocom, OU=OpenSSL Team, CN=USER2_$length, emailAddress=test@cryptocom.ru
154 }"
155
156 }
157
158
159 test "Resigning in DER format with a unsuitable key length 512" {
160         openssl "cms -resign -binary -inform der -nodetach -inkey U_cms_2_512/seckey.pem -signer U_cms_2_512/cert.pem -in cms_signed2_1_256.asn"
161 } 1 "no matching digest"
162
163 test "Resigning in DER format with a unsuitable key length 256" {
164         openssl "cms -resign -binary -inform der -nodetach -inkey U_cms_2_256/seckey.pem -signer U_cms_2_256/cert.pem -in cms_signed2_1_512.asn"
165 } 1 "no matching digest"
166
167 test "Resigning opaque in S/MIME format with a unsuitable key length 512" {
168         openssl "cms -resign -binary -nodetach -inkey U_cms_2_512/seckey.pem -signer U_cms_2_512/cert.pem -in cms_signed2_1_256_op.msg"
169 } 1 "no matching digest"
170
171 test "Resigning opaque in S/MIME format with a unsuitable key length 256" {
172         openssl "cms -resign -binary -nodetach -inkey U_cms_2_256/seckey.pem -signer U_cms_2_256/cert.pem -in cms_signed2_1_512_op.msg"
173 } 1 "no matching digest"
174
175 test "Resigning detached in DER format with a unsuitable key length 512" {
176         openssl "cms -resign -binary -inform der -inkey U_cms_2_512/seckey.pem -signer U_cms_2_512/cert.pem -in cms_signed2_1_256_det.asn -content cms_signed2.dat"
177 } 1 "no matching digest"
178
179 test "Resigning detached in DER format with a unsuitable key length 256" {
180         openssl "cms -resign -binary -inform der -inkey U_cms_2_256/seckey.pem -signer U_cms_2_256/cert.pem -in cms_signed2_1_512_det.asn -content cms_signed2.dat"
181 } 1 "no matching digest"
182
183 test "Resigning in S/MIME format with a unsuitable key length 512" {
184         openssl "cms -resign -binary -inkey U_cms_2_512/seckey.pem -signer U_cms_2_512/cert.pem -in cms_signed2_1_256.msg"
185 } 1 "no matching digest"
186
187 test "Resigning in S/MIME format with a unsuitable key length 256" {
188         openssl "cms -resign -binary -inkey U_cms_2_256/seckey.pem -signer U_cms_2_256/cert.pem -in cms_signed2_1_512.msg"
189 } 1 "no matching digest"
190
191
192 end_tests
193
194
195
196 #./load_engine cms -sign -binary -outform der -inform der -nodetach -inkey certs/fstek.key -signer certs/fstek.crt -out cms_signed2 -in cms_signed1
197 #./load_engine cms -verify -inform der -in cms_signed2 -noverify
198 #./load_engine cms -verify -inform der -in cms_signed2 -noverify -signer sss
199 #cat sss
200 #history 
201 #vim sss
202 #./load_engine x509 -in sss sss2
203 #./load_engine x509 -in sss 
204 #./load_engine x509 -in sss -subject -noout
205 #./load_engine x509 -in sss2 -subject -noout
206 #./load_engine cms -verify -inform der -in cms_signed2 -noverify -signer sss -out qqq