2 # создание секретного ключа
3 # создание заявки и самоподписанного сертификата командой req
4 # проверка OIDов алгоритма во всех структурах
5 lappend auto_path [file dirname [info script]]
6 package require ossltest
8 start_tests "Создание ключей и заявок, команда genpkey"
10 if {[info exists env(ALG_LIST)]} {
11 set alg_list $env(ALG_LIST)
13 switch -exact [engine_name] {
14 "ccore" {set alg_list {gost2001:A gost2001:B gost2001:C gost2001:XA gost2001:XB gost2012_256:A gost2012_256:B gost2012_256:C gost2012_256:XA gost2012_256:XB gost2012_512:A gost2012_512:B}}
15 "open" {set alg_list {gost2001:A gost2001:B gost2001:C gost2001:XA gost2001:XB gost2012_256:0 gost2012_256:A gost2012_256:B gost2012_256:C gost2012_256:XA gost2012_256:XB gost2012_512:A gost2012_512:B}}
19 foreach alg $alg_list {
20 set alg_fn [string map {":" "_"} $alg]
21 set username pkey_$alg_fn
22 foreach {alg_only params} [split $alg :] break
24 test -createsfiles $username/seckey.pem "Секретный ключ, алгоритм $alg" {
25 file delete -force $username
27 openssl "genpkey -algorithm $alg_only -pkeyopt paramset:$params -out $username/seckey.pem"
28 expr {[file size $username/seckey.pem] > 0}
31 test -skip {![file exists $username/seckey.pem]} "OID в секретном ключе" {
32 extract_oids $username/seckey.pem
33 } 0 [mkObjList [alg_long_name $alg] [pubkey_long_name $alg] [param_hash_long_name [param_hash $alg]]]
35 test -skip {![file exists $username/seckey.pem]} "Алгоритм $alg, заявка по секретному ключу" {
36 makeFile $username/req.conf [makeConf]
37 openssl "req -new -config $username/req.conf -key $username/seckey.pem -out $username/req.pem"
38 expr {[file size $username/req.pem] > 0}
41 test -skip {![file exists $username/req.pem]} "Подпись под заявкой корректна" {
42 grep "verif" [openssl "req -verify -in $username/req.pem"]
43 } 0 {Certificate request self-signature verify OK
46 test -skip {![file exists $username/req.pem]} "OID в заявке, алгоритм $alg" {
47 extract_oids $username/req.pem
48 } 0 [mkObjList [alg_long_name $alg] [pubkey_long_name $alg] [param_hash_long_name [param_hash $alg]] [hash_with_sign_long_name $alg]]
50 test -skip {![file exists $username/seckey.pem]} "Алгоритм $alg, сертификат по секретному ключу" {
51 openssl "req -new -x509 -config $username/req.conf -key $username/seckey.pem -out $username/cert.pem"
52 expr {[file size $username/cert.pem] > 0}
55 test -skip {![file exists $username/cert.pem]} "OID в сертификате" {
56 extract_oids $username/cert.pem
57 } 0 [mkObjList [hash_with_sign_long_name $alg] [alg_long_name $alg] [pubkey_long_name $alg]\
58 [param_hash_long_name [param_hash $alg]] [hash_with_sign_long_name $alg]]
60 test -createsfiles "$username/seckey.der" "Алгоритм $alg сохраняем ключ в DER-формате" {
61 openssl "genpkey -algorithm $alg_only -pkeyopt paramset:$params -out $username/seckey.der -outform DER"
62 file exists $username/seckey.der
65 test -skip {![file exists $username/seckey.der]} "OID в секретном ключе $alg DER" {
66 extract_oids $username/seckey.der DER
67 } 0 [mkObjList [alg_long_name $alg] [pubkey_long_name $alg] [param_hash_long_name [param_hash $alg]]]
69 test -skip {![file exists $username/seckey.der]} -createsfiles $username/req2.pem "Создаем заявку из ключа в формате DER" {
70 openssl "req -new -config $username/req.conf -key $username/seckey.der -keyform der -out $username/req2.pem"
71 expr {[file size $username/req2.pem] > 0}
74 test -skip {![file exists $username/req2.pem]} "Подпись под заявкой корректна" {
75 grep "verif" [openssl "req -verify -in $username/req2.pem"]
76 } 0 {Certificate request self-signature verify OK