2 lappend auto_path [file dirname [info script]]
3 package require ossltest
5 start_tests "тесты на команду pkcs8"
6 set key "-----BEGIN PRIVATE KEY-----
7 MEUCAQAwHAYGKoUDAgITMBIGByqFAwICIwEGByqFAwICHgEEIgIgSZ82qYpu6RQj
8 UeoKl5svrvYuMriHeAQvuSIvjAg5fnk=
9 -----END PRIVATE KEY-----
12 test "Печатаем эталонный ключ gost2001" {
13 set etalon [openssl [list pkey -text -noout << $key]]
14 } 0 "Private key: 499F36A98A6EE9142351EA0A979B2FAEF62E32B88778042FB9222F8C08397E79
15 Parameter set: id-GostR3410-2001-CryptoPro-A-ParamSet
18 test "Конвертируем в DER и проверяем, что ключ тот же gost2001" {
19 openssl [list pkcs8 -outform DER -out pkcs8-1.der -nocrypt << $key]
20 openssl [list pkey -inform DER -text -noout -in pkcs8-1.der]
24 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
25 test "Зашифровываем незашифрованный ключ gost2001, параметры CryptoPro-A" {
26 makeFile pkcs8-1A.key $key
27 set env(CRYPT_PARAMS) "id-Gost28147-89-CryptoPro-A-ParamSet"
28 set env(GOST_PBE_HMAC) "md_gost94"
29 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-1A.key -topk8 -out encA.key << $key]
32 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
34 test -skip {![file exists encA.key]} "Проверяем OID-ы PBE" {
35 set res [extract_oids encA.key]
36 regexp "HMAC GOST 34\.11-94" $res && regexp "GOST .*89"
39 test "Расшифровываем зашифрованный ключ gost2001" {
40 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in encA.key]]
41 openssl [list pkey -text -noout << $unencrypted]
45 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
46 test "Зашифровываем незашифрованный ключ gost2001, параметры CryptoPro-B" {
47 makeFile pkcs8-1B.key $key
48 set env(CRYPT_PARAMS) "id-Gost28147-89-CryptoPro-B-ParamSet"
49 set env(GOST_PBE_HMAC) "md_gost94"
50 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-1B.key -topk8 -out encB.key << $key]
53 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
55 test -skip {![file exists encB.key]} "Проверяем OID-ы PBE" {
56 set res [extract_oids encB.key]
57 regexp "HMAC GOST 34\.11-94" $res && regexp "GOST .*89"
61 test "Расшифровываем зашифрованный ключ gost2001" {
62 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in encB.key]]
63 openssl [list pkey -text -noout << $unencrypted]
68 test "Расшифровываем ключ, созданный mkkey" {
69 makeFile pkcs8-2.key "-----BEGIN ENCRYPTED PRIVATE KEY-----
70 MIGvMFUGCSqGSIb3DQEFDTBIMCcGCSqGSIb3DQEFDDAaBAjIvbrnGmGbTAIC
71 CAAwCgYGKoUDAgIKBQAwHQYGKoUDAgIVMBMECOtWtCMQo3dzBgcqhQMCAh8B
72 BFZFPKP6qDKi57rmas1U2fUjyZwjmrk6Y+naeWG/BTVJNJklW3HaHP+wuIFb
73 bxdi6rTNsYqxWm26qUHz6Op5SvCm0y+f8zE9cACQ5KQnFvNlojHvzmjO+Q==
74 -----END ENCRYPTED PRIVATE KEY-----
76 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -nocrypt -topk8 -in pkcs8-2.key ]]
77 openssl [list pkey -text -noout << $unencrypted]
80 test "Расшифровываем ключ, созданный mkkey, русский пароль" {
81 set env(PASS) [encoding convertfrom [encoding convertto utf-8 [rus "йцукенг"]]]
82 makeFile pkcs8-3.key "-----BEGIN ENCRYPTED PRIVATE KEY-----
83 MIGvMFUGCSqGSIb3DQEFDTBIMCcGCSqGSIb3DQEFDDAaBAgSfbLQ+fNe0AIC
84 CAAwCgYGKoUDAgIKBQAwHQYGKoUDAgIVMBMECJJ1Qd/rIBxqBgcqhQMCAh8B
85 BFZWfyFs12456ECvzNyg7LkPNAJS7qPih78kY4DJP7ty4bMydfCkfg20fMNl
86 O2zlJtg37z9vbhvqdWODCXc/XJ+Txmw3GLVDcvwQ/0woebcPlNUvMd9BzA==
87 -----END ENCRYPTED PRIVATE KEY-----
89 set unencrypted [openssl [list pkcs8 -passin env:PASS -nocrypt -topk8 -in pkcs8-3.key ]]
90 grep Private [openssl [list pkey -text -noout << $unencrypted]]
91 } 0 "Private key: 894150BCD66A400C198154D68E5817A6EF3546983863B57F6D04F5C14FD766CC\n"
93 set key256 "-----BEGIN PRIVATE KEY-----
94 MEgCAQAwHwYIKoUDBwEBAQEwEwYHKoUDAgIjAQYIKoUDBwEBAgIEIgIgK/ezK4Z5
95 GCo/srftX/HPs2AmcFKffF3/RWokTAKxMcM=
96 -----END PRIVATE KEY-----
99 test "Печатаем эталонный ключ gost2012_256" {
100 set etalon256 [openssl [list pkey -text -noout << $key256]]
101 } 0 "Private key: 2BF7B32B8679182A3FB2B7ED5FF1CFB3602670529F7C5DFF456A244C02B131C3
102 Parameter set: id-GostR3410-2001-CryptoPro-A-ParamSet
105 test "Конвертируем в DER и проверяем, что ключ тот же gost2012_256" {
106 openssl [list pkcs8 -outform DER -out pkcs8-256.der -nocrypt << $key]
107 openssl [list pkey -inform DER -text -noout -in pkcs8-256.der]
110 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
111 test "Зашифровываем незашифрованный ключ gost2012_256, параметры TK26 (умолчательные)" {
112 makeFile pkcs8-256.key $key256
113 catch {unset env(CRYPT_PARAMS)}
114 catch {unset env(GOST_PBE_HMAC)}
115 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-256.key -topk8 -out enc256.key << $key]
116 file exists enc256.key
118 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
120 test -skip {![file exists enc256.key]} "Проверяем OID-ы PBE" {
121 set res [extract_oids enc256.key]
122 regexp "HMAC GOST 34\.11-2012" $res && regexp "GOST .*89"
125 test "Расшифровываем зашифрованный ключ gost2012_256" {
126 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in enc256.key]]
127 openssl [list pkey -text -noout << $unencrypted]
131 set key512 "-----BEGIN PRIVATE KEY-----
132 MGsCAQAwIQYIKoUDBwEBAQIwFQYJKoUDBwECAQIBBggqhQMHAQECAwRDAkEAiCjF
133 2rwOmb5YwNnyObveusCDO+kw33jBijSrPiye155EO4ABz2aG8SHOTObVv4dFgtfZ
135 -----END PRIVATE KEY-----
138 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
139 test "Печатаем эталонный ключ gost2012_512" {
140 set etalon512 [openssl [list pkey -text -noout << $key512]]
141 } 0 "Private key: 8828C5DABC0E99BE58C0D9F239BBDEBAC0833BE930DF78C18A34AB3E2C9ED79E443B8001CF6686F121CE4CE6D5BF874582D7D983BC02B8E64DDC3E91481C8524
142 Parameter set: GOST R 34.10-2012 (512 bit) ParamSet A
145 test "Конвертируем в DER и проверяем, что ключ тот же gost2012_512" {
146 openssl [list pkcs8 -outform DER -out pkcs8-512.der -nocrypt << $key]
147 openssl [list pkey -inform DER -text -noout -in pkcs8-512.der]
150 test "Зашифровываем незашифрованный ключ gost2012_512, параметры TK26 (умолчательные)" {
151 makeFile pkcs8-512.key $key512
152 catch {unset env(CRYPT_PARAMS)}
153 set env(GOST_PBE_HMAC) "md_gost12_512"
154 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-512.key -topk8 -out enc512.key << $key]
155 file exists enc512.key
157 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
159 test -skip {![file exists enc512.key]} "Проверяем OID-ы PBE" {
160 set res [extract_oids enc512.key]
161 regexp "HMAC GOST 34\.11-2012" $res && regexp "GOST .*89"
164 test "Расшифровываем зашифрованный ключ gost2012 512 bit" {
165 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in enc512.key]]
166 openssl [list pkey -text -noout << $unencrypted]