aboutsummaryrefslogtreecommitdiff
path: root/tcl_tests/hwkeys.tcl
blob: 8c86a82201b7cb3f49fa78d600529199fe4ab945 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# -*- coding: cp1251 -*-
package require testlib

start_tests "Работа с аппаратными носителями"

if [info exists ::env(BASE_OPENSSL_CONF)] {
	set openssl_cnf [myfile openssl.cnf]
	set bf [open $::env(BASE_OPENSSL_CONF) r]
	set f [open $openssl_cnf w]
	set engines {}
	set in_engines 0
	while {[gets $bf line] >= 0} {
		puts $f $line
		if {[regexp {^\[engine_section\]} $line]} {
			puts $f "ce_filecnt_keys = cefk_section"
		}
	}
	close $bf
	if {$tcl_platform(platform) eq "windows"} {
		set lib_prefix	""
		set lib_suffix ".dll"
	} else {
		set lib_prefix "lib"
		set lib_suffix ".so"
	}	
	puts $f "\[cefk_section\]	
dynamic_path = \$ENV::TEST_ENGINE_DIR/${lib_prefix}ce_filecnt_keys$lib_suffix
engine_id = ce_filecnt_keys
default_algorithms = ALL
\[req\]
prompt=no
distinguished_name = req_dn
\[ req_dn \]
OU=OpenSSL Team
L=Moscow
CN=Dummy user
emailAddress=openssl@cryptocom.ru
O=Cryptocom
C=RU"
	close $f
	file copy  [file dirname $env(BASE_OPENSSL_CONF)]/cryptocom.lic [file dirname $openssl_cnf]/cryptocom.lic
	set ::env(OPENSSL_CONF) $openssl_cnf
	puts [logchannel] "OPENSSL_CONF=$::env(OPENSSL_CONF)"
	set ::env(TEST_ENGINE_DIR) [regsub {(/[^/]+)$} $::env(ENGINE_DIR) {/t\1}]
	puts [logchannel] "TEST_ENGINE_DIR=$::env(TEST_ENGINE_DIR)"
}

set cnt_pln_file [myfile cnt_pln]
set cnt_pln_dot_file [myfile cnt.pln.S]
set cnt_pln FILECNT=$cnt_pln_file
set cnt_enc_file [myfile cnt_enc]
set cnt_enc FILECNT=$cnt_enc_file
file copy -force ../cnt.pln $cnt_pln_file
file copy -force ../cnt.pln $cnt_pln_dot_file
file copy -force ../cnt.pln default_file_container
file copy -force ../cnt.enc $cnt_enc_file
set cntname "test keys"

file delete $cnt_enc_file.cmd $cnt_pln_file.cmd
eval [exec enums2tcl]

foreach K {S X} {
	set cert$K [myfile cert$K.pem]
	set pubk$K [myfile pubk$K.pem]
	upvar 0 cert$K cert pubk$K pubk

	test -title "$K: сертификат и его открытый ключ" -id cert$K {
		run openssl req -new -x509 -key $cnt_pln.$K -keyform ENGINE -engine cryptocom -out $cert
		run openssl x509 -pubkey -noout -in $cert
		file rename _stdout $pubk
	}

	test -title "$K: Подписываем файл закрытым ключом" -id sign$K -dep cert$K {
		run openssl dgst -md_gost94 -sign $cnt_pln.$K -keyform ENGINE -engine cryptocom -out $cert.sig $cert
	}

	test -title "$K: Проверяем подпись на закрытом ключе" -dep sign$K {
		run openssl dgst -md_gost94 -prverify $cnt_pln.$K -keyform ENGINE -engine cryptocom -signature $cert.sig $cert
	}

	test -title "$K: Проверяем подпись на открытом ключе" -dep sign$K {
		run openssl dgst -md_gost94 -verify $pubk -signature $cert.sig $cert
	}

	test -title "$K: Подписываем файл закрытым ключом, контейнер с именем" -id sign$K -dep cert$K {
		run openssl dgst -md_gost94 -sign $cnt_pln:$cntname.$K -keyform ENGINE -engine cryptocom -out $cert.sig $cert
	}

	test -title "$K: Подписываем файл запароленным закрытым ключом" -dep cert$K {
		run openssl dgst -md_gost94 -sign $cnt_enc.$K -keyform ENGINE -engine cryptocom -out $cert.sig -passin pass:abcdefghijklmnopqrstuvwxyz1234567890 $cert
		run openssl dgst -md_gost94 -verify $pubk -signature $cert.sig $cert
	}

}

