]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/cms.try
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / tcl_tests / cms.try
1 #!/usr/bin/tclsh
2 lappend auto_path [file dirname [info script]]
3 package require ossltest
4 cd $::test::dir
5 set testname [file rootname [file tail $::argv0]]
6
7 start_tests "Тесты на команду cms" 
8
9 test "Creating CA 2001" {
10         makeCA ${testname}CA gost2001:A
11 } 0 1
12
13 test "Creating CA 2012" {
14         makeCA
15 } 0 1
16
17
18 if {[info exists env(ALG_LIST)]} {
19         set alg_list $env(ALG_LIST)
20 } else {
21         switch -exact [engine_name] {
22                 "ccore" {set alg_list {gost2001:A gost2001:B gost2001:C gost2012_256:A gost2012_256:B gost2012_256:C gost2012_512:A gost2012_512:B}}
23                 "open" {set alg_list {gost2001:A gost2001:B gost2001:C gost2012_256:A gost2012_256:B gost2012_256:C gost2012_512:A gost2012_512:B}}
24         }
25 }
26
27 foreach alg $alg_list {
28         set alg_fn [string map {":" "_"} $alg]
29         set username U_cms_$alg_fn
30         switch -glob $alg {
31                 gost2012* {set ::test::ca ${testname}CA-2012
32                            set ca_sign_alg hash_with_sign12_512
33                           }
34                 * {set ::test::ca ${testname}CA
35                    set ca_sign_alg hash_with_sign01_cp
36                   }
37         }
38
39 test "Creating user with signing key $alg" {
40         makeRegisteredUser $username $alg
41
42         if {![file exists $username/req.pem]&&[file exists $username/cert.pem]} {
43                 file delete $username/cert.pem
44         }       
45         file exists $username/cert.pem
46 } 0 1
47
48 test -skip {![file exists $username/cert.pem]} -createsfiles [list cms_sign.dat cms_sign_$alg_fn.msg] "Signing a message without cert by $alg" {
49         makeFile cms_sign.dat [string repeat "Test data to cms_sign.\n" 100] 
50         openssl "cms -sign -in cms_sign.dat -text -out cms_sign_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem -nocerts"
51         file isfile cms_sign_$alg_fn.msg
52 } 0 1
53
54 test -skip {![file exist cms_sign_$alg_fn.msg]} "Checking micalg param in signed without cert $alg message" {
55         regexp -- micalg="[micalg [alg_hash $alg]]" [grep micalg [getFile cms_sign_$alg_fn.msg]]
56 } 0 1
57
58 test -createsfiles cms_sign_$alg_fn.pem -skip {![file exist cms_sign_$alg_fn.msg]} "Extracting CMS from signed without cert $alg message" {
59         openssl "cms -cmsout -out cms_sign_$alg_fn.pem -outform PEM -in cms_sign_$alg_fn.msg"
60         file isfile cms_sign_$alg_fn.pem
61 } 0 1
62
63
64 test -skip {![file exists cms_sign_$alg_fn.pem]} "Checking oids in cms struct" {
65         extract_oids cms_sign_$alg_fn.pem PEM
66 } 0 [mkObjList [hash_long_name $alg] [hash_long_name $alg] "GOST R 34.11-2012 with 256 bit hash" "GOST R 34.11-2012 with 512 bit hash" "GOST R 34.11-94" "GOST 28147-89" [alg_long_name $alg]]  
67 # hash_12_256 hash_12_512 hash_94 crypt89_cc are from sMIMECapabilities
68
69 test -skip {![file exists cms_sign_$alg_fn.msg]} "Verifying a message signed with $alg without ca " {
70         grep Veri [openssl "cms -verify -text -in cms_sign_$alg_fn.msg -out cms_verified.txt -noverify -certfile $username/cert.pem"]
71 } 0 "CMS Verification successful
72 "
73
74 test -skip {![file exists cms_sign_$alg_fn.msg]}  "Verifying a message signed with $alg with ca" {
75         grep Veri [openssl "cms -verify -text -in cms_sign_$alg_fn.msg -out cms_verified.txt -certfile $username/cert.pem -CAfile $::test::ca/cacert.pem"]
76 } 0 "CMS Verification successful
77 "
78
79 test -skip {![file exists cms_sign_$alg_fn.msg]} -createsfiles [list cms_bad_$alg_fn.msg cms_verified.txt] "Verifying corrupted messages signed with $alg" {
80         set corrupted [getFile cms_sign_$alg_fn.msg]
81         set index [string first "Test data" $corrupted ]
82         makeFile cms_bad_$alg_fn.msg [string replace $corrupted $index [expr $index+9] "Bad data"]
83         grep Verification [openssl "cms -verify -text -in cms_bad_$alg_fn.msg -out cms_verified.txt -noverify -certfile $username/cert.pem"]
84 } 1 "Verification failure"
85
86 test -skip {![file exists $username/cert.pem]}  -createsfiles [list cms_sign.dat cms_sign_c_$alg_fn.msg] "Signing a message by $alg with cert" {
87         makeFile cms_sign.dat [string repeat "Test data to sign.\n" 100] 
88         openssl "cms -sign -in cms_sign.dat -crlfeol -text -out cms_sign_c_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem"
89         file isfile cms_sign_c_$alg_fn.msg
90 } 0 1
91
92 test -skip {![file exist cms_sign_c_$alg_fn.msg]} "Checking micalg param in signed with cert $alg message" {
93         regexp -- micalg="[micalg [alg_hash $alg]]" [grep micalg [getFile cms_sign_c_$alg_fn.msg]]
94 } 0 1
95
96 test -skip {![file exists cms_sign_c_$alg_fn.msg]} "Verifying a message signed with $alg having cert inside without ca" {
97         grep Veri [openssl "cms -verify -text -in cms_sign_c_$alg_fn.msg -out cms_verified.txt -noverify"]
98 } 0 "CMS Verification successful
99 "
100
101 test -skip {![file exists cms_sign_c_$alg_fn.msg]} "Verifying a message signed with $alg having cert with ca" {
102         grep Veri [openssl "cms -verify -text -in cms_sign_c_$alg_fn.msg -out cms_verified.txt -CAfile $::test::ca/cacert.pem"]
103 } 0 "CMS Verification successful
104 "
105
106 test -skip {![file exists $username/cert.pem]} -createsfiles {cms_sign.dat cms_sign_op_$alg_fn.msg} "Signing a message by $alg with cert using opaque signing" {
107         makeFile cms_sign.dat [string repeat "Test data to cms_sign.\n" 100] 
108         openssl "cms -sign -in cms_sign.dat -text -out cms_sign_op_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem -nodetach"
109         file isfile cms_sign_op_$alg_fn.msg
110 } 0 1
111
112 test -createsfiles cms_verified.txt -skip {![file exists cms_sign_op_$alg_fn.msg]} "Verifying a message signed by $alg having cert inside without ca" {
113         grep Veri [openssl "cms -verify -text -in cms_sign_op_$alg_fn.msg -out cms_verified.txt -noverify"]
114 } 0 "CMS Verification successful
115 "
116
117 test -createsfiles cms_verified.txt -skip {![file exists cms_sign_op_$alg_fn.msg]} "Verifying a $alg opaque  message with ca" {
118         grep Veri [openssl "cms -verify -text -in cms_sign_op_$alg_fn.msg -out cms_verified.txt -CAfile $::test::ca/cacert.pem"]
119 } 0 "CMS Verification successful
120 "
121
122 test -createsfiles cms_broken_op_$alg_fn.msg  -skip {![file exists cms_sign_op_$alg_fn.msg]} "Verifying broken $alg opaque message" {
123         set data [getFile cms_sign_op_$alg_fn.msg]
124         regexp "(.*)\n\r?\n(.+)" $data match header encoded
125         set asnstruct [::base64::decode $encoded]
126         makeFile cms_broken_op_$alg_fn.msg "$header\n\n[::base64::encode [regsub -all\
127                 "Test data" $asnstruct "Best data"]]"
128         grep Verification [openssl "cms -verify -text -in cms_broken_op_$alg_fn.msg -out cms_verified.txt -CAfile $::test::ca/cacert.pem"]
129 } 1 "Verification failure"
130         
131
132 test -createsfiles "cms_sign_det_$alg_fn.msg" -skip {![file exists $username/cert.pem]||![file exists cms_sign.dat]} "Creating detached $alg signature" {
133         openssl "cms -sign -binary -in cms_sign.dat -out cms_sign_det_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem"
134         file exists cms_sign_det_$alg_fn.msg
135 } 0 1
136
137 test -skip {![file exist cms_sign_det_$alg_fn.msg]} "Checking micalg param in detached $alg signature" {
138         regexp -- micalg="[micalg [alg_hash $alg]]" [grep micalg [getFile cms_sign_det_$alg_fn.msg]]
139 } 0 1
140
141 test -createsfiles cms_sign_det_$alg_fn.pem -skip {![file exist cms_sign_det_$alg_fn.msg]} "Extracting CMS from signed $alg message" {
142 openssl "cms -cmsout -out cms_sign_det_$alg_fn.pem -outform PEM -in cms_sign_det_$alg_fn.msg"
143         file isfile cms_sign_$alg_fn.pem
144 } 0 1
145
146 #We expect cryptocom oids because of cert cms_signed by ca with Cryptocom algs
147 # Result sequence
148 # 1. digest 
149 # 2.  algorithm of CA key
150 # 3. algorithm of current key
151 # 4. algorithm of CA key
152 # 5. digest
153 # 6. digests from sMIMECapabilities
154 # 7. encryption from sMIMECapabilities
155 # 8. algorithm of current key
156 test -skip {![file exists cms_sign_$alg_fn.pem]} "Checking oids in cms struct" {
157         extract_oids cms_sign_det_$alg_fn.pem PEM
158 } 0 [mkObjList [hash_long_name $alg] [smime_hash_with_sign_long_name $ca_sign_alg] [alg_long_name $alg] [pubkey_long_name $alg] [param_hash_long_name [param_hash $alg]] [smime_hash_with_sign_long_name  $ca_sign_alg] [hash_long_name $alg] "GOST R 34.11-2012 with 256 bit hash" "GOST R 34.11-2012 with 512 bit hash" "GOST R 34.11-94" "GOST 28147-89" [alg_long_name $alg]]
159
160 test -skip {![file exists cms_sign_det_$alg_fn.pem]} "Verifying detached $alg cms_signature" {
161         grep Veri [openssl "cms -verify -binary -content cms_sign.dat -inform PEM -in cms_sign_det_$alg_fn.pem -out cms_verified.txt -noverify"]
162 } 0 "CMS Verification successful
163 "
164
165 test -skip {![file exists cms_sign_det_$alg_fn.msg]} -createsfiles {bad.dat} "Verifying corrupted $alg detached cms_signature" {
166         makeFile bad.dat [regsub Test [getFile cms_sign.dat] Best]
167         grep Verification [openssl "cms -verify -content bad.dat -in cms_sign_det_$alg_fn.msg -out cms_verified.txt -CAfile $::test::ca/cacert.pem"]
168 } 1 "Verification failure"
169
170
171 }
172 end_tests