1 # $OpenBSD: cert-userkey.sh,v 1.4 2010/04/16 01:58:45 djm Exp $
2 # Placed in the Public Domain.
4 tid
="certified user keys"
6 rm -f $OBJ/authorized_keys_
$USER $OBJ/user_ca_key
* $OBJ/cert_user_key
*
7 cp $OBJ/sshd_proxy
$OBJ/sshd_proxy_bak
10 ${SSHKEYGEN} -q -N '' -t rsa
-f $OBJ/user_ca_key ||\
11 fail
"ssh-keygen of user_ca_key failed"
13 # Generate and sign user keys
14 for ktype
in rsa dsa
; do
15 verbose
"$tid: sign user ${ktype} cert"
16 ${SSHKEYGEN} -q -N '' -t ${ktype} \
17 -f $OBJ/cert_user_key_
${ktype} || \
18 fail
"ssh-keygen of cert_user_key_${ktype} failed"
19 ${SSHKEYGEN} -q -s $OBJ/user_ca_key
-I \
20 "regress user key for $USER" \
21 -n $USER $OBJ/cert_user_key_
${ktype} ||
22 fail
"couldn't sign cert_user_key_${ktype}"
23 cp $OBJ/cert_user_key_
${ktype} $OBJ/cert_user_key_
${ktype}_v00
24 cp $OBJ/cert_user_key_
${ktype}.pub
$OBJ/cert_user_key_
${ktype}_v00.pub
25 ${SSHKEYGEN} -q -t v00
-s $OBJ/user_ca_key
-I \
26 "regress user key for $USER" \
27 -n $USER $OBJ/cert_user_key_
${ktype}_v00 ||
28 fail
"couldn't sign cert_user_key_${ktype}_v00"
33 if test "x$auth" = "xauthorized_keys" ; then
34 # Add CA to authorized_keys
36 echon
'cert-authority '
37 cat $OBJ/user_ca_key.pub
38 ) > $OBJ/authorized_keys_
$USER
40 echo > $OBJ/authorized_keys_
$USER
41 extra_sshd
="TrustedUserCAKeys $OBJ/user_ca_key.pub"
44 for ktype
in rsa dsa rsa_v00 dsa_v00
; do
45 for privsep
in yes no
; do
46 _prefix
="${ktype} privsep $privsep $auth"
48 verbose
"$tid: ${_prefix} connect"
50 cat $OBJ/sshd_proxy_bak
51 echo "UsePrivilegeSeparation $privsep"
55 ${SSH} -2i $OBJ/cert_user_key_
${ktype} \
56 -F $OBJ/ssh_proxy somehost true
58 fail
"ssh cert connect failed"
62 verbose
"$tid: ${_prefix} revoked key"
64 cat $OBJ/sshd_proxy_bak
65 echo "UsePrivilegeSeparation $privsep"
66 echo "RevokedKeys $OBJ/cert_user_key_${ktype}.pub"
69 ${SSH} -2i $OBJ/cert_user_key_
${ktype} \
70 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
72 fail
"ssh cert connect succeeded unexpecedly"
77 verbose
"$tid: ${ktype} $auth revoked CA key"
79 cat $OBJ/sshd_proxy_bak
80 echo "RevokedKeys $OBJ/user_ca_key.pub"
83 ${SSH} -2i $OBJ/cert_user_key_
${ktype} -F $OBJ/ssh_proxy \
84 somehost true
>/dev
/null
2>&1
86 fail
"ssh cert connect succeeded unexpecedly"
90 verbose
"$tid: $auth CA does not authenticate"
92 cat $OBJ/sshd_proxy_bak
95 verbose
"$tid: ensure CA key does not authenticate user"
96 ${SSH} -2i $OBJ/user_ca_key \
97 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
99 fail
"ssh cert connect with CA key succeeded unexpectedly"
103 basic_tests authorized_keys
104 basic_tests TrustedUserCAKeys
112 if test "x$auth_choice" = "x" ; then
113 auth_choice
="authorized_keys TrustedUserCAKeys"
116 for auth
in $auth_choice ; do
117 for ktype
in rsa rsa_v00
; do
118 cat $OBJ/sshd_proxy_bak
> $OBJ/sshd_proxy
119 if test "x$auth" = "xauthorized_keys" ; then
120 # Add CA to authorized_keys
122 echon
'cert-authority '
123 cat $OBJ/user_ca_key.pub
124 ) > $OBJ/authorized_keys_
$USER
126 echo > $OBJ/authorized_keys_
$USER
127 echo "TrustedUserCAKeys $OBJ/user_ca_key.pub" \
132 verbose
"$tid: $ident auth $auth expect $result $ktype"
133 ${SSHKEYGEN} -q -s $OBJ/user_ca_key \
134 -I "regress user key for $USER" \
136 $OBJ/cert_user_key_
${ktype} ||
137 fail
"couldn't sign cert_user_key_${ktype}"
139 ${SSH} -2i $OBJ/cert_user_key_
${ktype} \
140 -F $OBJ/ssh_proxy somehost true
>/dev
/null
2>&1
142 if [ "x$result" = "xsuccess" ] ; then
143 if [ $rc -ne 0 ]; then
144 fail
"$ident failed unexpectedly"
147 if [ $rc -eq 0 ]; then
148 fail
"$ident succeeded unexpectedly"
155 test_one
"correct principal" success
"-n ${USER}"
156 test_one
"host-certificate" failure
"-n ${USER} -h"
157 test_one
"wrong principals" failure
"-n foo"
158 test_one
"cert not yet valid" failure
"-n ${USER} -V20200101:20300101"
159 test_one
"cert expired" failure
"-n ${USER} -V19800101:19900101"
160 test_one
"cert valid interval" success
"-n ${USER} -V-1w:+2w"
161 test_one
"wrong source-address" failure
"-n ${USER} -Osource-address=10.0.0.0/8"
162 test_one
"force-command" failure
"-n ${USER} -Oforce-command=false"
164 # Behaviour is different here: TrustedUserCAKeys doesn't allow empty principals
165 test_one
"empty principals" success
"" authorized_keys
166 test_one
"empty principals" failure
"" TrustedUserCAKeys
169 for ktype
in rsa dsa rsa_v00 dsa_v00
; do
171 *_v00
) args
="-t v00" ;;
175 ${SSHKEYGEN} $args -q -s $OBJ/cert_user_key_
${ktype} -I \
176 "regress user key for $USER" \
177 -n $USER $OBJ/cert_user_key_
${ktype} ||
178 fail
"couldn't sign cert_user_key_${ktype}"
179 verbose
"$tid: user ${ktype} connect wrong cert"
180 ${SSH} -2i $OBJ/cert_user_key_
${ktype} -F $OBJ/ssh_proxy \
181 somehost true
>/dev
/null
2>&1
182 if [ $?
-eq 0 ]; then
183 fail
"ssh cert connect $ident succeeded unexpectedly"
187 rm -f $OBJ/authorized_keys_
$USER $OBJ/user_ca_key
* $OBJ/cert_user_key
*