test -title "Читаем по полной спецификации" {
	run hwkeys -load $cnt_pln:$cntname.S
}

test -title "Читаем без имени контейнера" {
	run hwkeys -load $cnt_pln.S
}

test -title "Читаем без имени носителя"  {
	run hwkeys -load FILECNT:$cntname.S
}

test -title "Читаем без имен контейнера и носителя" {
	run hwkeys -load FILECNT.S
}

test -title "Читаем с именем носителя, содержащим .S" {
	run hwkeys -load FILECNT=$cnt_pln_dot_file.S
}

end_tests

proc write_cmd_file {filename args} {
	set f [open filename w]
	fconfigure $f -encoding binary
	puts -nonewline $f [binary format c* $args]
	close $f
}

test -title "Читаем, нет носителя, нет коллбэка" {
	write_cmd_file $cnt_pln_file.cmd $cc_rc_no_contact
	run -fail -stderr {regex {cc_rds_read_key.*==cc_rc_no_contact.*load_key failed}} \
		hwkeys -no-cb -load $cnt_pln.S
}

test -title "Читаем, нет носителя, есть коллбэк, носитель дали"

test -title "Читаем, нет носителя, есть коллбэк, запрос отменили"

test -title "Читаем, есть носитель, нет контейнера"

test -title "Читаем, не тот контейнер, нет коллбэка"

test -title "Читаем, не тот контейнер, есть коллбэк, носитель поменяли, опять не тот, еще раз поменяли, теперь тот"

test -title "Читаем, не тот контейнер, есть коллбэк, запрос отменили"

test -title "Читаем, нет этого ключа (другой есть)"

test -title "Читаем, ошибка чтения, нет коллбэка"

test -title "Читаем, ошибка чтения, устранена"

test -title "Читаем, ошибка чтения, таймаут"

test -title "Читаем, ошибка чтения, отмена"

test -title "Читаем, не сошлась CRC ключа"

test -title "Читаем парольный, даем пароль"

test -title "Читаем парольный, даем пароль со второй попытки"

test -title "Читаем парольный, ошибка возврата пароля"

test -title "Читаем парольный, отмена"

test -title "Пишем в свежий контейнер"

test -title "Проверяем подписью, что это - тот же самый ключ"

test -title "Пишем в тот же контейнер второй ключ зашифрованным"

test -title "Проверяем подписью, что оно"

test -title "Пишем безымянный"

test -title "Пишем зашифрованный, пароли совпадают со второй попытки"

test -title "Пишем зашифрованный, ошибка получения пароля"

test -title "Пишем зашифрованный, отмена"

test -title "Ошибка записи, нет коллбэка"

test -title "Ошибка записи, вернули носитель"

test -title "Ошибка записи, таймаут"

test -title "Ошибка записи, отмена"

test -title "Нет носителя, нет коллбэка"

test -title "Нет носителя, дали"

test -title "Нет носителя, таймаут"

test -title "Нет носителя, отмена"

test -title "Не тот контейнер, нет перезаписи, нет коллбэка"

test -title "Не тот контейнер, нет перезаписи, сменили носитель"

test -title "Не тот контейнер, нет перезаписи, таймаут"

test -title "Не тот контейнер, нет перезаписи, отмена"

test -title "Не тот контейнер, есть перезапись"

test -title "Ключ есть, перезапись запрещена"

test -title "Ключ есть, перезапись разрешена"

test -title "Затираем"

test -title "Затираем, нет носителя, нет коллбэка"

test -title "Затираем, нет носителя, дали носитель"

test -title "Затираем, нет носителя, таймаут"

test -title "Затираем, нет носителя, отмена"

test -title "Затираем, не тот контейнер, нет коллбэка"

test -title "Затираем, не тот контейнер, сменили носитель"

test -title "Затираем, не тот контейнер, таймаут"

test -title "Затираем, не тот контейнер, отмена"

test -title "Затираем контейнер без имени, даем без имени"

test -title "Затираем контейнер без имени, даем с именем"