1 # $OpenBSD: cert-hostkey.sh,v 1.4 2010/04/16 01:58:45 djm Exp $
2 # Placed in the Public Domain.
4 tid
="certified host keys"
6 rm -f $OBJ/known_hosts-cert
$OBJ/host_ca_key
* $OBJ/cert_host_key
*
7 cp $OBJ/sshd_proxy
$OBJ/sshd_proxy_bak
9 HOSTS
='localhost-with-alias,127.0.0.1,::1'
11 # Create a CA key and add it to known hosts
12 ${SSHKEYGEN} -q -N '' -t rsa
-f $OBJ/host_ca_key ||\
13 fail
"ssh-keygen of host_ca_key failed"
15 echon
'@cert-authority '
17 cat $OBJ/host_ca_key.pub
18 ) > $OBJ/known_hosts-cert
20 # Generate and sign host keys
21 for ktype
in rsa dsa
; do
22 verbose
"$tid: sign host ${ktype} cert"
23 # Generate and sign a host key
24 ${SSHKEYGEN} -q -N '' -t ${ktype} \
25 -f $OBJ/cert_host_key_
${ktype} || \
26 fail
"ssh-keygen of cert_host_key_${ktype} failed"
27 ${SSHKEYGEN} -h -q -s $OBJ/host_ca_key \
28 -I "regress host key for $USER" \
29 -n $HOSTS $OBJ/cert_host_key_
${ktype} ||
30 fail
"couldn't sign cert_host_key_${ktype}"
31 cp $OBJ/cert_host_key_
${ktype} $OBJ/cert_host_key_
${ktype}_v00
32 cp $OBJ/cert_host_key_
${ktype}.pub
$OBJ/cert_host_key_
${ktype}_v00.pub
33 ${SSHKEYGEN} -t v00
-h -q -s $OBJ/host_ca_key \
34 -I "regress host key for $USER" \
35 -n $HOSTS $OBJ/cert_host_key_
${ktype}_v00 ||
36 fail
"couldn't sign cert_host_key_${ktype}_v00"
40 for privsep
in yes no
; do
41 for ktype
in rsa dsa rsa_v00 dsa_v00
; do
42 verbose
"$tid: host ${ktype} cert connect privsep $privsep"
44 cat $OBJ/sshd_proxy_bak
45 echo HostKey
$OBJ/cert_host_key_
${ktype}
46 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
47 echo UsePrivilegeSeparation
$privsep
50 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
51 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
52 -F $OBJ/ssh_proxy somehost true
54 fail
"ssh cert connect failed"
59 # Revoked certificates with key present
61 echon
'@cert-authority '
63 cat $OBJ/host_ca_key.pub
66 cat $OBJ/cert_host_key_rsa.pub
69 cat $OBJ/cert_host_key_dsa.pub
72 cat $OBJ/cert_host_key_rsa_v00.pub
75 cat $OBJ/cert_host_key_dsa_v00.pub
76 ) > $OBJ/known_hosts-cert
77 for privsep
in yes no
; do
78 for ktype
in rsa dsa rsa_v00 dsa_v00
; do
79 verbose
"$tid: host ${ktype} revoked cert privsep $privsep"
81 cat $OBJ/sshd_proxy_bak
82 echo HostKey
$OBJ/cert_host_key_
${ktype}
83 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
84 echo UsePrivilegeSeparation
$privsep
87 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
88 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
89 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
91 fail
"ssh cert connect succeeded unexpectedly"
98 echon
'@cert-authority '
100 cat $OBJ/host_ca_key.pub
103 cat $OBJ/host_ca_key.pub
104 ) > $OBJ/known_hosts-cert
105 for ktype
in rsa dsa rsa_v00 dsa_v00
; do
106 verbose
"$tid: host ${ktype} revoked cert"
108 cat $OBJ/sshd_proxy_bak
109 echo HostKey
$OBJ/cert_host_key_
${ktype}
110 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
112 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
113 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
114 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
115 if [ $?
-eq 0 ]; then
116 fail
"ssh cert connect succeeded unexpectedly"
120 # Create a CA key and add it to known hosts
122 echon
'@cert-authority '
124 cat $OBJ/host_ca_key.pub
125 ) > $OBJ/known_hosts-cert
132 for kt
in rsa rsa_v00
; do
134 *_v00
) args
="-t v00" ;;
138 verbose
"$tid: host cert connect $ident $kt expect $result"
139 ${SSHKEYGEN} -q -s $OBJ/host_ca_key \
140 -I "regress host key for $USER" \
142 $OBJ/cert_host_key_
${kt} ||
143 fail
"couldn't sign cert_host_key_${kt}"
145 cat $OBJ/sshd_proxy_bak
146 echo HostKey
$OBJ/cert_host_key_
${kt}
147 echo HostCertificate
$OBJ/cert_host_key_
${kt}-cert.pub
150 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
151 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
152 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
154 if [ "x$result" = "xsuccess" ] ; then
155 if [ $rc -ne 0 ]; then
156 fail
"ssh cert connect $ident failed unexpectedly"
159 if [ $rc -eq 0 ]; then
160 fail
"ssh cert connect $ident succeeded unexpectedly"
166 test_one
"user-certificate" failure
"-n $HOSTS"
167 test_one
"empty principals" success
"-h"
168 test_one
"wrong principals" failure
"-h -n foo"
169 test_one
"cert not yet valid" failure
"-h -V20200101:20300101"
170 test_one
"cert expired" failure
"-h -V19800101:19900101"
171 test_one
"cert valid interval" success
"-h -V-1w:+2w"
172 test_one
"cert has constraints" failure
"-h -Oforce-command=false"
174 # Check downgrade of cert to raw key when no CA found
175 for v
in v01 v00
; do
176 for ktype
in rsa dsa
; do
177 rm -f $OBJ/known_hosts-cert
$OBJ/cert_host_key
*
178 verbose
"$tid: host ${ktype} ${v} cert downgrade to raw key"
179 # Generate and sign a host key
180 ${SSHKEYGEN} -q -N '' -t ${ktype} \
181 -f $OBJ/cert_host_key_
${ktype} || \
182 fail
"ssh-keygen of cert_host_key_${ktype} failed"
183 ${SSHKEYGEN} -t ${v} -h -q -s $OBJ/host_ca_key \
184 -I "regress host key for $USER" \
185 -n $HOSTS $OBJ/cert_host_key_
${ktype} ||
186 fail
"couldn't sign cert_host_key_${ktype}"
189 cat $OBJ/cert_host_key_
${ktype}.pub
190 ) > $OBJ/known_hosts-cert
192 cat $OBJ/sshd_proxy_bak
193 echo HostKey
$OBJ/cert_host_key_
${ktype}
194 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
197 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
198 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
199 -F $OBJ/ssh_proxy somehost true
200 if [ $?
-ne 0 ]; then
201 fail
"ssh cert connect failed"
208 echon
'@cert-authority '
210 cat $OBJ/host_ca_key.pub
211 ) > $OBJ/known_hosts-cert
212 for v
in v01 v00
; do
213 for kt
in rsa dsa
; do
214 rm -f $OBJ/cert_host_key
*
216 ${SSHKEYGEN} -q -N '' -t ${kt} \
217 -f $OBJ/cert_host_key_
${kt} || \
218 fail
"ssh-keygen of cert_host_key_${kt} failed"
219 ${SSHKEYGEN} -t ${v} -h -q -s $OBJ/cert_host_key_${kt} \
220 -I "regress host key for $USER" \
221 -n $HOSTS $OBJ/cert_host_key_
${kt} ||
222 fail
"couldn't sign cert_host_key_${kt}"
223 verbose
"$tid: host ${kt} connect wrong cert"
225 cat $OBJ/sshd_proxy_bak
226 echo HostKey
$OBJ/cert_host_key_
${kt}
227 echo HostCertificate
$OBJ/cert_host_key_
${kt}-cert.pub
230 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
231 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
232 -F $OBJ/ssh_proxy
-q somehost true
>/dev
/null
2>&1
233 if [ $?
-eq 0 ]; then
234 fail
"ssh cert connect $ident succeeded unexpectedly"
239 rm -f $OBJ/known_hosts-cert
$OBJ/host_ca_key
* $OBJ/cert_host_key
*