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