1 # $OpenBSD: cert-hostkey.sh,v 1.3 2010/03/04 10:38:23 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}"
34 for privsep
in yes no
; do
35 for ktype
in rsa dsa
; do
36 verbose
"$tid: host ${ktype} cert connect privsep $privsep"
38 cat $OBJ/sshd_proxy_bak
39 echo HostKey
$OBJ/cert_host_key_
${ktype}
40 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
41 echo UsePrivilegeSeparation
$privsep
44 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
45 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
46 -F $OBJ/ssh_proxy somehost true
48 fail
"ssh cert connect failed"
53 # Revoked certificates with key present
55 echon
'@cert-authority '
57 cat $OBJ/host_ca_key.pub
60 cat $OBJ/cert_host_key_rsa.pub
63 cat $OBJ/cert_host_key_dsa.pub
64 ) > $OBJ/known_hosts-cert
65 for privsep
in yes no
; do
66 for ktype
in rsa dsa
; do
67 verbose
"$tid: host ${ktype} revoked cert privsep $privsep"
69 cat $OBJ/sshd_proxy_bak
70 echo HostKey
$OBJ/cert_host_key_
${ktype}
71 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
72 echo UsePrivilegeSeparation
$privsep
75 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
76 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
77 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
79 fail
"ssh cert connect succeeded unexpectedly"
86 echon
'@cert-authority '
88 cat $OBJ/host_ca_key.pub
91 cat $OBJ/host_ca_key.pub
92 ) > $OBJ/known_hosts-cert
93 for ktype
in rsa dsa
; do
94 verbose
"$tid: host ${ktype} revoked cert"
96 cat $OBJ/sshd_proxy_bak
97 echo HostKey
$OBJ/cert_host_key_
${ktype}
98 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
100 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
101 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
102 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
103 if [ $?
-eq 0 ]; then
104 fail
"ssh cert connect succeeded unexpectedly"
108 # Create a CA key and add it to known hosts
110 echon
'@cert-authority '
112 cat $OBJ/host_ca_key.pub
113 ) > $OBJ/known_hosts-cert
120 verbose
"$tid: test host cert connect $ident expect $result"
122 ${SSHKEYGEN} -q -s $OBJ/host_ca_key
-I "regress host key for $USER" \
124 $OBJ/cert_host_key_rsa ||
125 fail
"couldn't sign cert_host_key_rsa"
127 cat $OBJ/sshd_proxy_bak
128 echo HostKey
$OBJ/cert_host_key_rsa
129 echo HostCertificate
$OBJ/cert_host_key_rsa-cert.pub
132 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
133 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
134 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
136 if [ "x$result" = "xsuccess" ] ; then
137 if [ $rc -ne 0 ]; then
138 fail
"ssh cert connect $ident failed unexpectedly"
141 if [ $rc -eq 0 ]; then
142 fail
"ssh cert connect $ident succeeded unexpectedly"
147 test_one
"user-certificate" failure
"-n $HOSTS"
148 test_one
"empty principals" success
"-h"
149 test_one
"wrong principals" failure
"-h -n foo"
150 test_one
"cert not yet valid" failure
"-h -V20200101:20300101"
151 test_one
"cert expired" failure
"-h -V19800101:19900101"
152 test_one
"cert valid interval" success
"-h -V-1w:+2w"
153 test_one
"cert has constraints" failure
"-h -Oforce-command=false"
155 # Check downgrade of cert to raw key when no CA found
156 rm -f $OBJ/known_hosts-cert
$OBJ/cert_host_key
*
157 for ktype
in rsa dsa
; do
158 verbose
"$tid: host ${ktype} cert downgrade to raw key"
159 # Generate and sign a host key
160 ${SSHKEYGEN} -q -N '' -t ${ktype} \
161 -f $OBJ/cert_host_key_
${ktype} || \
162 fail
"ssh-keygen of cert_host_key_${ktype} failed"
163 ${SSHKEYGEN} -h -q -s $OBJ/host_ca_key
-I "regress host key for $USER" \
164 -n $HOSTS $OBJ/cert_host_key_
${ktype} ||
165 fail
"couldn't sign cert_host_key_${ktype}"
168 cat $OBJ/cert_host_key_
${ktype}.pub
169 ) > $OBJ/known_hosts-cert
171 cat $OBJ/sshd_proxy_bak
172 echo HostKey
$OBJ/cert_host_key_
${ktype}
173 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
176 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
177 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
178 -F $OBJ/ssh_proxy somehost true
179 if [ $?
-ne 0 ]; then
180 fail
"ssh cert connect failed"
186 echon
'@cert-authority '
188 cat $OBJ/host_ca_key.pub
189 ) > $OBJ/known_hosts-cert
190 for ktype
in rsa dsa
; do
192 ${SSHKEYGEN} -h -q -s $OBJ/cert_host_key_
${ktype} \
193 -I "regress host key for $USER" \
194 -n $HOSTS $OBJ/cert_host_key_
${ktype} ||
195 fail
"couldn't sign cert_host_key_${ktype}"
196 verbose
"$tid: host ${ktype} connect wrong cert"
198 cat $OBJ/sshd_proxy_bak
199 echo HostKey
$OBJ/cert_host_key_
${ktype}
200 echo HostCertificate
$OBJ/cert_host_key_
${ktype}-cert.pub
203 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
204 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
205 -F $OBJ/ssh_proxy
-q somehost true
>/dev
/null
2>&1
206 if [ $?
-eq 0 ]; then
207 fail
"ssh cert connect $ident succeeded unexpectedly"
211 rm -f $OBJ/known_hosts-cert
$OBJ/host_ca_key
* $OBJ/cert_host_key
*