]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/cms_cs.try
tcl_tests: Add TCL tests files
[openssl-gost/engine.git] / tcl_tests / cms_cs.try
1 #!/usr/bin/tclsh
2 # -*- coding: cp1251 -*-
3 lappend auto_path [file dirname [info script]]
4 package require ossltest
5 cd $::test::dir
6 set testname [file rootname [file tail $::argv0]]
7
8 start_tests "Тесты на интероперабельность результатов подписи командой cms с smime-проверками на эталонниках" 
9
10 if {[info exists env(ALG_LIST)]} {
11         set alg_list $env(ALG_LIST)
12 } else {
13         switch -exact [engine_name] {
14                 "ccore" {set alg_list {gost2001:A gost2001:B gost2001:C}}
15                 "open" {set alg_list {gost2001:A gost2001:B gost2001:C}}
16         }
17 }
18
19 foreach alg $alg_list {
20         set alg_fn [string map {":" "_"} $alg]
21         set username U_cms_$alg_fn
22         switch -glob $alg {
23                 gost2012* {set ::test::ca cmsCA-2012
24                            set ca_sign_alg hash_with_sign12_512
25                           }
26                 * {set ::test::ca cmsCA
27                    set ca_sign_alg hash_with_sign01_cp
28                   }
29         }
30 set hosts [list tls-ref-cp21]
31 foreach hstname $hosts {
32
33
34 #test -skip {![file exists $username/cert.pem]} -createsfiles [list sign.dat sign_$alg_fn.msg] "Signing a message by smime without cert by $alg (verify by smime)" {
35 #       makeFile sign.dat [string repeat "Test data to sign.\n" 100] 
36 #       openssl "cms -sign -in sign.dat -text -out sign_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem -nocerts"
37 #       file isfile sign_$alg_fn.msg
38 #} 0 1
39
40 test -skip {![file exists sign_$alg_fn.msg]} "Verifying a message signed with $alg without ca via smime" {
41         grep Veri [openssl_remote "$username sign_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/sign_$alg_fn.msg -out TESTPATH/verified.txt -noverify -certfile TESTPATH/$username/cert.pem" "cms"]
42 } 0 "Verification successful
43 "
44
45 test -skip {![file exists sign_$alg_fn.msg]}  "Verifying a message signed with $alg with ca via smime" {
46         grep Veri [openssl_remote "$::test::ca sign_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/sign_$alg_fn.msg -out TESTPATH/verified.txt -certfile TESTPATH/$username/cert.pem -CAfile TESTPATH/$::test::ca/cacert.pem" "cms"]
47 } 0 "Verification successful
48 "
49
50 test -skip {![file exists sign_$alg_fn.msg]} -createsfiles [list bad_$alg_fn.msg TESTPATH/verified.txt] "Verifying corrupted messages signed with $alg via smime" {
51         set corrupted [getFile sign_$alg_fn.msg]
52         set index [string first "Test data" $corrupted ]
53         makeFile bad_$alg_fn.msg [string replace $corrupted $index [expr $index+9] "Bad data"]
54         grep Verification [openssl_remote "bad_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/bad_$alg_fn.msg -out TESTPATH/verified.txt -noverify -certfile TESTPATH/$username/cert.pem" "cms"]
55 } 1 "Verification failure"
56
57 #test -skip {![file exists $username/cert.pem]}  -createsfiles [list sign.dat sign_c_$alg_fn.msg] "Signing a message by $alg with cert" {
58 #       makeFile sign.dat [string repeat "Test data to sign.\n" 100] 
59 #       openssl "cms -sign -in sign.dat -crlfeol -text -out sign_c_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem"
60 #       file isfile sign_c_$alg_fn.msg
61 #} 0 1
62
63 test -skip {![file exists sign_c_$alg_fn.msg]} "Verifying a message signed with $alg having cert inside without ca via smime" {
64         grep Veri [openssl_remote "sign_c_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/sign_c_$alg_fn.msg -out TESTPATH/verified.txt -noverify" "cms"]
65 } 0 "Verification successful
66 "
67
68 test -skip {![file exists sign_c_$alg_fn.msg]} "Verifying a message signed with $alg having cert with ca via smime" {
69         grep Veri [openssl_remote "sign_c_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/sign_c_$alg_fn.msg -out TESTPATH/verified.txt -CAfile TESTPATH/$::test::ca/cacert.pem" "cms"]
70 } 0 "Verification successful
71 "
72
73 #test -skip {![file exists $username/cert.pem]} -createsfiles {sign.dat sign_op_$alg_fn.msg} "Signing a message by $alg with cert using opaque signing" {
74 #       makeFile sign.dat [string repeat "Test data to sign.\n" 100] 
75 #       openssl "cms -sign -in sign.dat -text -out sign_op_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem -nodetach"
76 #       file isfile sign_op_$alg_fn.msg
77 #} 0 1
78
79 test -createsfiles TESTPATH/verified.txt -skip {![file exists sign_op_$alg_fn.msg]} "Verifying a message signed by $alg having cert inside without ca via smime" {
80         grep Veri [openssl_remote "sign_op_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/sign_op_$alg_fn.msg -out TESTPATH/verified.txt -noverify" "cms"]
81 } 0 "Verification successful
82 "
83
84 test -createsfiles TESTPATH/verified.txt -skip {![file exists sign_op_$alg_fn.msg]} "Verifying a $alg opaque  message with ca via smime" {
85         grep Veri [openssl_remote "sign_op_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/sign_op_$alg_fn.msg -out TESTPATH/verified.txt -CAfile TESTPATH/$::test::ca/cacert.pem" "cms"]
86 } 0 "Verification successful
87 "
88
89 test -createsfiles broken_op_$alg_fn.msg  -skip {![file exists sign_op_$alg_fn.msg]} "Verifying broken $alg opaque message" {
90         set data [getFile sign_op_$alg_fn.msg]
91         regexp "(.*)\n\r?\n(.+)" $data match header encoded
92         set asnstruct [::base64::decode $encoded]
93         makeFile broken_op_$alg_fn.msg "$header\n\n[::base64::encode [regsub -all\
94                 "Test data" $asnstruct "Best data"]]"
95         grep Verification [openssl_remote "broken_op_$alg_fn.msg" "$hstname" "smime -verify -text -in TESTPATH/broken_op_$alg_fn.msg -out TESTPATH/verified.txt -CAfile TESTPATH/$::test::ca/cacert.pem" "cms"]
96 } 1 "Verification failure"
97
98 #test -createsfiles "sign_det_$alg_fn.msg" -skip {![file exists $username/cert.pem]||![file exists sign.dat]} "Creating detached $alg signature" {
99 #       openssl "cms -sign -binary -in sign.dat -out sign_det_$alg_fn.msg -signer $username/cert.pem -inkey $username/seckey.pem"
100 #       file exists sign_det_$alg_fn.msg
101 #} 0 1
102
103 #We expect cryptocom oids because of cert signed by ca with Cryptocom algs
104 # Result sequence
105 # 1. digest 
106 # 2.  algorithm of CA key
107 # 3. algorithm of current key
108 # 4. algorithm of CA key
109 # 5. digest
110 # 6. digests from sMIMECapabilities
111 # 7. encryption from sMIMECapabilities
112 # 8. algorithm of current key
113
114 test -skip {![file exists pk7sign_$alg_fn.pem]} "Verifying detached $alg signature via smime" {
115         grep Veri [openssl_remote "pk7sign_$alg_fn.pem sign.dat" "$hstname" "smime -verify -content TESTPATH/sign.dat -inform PEM -in TESTPATH/pk7sign_$alg_fn.pem -out TESTPATH/verified.txt -noverify" "cms"]
116 } 0 "Verification successful
117 "
118
119 test -skip {![file exists pk7sign_$alg_fn.pem]} -createsfiles {bad.dat} "Verifying corrupted $alg detached signature" {
120         makeFile bad.dat [regsub Test [getFile sign.dat] Best]
121         grep Verification [openssl_remote "sign_det_$alg_fn.msg bad.dat" "$hstname" "smime -verify -content TESTPATH/bad.dat -in TESTPATH/sign_det_$alg_fn.msg -out TESTPATH/verified.txt -CAfile TESTPATH/$::test::ca/cacert.pem" "cms"]
122 } 1 "Verification failure"
123 }
124
125 }
126 end_tests