2 lappend auto_path [file dirname [info script]]
3 package require ossltest
5 set testname [file rootname [file tail $::argv0]]
7 start_tests "Тесты на команду ca"
9 if {[info exists env(ALG_LIST)]} {
10 set alg_pair_list $env(ALG_LIST)
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}}}
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}
26 foreach {ca_alg alg_list} $alg_pair_list {
27 set ca_alg_fn [string map {":" "_"} $ca_alg]
29 test "Creating CA ($ca_alg)" {
30 makeCA ${testname}CA-$ca_alg_fn $ca_alg
35 foreach alg $alg_list {
36 set alg_fn [string map {":" "_"} $alg]
37 set userdir U_ca_${alg_fn}_for_${ca_alg_fn}
40 test "Creating user request ($alg)" {
41 makeUser $userdir $alg
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"]
48 if [file exists $userdir/req.pem] {
49 set cert [getFile $userdir/req.pem]
50 makeFile $userdir/broken.pem [hackPem "Cryptocom" $cert "Kriptokom"]
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
57 #test "Generating self-signed CA certificate" {
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 grep "Data Base" [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 "Data Base Updated
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
75 test -skip {![file exists test.crl]} "Displaying CRL" {
76 grep "(Serial|Version|Signature Alg|Issuer)" [openssl "crl -text -noout -in test.crl"]
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]
83 test -skip {![file exists test.crl]} "Verifying CRL OK" {
84 grep verify [openssl "crl -in test.crl -noout -CAfile $::test::ca/cacert.pem"]
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"]
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
99 test "Verifying certificate" {
100 grep "cert.pem" [openssl "verify -CAfile $::test::ca/cacert.pem $userdir/cert.pem"]
101 } 0 "$userdir/cert.pem: OK
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"
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"
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]]
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]]