1 # $OpenBSD: cert-hostkey.sh,v 1.5 2010/08/31 12:24:09 djm Exp $
2 # Placed in the Public Domain.
4 tid
="certified host keys"
6 # used to disable ECC based tests on platforms without ECC
8 if grep "#define.*OPENSSL_HAS_ECC" ${BUILDDIR}/config.h
>/dev
/null
2>&1
13 rm -f $OBJ/known_hosts-cert
$OBJ/host_ca_key
* $OBJ/cert_host_key
*
14 cp $OBJ/sshd_proxy
$OBJ/sshd_proxy_bak
16 HOSTS
='localhost-with-alias,127.0.0.1,::1'
18 # Create a CA key and add it to known hosts
19 ${SSHKEYGEN} -q -N '' -t rsa
-f $OBJ/host_ca_key ||\
20 fail
"ssh-keygen of host_ca_key failed"
22 echon
'@cert-authority '
24 cat $OBJ/host_ca_key.pub
25 ) > $OBJ/known_hosts-cert
27 # Generate and sign host keys
28 for ktype
in rsa dsa
$ecdsa ; do
29 verbose
"$tid: sign host ${ktype} cert"
30 # Generate and sign a host key
31 ${SSHKEYGEN} -q -N '' -t ${ktype} \
32 -f $OBJ/cert_host_key_
${ktype} || \
33 fail
"ssh-keygen of cert_host_key_${ktype} failed"
34 ${SSHKEYGEN} -h -q -s $OBJ/host_ca_key \
35 -I "regress host key for $USER" \
36 -n $HOSTS $OBJ/cert_host_key_
${ktype} ||
37 fail
"couldn't sign cert_host_key_${ktype}"
38 # v00 ecdsa certs do not exist
39 test "{ktype}" = "ecdsa" && continue
40 cp $OBJ/cert_host_key_
${ktype} $OBJ/cert_host_key_
${ktype}_v00
41 cp $OBJ/cert_host_key_
${ktype}.pub
$OBJ/cert_host_key_
${ktype}_v00.pub
42 ${SSHKEYGEN} -t v00
-h -q -s $OBJ/host_ca_key \
43 -I "regress host key for $USER" \
44 -n $HOSTS $OBJ/cert_host_key_
${ktype}_v00 ||
45 fail
"couldn't sign cert_host_key_${ktype}_v00"
49 for privsep
in yes no
; do
50 for ktype
in rsa dsa
$ecdsa rsa_v00 dsa_v00
; do
51 verbose
"$tid: host ${ktype} cert connect privsep $privsep"
53 cat $OBJ/sshd_proxy_bak
54 echo HostKey
$OBJ/cert_host_key_
${ktype}
55 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
56 echo UsePrivilegeSeparation
$privsep
59 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
60 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
61 -F $OBJ/ssh_proxy somehost true
63 fail
"ssh cert connect failed"
68 # Revoked certificates with key present
70 echon
'@cert-authority '
72 cat $OBJ/host_ca_key.pub
75 cat $OBJ/cert_host_key_rsa.pub
78 cat $OBJ/cert_host_key_ecdsa.pub
81 cat $OBJ/cert_host_key_dsa.pub
84 cat $OBJ/cert_host_key_rsa_v00.pub
87 cat $OBJ/cert_host_key_dsa_v00.pub
88 ) > $OBJ/known_hosts-cert
89 for privsep
in yes no
; do
90 for ktype
in rsa dsa
$ecdsa rsa_v00 dsa_v00
; do
91 verbose
"$tid: host ${ktype} revoked cert privsep $privsep"
93 cat $OBJ/sshd_proxy_bak
94 echo HostKey
$OBJ/cert_host_key_
${ktype}
95 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
96 echo UsePrivilegeSeparation
$privsep
99 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
100 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
101 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
102 if [ $?
-eq 0 ]; then
103 fail
"ssh cert connect succeeded unexpectedly"
110 echon
'@cert-authority '
112 cat $OBJ/host_ca_key.pub
115 cat $OBJ/host_ca_key.pub
116 ) > $OBJ/known_hosts-cert
117 for ktype
in rsa dsa
$ecdsa rsa_v00 dsa_v00
; do
118 verbose
"$tid: host ${ktype} revoked cert"
120 cat $OBJ/sshd_proxy_bak
121 echo HostKey
$OBJ/cert_host_key_
${ktype}
122 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
124 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
125 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
126 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
127 if [ $?
-eq 0 ]; then
128 fail
"ssh cert connect succeeded unexpectedly"
132 # Create a CA key and add it to known hosts
134 echon
'@cert-authority '
136 cat $OBJ/host_ca_key.pub
137 ) > $OBJ/known_hosts-cert
144 for kt
in rsa rsa_v00
; do
146 *_v00
) args
="-t v00" ;;
150 verbose
"$tid: host cert connect $ident $kt expect $result"
151 ${SSHKEYGEN} -q -s $OBJ/host_ca_key \
152 -I "regress host key for $USER" \
154 $OBJ/cert_host_key_
${kt} ||
155 fail
"couldn't sign cert_host_key_${kt}"
157 cat $OBJ/sshd_proxy_bak
158 echo HostKey
$OBJ/cert_host_key_
${kt}
159 echo HostCertificate
$OBJ/cert_host_key_
${kt}-cert.pub
162 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
163 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
164 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
166 if [ "x$result" = "xsuccess" ] ; then
167 if [ $rc -ne 0 ]; then
168 fail
"ssh cert connect $ident failed unexpectedly"
171 if [ $rc -eq 0 ]; then
172 fail
"ssh cert connect $ident succeeded unexpectedly"
178 test_one
"user-certificate" failure
"-n $HOSTS"
179 test_one
"empty principals" success
"-h"
180 test_one
"wrong principals" failure
"-h -n foo"
181 test_one
"cert not yet valid" failure
"-h -V20200101:20300101"
182 test_one
"cert expired" failure
"-h -V19800101:19900101"
183 test_one
"cert valid interval" success
"-h -V-1w:+2w"
184 test_one
"cert has constraints" failure
"-h -Oforce-command=false"
186 # Check downgrade of cert to raw key when no CA found
187 for v
in v01 v00
; do
188 for ktype
in rsa dsa
$ecdsa ; do
189 # v00 ecdsa certs do not exist.
190 test "${v}${ktype}" = "v00ecdsa" && continue
191 rm -f $OBJ/known_hosts-cert
$OBJ/cert_host_key
*
192 verbose
"$tid: host ${ktype} ${v} cert downgrade to raw key"
193 # Generate and sign a host key
194 ${SSHKEYGEN} -q -N '' -t ${ktype} \
195 -f $OBJ/cert_host_key_
${ktype} || \
196 fail
"ssh-keygen of cert_host_key_${ktype} failed"
197 ${SSHKEYGEN} -t ${v} -h -q -s $OBJ/host_ca_key \
198 -I "regress host key for $USER" \
199 -n $HOSTS $OBJ/cert_host_key_
${ktype} ||
200 fail
"couldn't sign cert_host_key_${ktype}"
203 cat $OBJ/cert_host_key_
${ktype}.pub
204 ) > $OBJ/known_hosts-cert
206 cat $OBJ/sshd_proxy_bak
207 echo HostKey
$OBJ/cert_host_key_
${ktype}
208 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
211 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
212 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
213 -F $OBJ/ssh_proxy somehost true
214 if [ $?
-ne 0 ]; then
215 fail
"ssh cert connect failed"
222 echon
'@cert-authority '
224 cat $OBJ/host_ca_key.pub
225 ) > $OBJ/known_hosts-cert
226 for v
in v01 v00
; do
227 for kt
in rsa dsa
$ecdsa ; do
228 # v00 ecdsa certs do not exist.
229 test "${v}${ktype}" = "v00ecdsa" && continue
230 rm -f $OBJ/cert_host_key
*
232 ${SSHKEYGEN} -q -N '' -t ${kt} \
233 -f $OBJ/cert_host_key_
${kt} || \
234 fail
"ssh-keygen of cert_host_key_${kt} failed"
235 ${SSHKEYGEN} -t ${v} -h -q -s $OBJ/cert_host_key_${kt} \
236 -I "regress host key for $USER" \
237 -n $HOSTS $OBJ/cert_host_key_
${kt} ||
238 fail
"couldn't sign cert_host_key_${kt}"
239 verbose
"$tid: host ${kt} connect wrong cert"
241 cat $OBJ/sshd_proxy_bak
242 echo HostKey
$OBJ/cert_host_key_
${kt}
243 echo HostCertificate
$OBJ/cert_host_key_
${kt}-cert.pub
246 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
247 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
248 -F $OBJ/ssh_proxy
-q somehost true
>/dev
/null
2>&1
249 if [ $?
-eq 0 ]; then
250 fail
"ssh cert connect $ident succeeded unexpectedly"
255 rm -f $OBJ/known_hosts-cert
$OBJ/host_ca_key
* $OBJ/cert_host_key
*