]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/ca.try
249923b2f9558849ffae2a264e0e8af3678dcd11
[openssl-gost/engine.git] / tcl_tests / ca.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 "Тесты на команду ca" 
8
9 if {[info exists env(ALG_LIST)]} {
10         set alg_pair_list $env(ALG_LIST)
11 } else {
12         switch -exact [engine_name] {
13                 "ccore" {set alg_pair_list {gost2001:A {gost2001:B} gost2012_256:A {gost2012_256:C} gost2012_512:B {gost2012_256:B gost2012_512:A}}}
14                 "open" {
15                         set alg_pair_list {
16                                 gost2001:A {gost2001:B}
17                                 gost2012_256:A {gost2012_256:B gost2012_512:B}
18                                 gost2012_256:TCA {gost2012_256:A gost2012_512:A}
19                                 gost2012_512:A {gost2012_256:A gost2012_256:TCA gost2012_512:A gost2012_512:C}
20                                 gost2012_512:C {gost2012_256:B gost2012_256:TCB gost2012_512:B gost2012_512:C}
21                         }
22                 }
23         }
24 }
25
26 foreach {ca_alg alg_list} $alg_pair_list {
27         set ca_alg_fn [string map {":" "_"} $ca_alg]
28
29 test "Creating CA ($ca_alg)" {
30         makeCA ${testname}CA-$ca_alg_fn $ca_alg
31 } 0 1
32
33 set serial_list ""
34
35 foreach alg $alg_list {
36         set alg_fn [string map {":" "_"} $alg]
37         set userdir U_ca_${alg_fn}_for_${ca_alg_fn}
38
39 #Depends on previous
40 test "Creating user request ($alg)" {
41         makeUser $userdir $alg
42 } 0 1
43
44 test -skip {![file exists $userdir/req.pem]}  "Registering cert at CA" {
45         grep Sign [openssl "ca -config $::test::ca/ca.conf -in $userdir/req.pem -out $userdir/cert.pem -batch -notext"] 
46 } 0 "Signature ok
47 "
48 if [file exists $userdir/req.pem] {
49 set cert [getFile $userdir/req.pem]
50 makeFile $userdir/broken.pem  [hackPem "Cryptocom" $cert "Kriptokom"]
51 }
52 test -skip {![file exists $userdir/broken.pem]} "Registering broken request at ca" {
53         grep Sign [openssl "ca -config $::test::ca/ca.conf -in $userdir/broken.pem -out $userdir/badcert.pem -batch"]
54 } 0 "Signature did not match the certificate request
55 "
56
57 #test "Generating self-signed CA certificate" {
58 #
59 #} 0 "not written"
60
61 test  "Revoking certificate" {
62         set revoking_cert $::test::ca/newcerts/[string trim [getFile $::test::ca/serial.old]].pem
63         append serial_list [regsub "serial=" [openssl "x509 -in $revoking_cert -noout -serial"] "    Serial Number: "]
64         string map {"Data Base" Database Updated updated} [ grep "Data" [openssl "ca -crl_reason keyCompromize -crl_compromise [clock\
65         format [clock seconds]  -format %Y%m%d%H%M%SZ] -revoke $revoking_cert -config $::test::ca/ca.conf"] ]
66 } 0 "Database updated
67 "
68 test -createsfiles test.crl "Generating CRL" {
69         openssl "ca -gencrl -config $::test::ca/ca.conf -out test.crl"
70         file copy -force $::test::ca/cacert.pem test_crl_cacert.pem
71         file exist test.crl
72 } 0 1   
73
74
75 test -skip {![file exists test.crl]} "Displaying CRL" {
76         regsub -all " = " [grep "(Serial|Version|Signature Alg|Issuer)" [openssl "crl -text -noout -in test.crl"] ] "="
77 } 0 "        Version 2 (0x1)
78         Signature Algorithm: [hash_with_sign_long_name $ca_alg]
79         Issuer: C=RU, L=Moscow, CN=Test CA $ca_alg, O=Cryptocom, OU=OpenSSL CA, emailAddress=openssl@cryptocom.ru
80 $serial_list    Signature Algorithm: [hash_with_sign_long_name  $ca_alg]
81 "
82
83 test -skip {![file exists test.crl]} "Verifying CRL OK" {
84         grep verify [openssl "crl -in test.crl -noout -CAfile $::test::ca/cacert.pem"]
85 } 0 "verify OK
86 "
87
88 test -skip {![file exists test.crl]} "Verifying corrupted CRL" {
89         makeFile "badcrl.pem" [hackPem "\01\x1E" [getFile test.crl] "\01\0"]
90         grep verify [openssl "crl -in badcrl.pem -noout -CAfile $::test::ca/cacert.pem"]
91 } 0 "verify failure
92 "
93
94 test "Verifying CA certificate" {
95         grep "(cacert.pem|error|OK)" [openssl "verify -CAfile $::test::ca/cacert.pem $::test::ca/cacert.pem"]
96 } 0 "$::test::ca/cacert.pem: OK
97 "
98
99 test "Verifying certificate" {
100         grep "cert.pem" [openssl "verify -CAfile $::test::ca/cacert.pem $userdir/cert.pem"]
101 } 0 "$userdir/cert.pem: OK
102 "
103
104 test "Verifying bad certificate" {
105         makeFile "badcert.pem" [hackPem "Team" [getFile $userdir/cert.pem] "meat"]
106         openssl "verify -CAfile $::test::ca/cacert.pem badcert.pem"
107 } 1 "certificate signature failure"
108
109 test "Verifying revoked certificate" {
110         makeFile ca_crl.pem "[getFile $::test::ca/cacert.pem]\n[getFile test.crl]"
111         openssl "verify -crl_check -CAfile ca_crl.pem $userdir/cert.pem"
112 } 1 "certificate revoked"
113
114 test "Create a PKCS#7 structure from a certificate and CRL" {
115         openssl "crl2pkcs7 -in test.crl -certfile $userdir/cert.pem -out $userdir/p7.pem"
116         extract_oids $userdir/p7.pem PEM
117 } 0 [mkObjList [hash_with_sign_long_name $ca_alg] [alg_long_name $alg] [pubkey_long_name $alg] [param_hash_long_name [param_hash $alg] $alg] [hash_with_sign_long_name $ca_alg] [hash_with_sign_long_name $ca_alg] [hash_with_sign_long_name $ca_alg]]
118
119 test "Creates a PKCS#7 structure without CRL" {
120         openssl "crl2pkcs7 -nocrl -certfile $userdir/cert.pem -certfile $::test::ca/cacert.pem -out $userdir/p7_nocrl.pem"
121         extract_oids $userdir/p7_nocrl.pem PEM
122 } 0 [mkObjList [hash_with_sign_long_name $ca_alg] [alg_long_name $alg] [pubkey_long_name $alg] [param_hash_long_name [param_hash $alg] $alg]  [hash_with_sign_long_name $ca_alg] [hash_with_sign_long_name $ca_alg] [alg_long_name $ca_alg] [pubkey_long_name $ca_alg] [param_hash_long_name [param_hash $ca_alg] $ca_alg] [hash_with_sign_long_name $ca_alg]]
123
124 }
125
126 }
127
128 end_tests