- (dtucker) [configure.ac] Use a proper AC_CHECK_DECL for BROKEN_GETADDRINFO
[openssh-git.git] / regress / cert-hostkey.sh
blob3fda667cbab47f81bab10e9139b9b553374302d5
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 '
16 echon "$HOSTS "
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 done
33 # Basic connect tests
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
42 ) > $OBJ/sshd_proxy
44 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
45 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
46 -F $OBJ/ssh_proxy somehost true
47 if [ $? -ne 0 ]; then
48 fail "ssh cert connect failed"
50 done
51 done
53 # Revoked certificates with key present
55 echon '@cert-authority '
56 echon "$HOSTS "
57 cat $OBJ/host_ca_key.pub
58 echon '@revoked '
59 echon "* "
60 cat $OBJ/cert_host_key_rsa.pub
61 echon '@revoked '
62 echon "* "
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
73 ) > $OBJ/sshd_proxy
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
78 if [ $? -eq 0 ]; then
79 fail "ssh cert connect succeeded unexpectedly"
81 done
82 done
84 # Revoked CA
86 echon '@cert-authority '
87 echon "$HOSTS "
88 cat $OBJ/host_ca_key.pub
89 echon '@revoked '
90 echon "* "
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
99 ) > $OBJ/sshd_proxy
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"
106 done
108 # Create a CA key and add it to known hosts
110 echon '@cert-authority '
111 echon "$HOSTS "
112 cat $OBJ/host_ca_key.pub
113 ) > $OBJ/known_hosts-cert
115 test_one() {
116 ident=$1
117 result=$2
118 sign_opts=$3
120 verbose "$tid: test host cert connect $ident expect $result"
122 ${SSHKEYGEN} -q -s $OBJ/host_ca_key -I "regress host key for $USER" \
123 $sign_opts \
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
130 ) > $OBJ/sshd_proxy
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
135 rc=$?
136 if [ "x$result" = "xsuccess" ] ; then
137 if [ $rc -ne 0 ]; then
138 fail "ssh cert connect $ident failed unexpectedly"
140 else
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}"
167 echon "$HOSTS "
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
174 ) > $OBJ/sshd_proxy
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"
182 done
184 # Wrong certificate
186 echon '@cert-authority '
187 echon "$HOSTS "
188 cat $OBJ/host_ca_key.pub
189 ) > $OBJ/known_hosts-cert
190 for ktype in rsa dsa ; do
191 # Self-sign key
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
201 ) > $OBJ/sshd_proxy
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"
209 done
211 rm -f $OBJ/known_hosts-cert $OBJ/host_ca_key* $OBJ/cert_host_key*