2 lappend auto_path [file dirname [info script]]
3 package require ossltest
5 start_tests "Тесты на команду cms - вторая подпись"
11 makeFile cms_signed2.dat "Test data for 2 signatures"
14 foreach length {256 512} {
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
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
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
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 {Verification successful
36 test "Signed data is extracted correctly" {
37 string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
40 ### Test extracted sertificates
42 test "Extracting signer certificates" {
45 set certs [regexp -all -inline -- {-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----} [getFile signer.certs]]
47 makeFile cert[incr i].pem $cert
48 lappend subjs [grep subject [openssl "x509 -in cert$i.pem -subject -noout"]]
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
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
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
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 {Verification successful
70 test "Signed data is extracted correctly" {
71 string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
74 ### Test extracted sertificates
76 test "Extracting signer certificates" {
79 set certs [regexp -all -inline -- {-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----} [getFile signer.certs]]
81 makeFile cert[incr i].pem $cert
82 lappend subjs [grep subject [openssl "x509 -in cert$i.pem -subject -noout"]]
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
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
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
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 {Verification successful
104 test "Signed data is extracted correctly" {
105 string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
108 ### Test extracted sertificates
110 test "Extracting signer certificates" {
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 [grep subject [openssl "x509 -in cert_asn$i.pem -subject -noout"]]
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
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
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"]
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 {Verification successful
137 test "Signed data is extracted correctly" {
138 string eq [getFile cms_signed2.dat] [getFile was_signed.dat]
141 ### Test extracted sertificates
143 test "Extracting signer certificates" {
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 [grep subject [openssl "x509 -in cert_cms$i.pem -subject -noout"]]
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
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"
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"
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"
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"
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"
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"
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"
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"
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
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