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