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
16 X:3A5EB29A20FAB84B58ADECB6F27EBAF2F21FE12122A5B1CF0ACEDD52756F238E
17 Y:D2CB63A5699267CDA88FABA9E417C5931FA106B07D6853D9B70BACB4E592A6CC
18 Parameter set: id-GostR3410-2001-CryptoPro-A-ParamSet
21 test "Конвертируем в DER и проверяем, что ключ тот же gost2001" {
22 openssl [list pkcs8 -outform DER -out pkcs8-1.der -nocrypt << $key]
23 openssl [list pkey -inform DER -text -noout -in pkcs8-1.der]
27 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
28 test "Зашифровываем незашифрованный ключ gost2001, параметры CryptoPro-A" {
29 makeFile pkcs8-1A.key $key
30 set env(CRYPT_PARAMS) "id-Gost28147-89-CryptoPro-A-ParamSet"
31 set env(GOST_PBE_HMAC) "md_gost94"
32 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-1A.key -topk8 -out encA.key << $key]
35 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
37 test -skip {![file exists encA.key]} "Проверяем OID-ы PBE" {
38 set res [extract_oids encA.key]
39 regexp "HMAC GOST 34\.11-94" $res && regexp "GOST .*89"
42 test "Расшифровываем зашифрованный ключ gost2001" {
43 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in encA.key]]
44 openssl [list pkey -text -noout << $unencrypted]
48 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
49 test "Зашифровываем незашифрованный ключ gost2001, параметры CryptoPro-B" {
50 makeFile pkcs8-1B.key $key
51 set env(CRYPT_PARAMS) "id-Gost28147-89-CryptoPro-B-ParamSet"
52 set env(GOST_PBE_HMAC) "md_gost94"
53 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-1B.key -topk8 -out encB.key << $key]
56 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
58 test -skip {![file exists encB.key]} "Проверяем OID-ы PBE" {
59 set res [extract_oids encB.key]
60 regexp "HMAC GOST 34\.11-94" $res && regexp "GOST .*89"
64 test "Расшифровываем зашифрованный ключ gost2001" {
65 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in encB.key]]
66 openssl [list pkey -text -noout << $unencrypted]
71 test "Расшифровываем ключ, созданный mkkey" {
72 makeFile pkcs8-2.key "-----BEGIN ENCRYPTED PRIVATE KEY-----
73 MIGvMFUGCSqGSIb3DQEFDTBIMCcGCSqGSIb3DQEFDDAaBAjIvbrnGmGbTAIC
74 CAAwCgYGKoUDAgIKBQAwHQYGKoUDAgIVMBMECOtWtCMQo3dzBgcqhQMCAh8B
75 BFZFPKP6qDKi57rmas1U2fUjyZwjmrk6Y+naeWG/BTVJNJklW3HaHP+wuIFb
76 bxdi6rTNsYqxWm26qUHz6Op5SvCm0y+f8zE9cACQ5KQnFvNlojHvzmjO+Q==
77 -----END ENCRYPTED PRIVATE KEY-----
79 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -nocrypt -topk8 -in pkcs8-2.key ]]
80 openssl [list pkey -text -noout << $unencrypted]
83 test "Расшифровываем ключ, созданный mkkey, русский пароль" {
84 set env(PASS) [encoding convertfrom [encoding convertto utf-8 [rus "йцукенг"]]]
85 makeFile pkcs8-3.key "-----BEGIN ENCRYPTED PRIVATE KEY-----
86 MIGvMFUGCSqGSIb3DQEFDTBIMCcGCSqGSIb3DQEFDDAaBAgSfbLQ+fNe0AIC
87 CAAwCgYGKoUDAgIKBQAwHQYGKoUDAgIVMBMECJJ1Qd/rIBxqBgcqhQMCAh8B
88 BFZWfyFs12456ECvzNyg7LkPNAJS7qPih78kY4DJP7ty4bMydfCkfg20fMNl
89 O2zlJtg37z9vbhvqdWODCXc/XJ+Txmw3GLVDcvwQ/0woebcPlNUvMd9BzA==
90 -----END ENCRYPTED PRIVATE KEY-----
92 set unencrypted [openssl [list pkcs8 -passin env:PASS -nocrypt -topk8 -in pkcs8-3.key ]]
93 grep Private [openssl [list pkey -text -noout << $unencrypted]]
94 } 0 "Private key: 894150BCD66A400C198154D68E5817A6EF3546983863B57F6D04F5C14FD766CC\n"
96 set key256 "-----BEGIN PRIVATE KEY-----
97 MEgCAQAwHwYIKoUDBwEBAQEwEwYHKoUDAgIjAQYIKoUDBwEBAgIEIgIgK/ezK4Z5
98 GCo/srftX/HPs2AmcFKffF3/RWokTAKxMcM=
99 -----END PRIVATE KEY-----
102 test "Печатаем эталонный ключ gost2012_256" {
103 set etalon256 [openssl [list pkey -text -noout << $key256]]
104 } 0 "Private key: 2BF7B32B8679182A3FB2B7ED5FF1CFB3602670529F7C5DFF456A244C02B131C3
106 X:AEE47DB40193567F54626017CD98EC2FA1BD72CC2F73F7D0D517C61F1F83F3C8
107 Y:3AED4E504E0E470F0C1DEE399A440A791C45C42539E56F9AECCB63ABF3FC2F1F
108 Parameter set: id-GostR3410-2001-CryptoPro-A-ParamSet
111 test "Конвертируем в DER и проверяем, что ключ тот же gost2012_256" {
112 openssl [list pkcs8 -outform DER -out pkcs8-256.der -nocrypt << $key]
113 openssl [list pkey -inform DER -text -noout -in pkcs8-256.der]
116 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
117 test "Зашифровываем незашифрованный ключ gost2012_256, параметры TK26 (умолчательные)" {
118 makeFile pkcs8-256.key $key256
119 catch {unset env(CRYPT_PARAMS)}
120 catch {unset env(GOST_PBE_HMAC)}
121 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-256.key -topk8 -out enc256.key << $key]
122 file exists enc256.key
124 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
126 test -skip {![file exists enc256.key]} "Проверяем OID-ы PBE" {
127 set res [extract_oids enc256.key]
128 regexp "HMAC GOST 34\.11-2012" $res && regexp "GOST .*89"
131 test "Расшифровываем зашифрованный ключ gost2012_256" {
132 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in enc256.key]]
133 openssl [list pkey -text -noout << $unencrypted]
137 set key512 "-----BEGIN PRIVATE KEY-----
138 MGsCAQAwIQYIKoUDBwEBAQIwFQYJKoUDBwECAQIBBggqhQMHAQECAwRDAkEAiCjF
139 2rwOmb5YwNnyObveusCDO+kw33jBijSrPiye155EO4ABz2aG8SHOTObVv4dFgtfZ
141 -----END PRIVATE KEY-----
144 save_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
145 test "Печатаем эталонный ключ gost2012_512" {
146 set etalon512 [openssl [list pkey -text -noout << $key512]]
147 } 0 "Private key: 8828C5DABC0E99BE58C0D9F239BBDEBAC0833BE930DF78C18A34AB3E2C9ED79E443B8001CF6686F121CE4CE6D5BF874582D7D983BC02B8E64DDC3E91481C8524
149 X:C9303D4DF7601366C35F1F79B735257FFBBABBBAF80AA89C52C385A4BF2FFBE922CDDD2C96842D3BFBB0BA06F00A3A92D5304386EEFA0F711C7AD9C360513DC
150 Y:12A3A22F5C29640628DB2676FF922429D67D646F8D73EA2C9675B17E3183B300B9D726930CBBD45CF294242DAE07E54C25ED12D5A4D453CB82D4706B1CF2D7B8
151 Parameter set: GOST R 34.10-2012 (512 bit) ParamSet A
154 test "Конвертируем в DER и проверяем, что ключ тот же gost2012_512" {
155 openssl [list pkcs8 -outform DER -out pkcs8-512.der -nocrypt << $key]
156 openssl [list pkey -inform DER -text -noout -in pkcs8-512.der]
159 test "Зашифровываем незашифрованный ключ gost2012_512, параметры TK26 (умолчательные)" {
160 makeFile pkcs8-512.key $key512
161 catch {unset env(CRYPT_PARAMS)}
162 set env(GOST_PBE_HMAC) "md_gost12_512"
163 openssl [list pkcs8 -v2 gost89 -passout pass:qwertyu -in pkcs8-512.key -topk8 -out enc512.key << $key]
164 file exists enc512.key
166 restore_env2 {CRYPT_PARAMS GOST_PBE_HMAC}
168 test -skip {![file exists enc512.key]} "Проверяем OID-ы PBE" {
169 set res [extract_oids enc512.key]
170 regexp "HMAC GOST 34\.11-2012" $res && regexp "GOST .*89"
173 test "Расшифровываем зашифрованный ключ gost2012 512 bit" {
174 set unencrypted [openssl [list pkcs8 -passin pass:qwertyu -topk8 -nocrypt -in enc512.key]]
175 openssl [list pkey -text -noout << $unencrypted]