2 # -*- coding: cp1251 -*-
3 lappend auto_path [file dirname [info script]]
4 package require ossltest
6 set testname [file rootname [file tail $::argv0]]
8 start_tests "Тесты на команду ca"
10 if {[info exists env(ALG_LIST)]} {
11 set alg_pair_list $env(ALG_LIST)
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}}}
19 foreach {ca_alg alg_list} $alg_pair_list {
20 set ca_alg_fn [string map {":" "_"} $ca_alg]
23 makeCA ${testname}CA-$ca_alg_fn $ca_alg
28 foreach alg $alg_list {
29 set alg_fn [string map {":" "_"} $alg]
30 set userdir U_ca_${alg_fn}_for_${ca_alg_fn}
33 test "Creating user request" {
34 makeUser $userdir $alg
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"]
41 if [file exists $userdir/req.pem] {
42 set cert [getFile $userdir/req.pem]
43 makeFile $userdir/broken.pem [hackPem "Cryptocom" $cert "Kriptokom"]
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
50 #test "Generating self-signed CA certificate" {
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
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
68 test -skip {![file exists test.crl]} "Displaying CRL" {
69 grep "(Serial|Version|Signature Alg|Issuer)" [openssl "crl -text -noout -in test.crl"]
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]
76 test -skip {![file exists test.crl]} "Verifying CRL OK" {
77 grep verify [openssl "crl -in test.crl -noout -CAfile $::test::ca/cacert.pem"]
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"]
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
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"
96 test "Verifying certificate" {
97 grep "cert.pem" [openssl "verify -CAfile $::test::ca/cacert.pem $userdir/cert.pem"]
98 } 0 "$userdir/cert.pem: OK
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"
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"
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]]
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]]