2 # -*- coding: cp1251 -*-
3 lappend auto_path [file dirname [info script]]
5 package require ossltest
8 puts stderr "Usage $argv0 cipher-list-file"
20 get_hosts [lindex $argv 0]
22 start_tests "TLS-соединение от клиента [lindex $argv 0]"
24 set CAhost lynx.lan.cryptocom.ru
25 set CAprefix /cgi-bin/autoca
28 foreach alg [array names hosts] {
29 set alg2 [regsub {(gost\d+)cp} $alg {\1}]
30 set alg_fn [string map {":" "_"} $alg2]
31 set alg_ca [regexp -inline {^[^:]+} $alg]
33 if {[string match gost2001* $alg]} {
34 set alg_cli_list "gost2001_A gost2001_XA"
35 } elseif {[string match gost2012* $alg]} {
36 set alg_cli_list "gost2001_A gost2012_256_A gost2012_256_XA gost2012_512_A gost2012_512_B"
38 set alg_cli_list $alg_ca
42 test -skip {[file exist ca_$alg_ca.pem]} "Получить сертификат $alg_ca CA" {
43 getCAcert $CAhost $CAprefix $alg_ca
46 test -skip {[file exist srv_$alg_fn/cert.pem]} "Получить сертификат $alg для сервера" {
47 getCAAlgParams $CAhost $CAprefix $alg_ca
48 if {![makeUser srv_$alg_fn $alg2 CN [info hostname]]} {
49 error "Request generation failed"
51 registerUserAtCA srv_$alg_fn $CAhost $CAprefix $alg_ca
52 file exists srv_$alg_fn/cert.pem
55 if {[array exists suites]} {array unset suites}
56 array set suites $hosts($alg)
57 foreach suite [array names suites] {
58 if {![regexp {(.+):(.+)} $suite => proto cs]} {
62 if {[info exists suite_map($cs)]} {
63 set mycs $suite_map($cs)
67 set host [lindex [split $suites($suite) :] 0]
68 set host_short [lindex [split $host .] 0]
69 # We assume that CA certificates are already copied into Apache
71 set ca_file "/etc/apache/ssl.crt/${alg_ca}-root.crt"
73 test "Корректный хэндшейк $suite" {
75 set list [client_server [list -connect [info hostname]:4433 \
76 -CAfile $ca_file -state -cipher $cs] \
77 [concat [list -www -cert srv_$alg_fn/cert.pem \
78 -key srv_$alg_fn/seckey.pem -cipher $mycs] $protos($proto)] {}]
79 set cln_exit_code [lindex $list 2]
80 set srv_error [string match "*error*" [lindex $list 4]]
81 if {[regexp -lineanchor \
82 {^\s*Protocol\s*:\s*(\S*)\s*$.*^\s*Cipher\s*:\s*(\S*)\s*$} \
83 [lindex $list 0] -> result_proto result_cipher]} {
84 if {$proto == "default"} {set result_proto "default"}
85 list $cln_exit_code $srv_error $result_proto $result_cipher
89 } 0 [list 0 0 $proto $cs]
92 test "Сервер требует сертификат, сертификата нет $suite" {
94 set list [client_server [list -connect [info hostname]:4433 \
95 -CAfile $ca_file -state -cipher $cs] \
96 [concat [list -www -cert srv_$alg_fn/cert.pem \
97 -key srv_$alg_fn/seckey.pem -cipher $mycs -Verify 3 \
98 -verify_return_error] $protos($proto)] {}]
99 string match "*error*" [lindex $list 4]
103 test "Некорректный клиентский сертфиикат $suite" {
105 set list [client_server [list -connect [info hostname]:4433 \
106 -cert /home/build/client-$alg_ca/cert.pem \
107 -key /home/build/client-$alg_ca/seckey.pem \
108 -CAfile $ca_file -state -cipher $cs] \
109 [concat [list -www -cert srv_$alg_fn/cert.pem \
110 -key srv_$alg_fn/seckey.pem -cipher $mycs -Verify 3 \
111 -verify_return_error] $protos($proto)] {}]
112 string match "*error*" [lindex $list 4]
117 foreach alg_cli $alg_cli_list {
119 test "Клиентский сертификат $alg_cli $suite" {
121 set list [client_server [list -connect [info hostname]:4433 \
122 -cert /home/build/client-$alg_cli/cert.pem \
123 -key /home/build/client-$alg_cli/seckey.pem \
124 -CAfile $ca_file -state -cipher $cs] \
125 [concat [list -www -cert srv_$alg_fn/cert.pem \
126 -key srv_$alg_fn/seckey.pem -CAfile ca_$alg_ca.pem \
127 -cipher $mycs -Verify 3 -verify_return_error] \
129 set cln_exit_code [lindex $list 2]
130 set srv_error [string match "*error*" [lindex $list 4]]
131 if {[regexp -lineanchor \
132 {^\s*Protocol\s*:\s*(\S*)\s*$.*^\s*Cipher\s*:\s*(\S*)\s*$} \
133 [lindex $list 0] -> result_proto result_cipher]} {
134 if {$proto == "default"} {set result_proto "default"}
135 list $cln_exit_code $srv_error $result_proto $result_cipher
139 } 0 [list 0 0 $proto $cs]