- (dtucker) [openbsd-compat/port-linux.c] Check is_selinux_enabled for exact
[openssh-git.git] / regress / cert-hostkey.sh
blob0265e8f6b04eefe69119fd97d90f347196e0d4be
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 '
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 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"
37 done
39 # Basic connect tests
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
48 ) > $OBJ/sshd_proxy
50 ${SSH} -2 -oUserKnownHostsFile=$OBJ/known_hosts-cert \
51 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
52 -F $OBJ/ssh_proxy somehost true
53 if [ $? -ne 0 ]; then
54 fail "ssh cert connect failed"
56 done
57 done
59 # Revoked certificates with key present
61 echon '@cert-authority '
62 echon "$HOSTS "
63 cat $OBJ/host_ca_key.pub
64 echon '@revoked '
65 echon "* "
66 cat $OBJ/cert_host_key_rsa.pub
67 echon '@revoked '
68 echon "* "
69 cat $OBJ/cert_host_key_dsa.pub
70 echon '@revoked '
71 echon "* "
72 cat $OBJ/cert_host_key_rsa_v00.pub
73 echon '@revoked '
74 echon "* "
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
85 ) > $OBJ/sshd_proxy
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
90 if [ $? -eq 0 ]; then
91 fail "ssh cert connect succeeded unexpectedly"
93 done
94 done
96 # Revoked CA
98 echon '@cert-authority '
99 echon "$HOSTS "
100 cat $OBJ/host_ca_key.pub
101 echon '@revoked '
102 echon "* "
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
111 ) > $OBJ/sshd_proxy
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"
118 done
120 # Create a CA key and add it to known hosts
122 echon '@cert-authority '
123 echon "$HOSTS "
124 cat $OBJ/host_ca_key.pub
125 ) > $OBJ/known_hosts-cert
127 test_one() {
128 ident=$1
129 result=$2
130 sign_opts=$3
132 for kt in rsa rsa_v00 ; do
133 case $kt in
134 *_v00) args="-t v00" ;;
135 *) args="" ;;
136 esac
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" \
141 $sign_opts $args \
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
148 ) > $OBJ/sshd_proxy
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
153 rc=$?
154 if [ "x$result" = "xsuccess" ] ; then
155 if [ $rc -ne 0 ]; then
156 fail "ssh cert connect $ident failed unexpectedly"
158 else
159 if [ $rc -eq 0 ]; then
160 fail "ssh cert connect $ident succeeded unexpectedly"
163 done
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}"
188 echon "$HOSTS "
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
195 ) > $OBJ/sshd_proxy
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"
203 done
204 done
206 # Wrong certificate
208 echon '@cert-authority '
209 echon "$HOSTS "
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*
215 # Self-sign 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
228 ) > $OBJ/sshd_proxy
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"
236 done
237 done
239 rm -f $OBJ/known_hosts-cert $OBJ/host_ca_key* $OBJ/cert_host_key*