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}}}
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}}}
18 foreach {ca_alg alg_list} $alg_pair_list {
19 set ca_alg_fn [string map {":" "_"} $ca_alg]
22 makeCA ${testname}CA-$ca_alg_fn $ca_alg
27 foreach alg $alg_list {
28 set alg_fn [string map {":" "_"} $alg]
29 set userdir U_ca_${alg_fn}_for_${ca_alg_fn}
32 test "Creating user request" {
33 makeUser $userdir $alg
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"]
40 if [file exists $userdir/req.pem] {
41 set cert [getFile $userdir/req.pem]
42 makeFile $userdir/broken.pem [hackPem "Cryptocom" $cert "Kriptokom"]
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
49 #test "Generating self-signed CA certificate" {
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
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
67 test -skip {![file exists test.crl]} "Displaying CRL" {
68 grep "(Serial|Version|Signature Alg|Issuer)" [openssl "crl -text -noout -in test.crl"]
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]
75 test -skip {![file exists test.crl]} "Verifying CRL OK" {
76 grep verify [openssl "crl -in test.crl -noout -CAfile $::test::ca/cacert.pem"]
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"]
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
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"
95 test "Verifying certificate" {
96 grep "cert.pem" [openssl "verify -CAfile $::test::ca/cacert.pem $userdir/cert.pem"]
97 } 0 "$userdir/cert.pem: OK
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"
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"
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]]
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]]