Lines Matching +full:touch +full:- +full:keys

1 #	$OpenBSD: cert-hostkey.sh,v 1.27 2021/09/30 05:26:26 dtucker Exp $
4 tid="certified host keys"
6 rm -f $OBJ/known_hosts-cert* $OBJ/host_ca_key* $OBJ/host_revoked_*
7 rm -f $OBJ/cert_host_key* $OBJ/host_krl_*
12 for i in `$SSH -Q key | maybe_filter_sk`; do
13 if [ -z "$types" ]; then
18 # Special treatment for RSA keys.
20 types="rsa-sha2-256-cert-v01@openssh.com,$i,$types"
21 types="rsa-sha2-512-cert-v01@openssh.com,$types";;
24 types="$types,rsa-sha2-512,rsa-sha2-256,$i";;
25 # Prefer certificate to plain keys.
40 HOSTS='localhost-with-alias,127.0.0.1,::1'
44 printf "@cert-authority $HOSTS "
59 ${SSHKEYGEN} -q -N '' -t ed25519 -f $OBJ/host_ca_key ||\
60 fail "ssh-keygen of host_ca_key failed"
61 ${SSHKEYGEN} -q -N '' -t $ktype2 -f $OBJ/host_ca_key2 ||\
62 fail "ssh-keygen of host_ca_key failed"
64 kh_ca host_ca_key.pub host_ca_key2.pub > $OBJ/known_hosts-cert.orig
65 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
68 touch $OBJ/host_revoked_empty
69 touch $OBJ/host_revoked_plain
70 touch $OBJ/host_revoked_cert
73 PLAIN_TYPES=`echo "$SSH_KEYTYPES" | sed 's/^ssh-dss/ssh-dsa/g;s/^ssh-//'`
76 PLAIN_TYPES="$PLAIN_TYPES rsa-sha2-256 rsa-sha2-512"
80 ${SSHKEYGEN} -kf $OBJ/host_krl_empty || fatal "KRL init failed"
81 ${SSHKEYGEN} -kf $OBJ/host_krl_plain || fatal "KRL init failed"
82 ${SSHKEYGEN} -kf $OBJ/host_krl_cert || fatal "KRL init failed"
83 ${SSHKEYGEN} -kf $OBJ/host_krl_ca $OBJ/host_ca_key.pub $OBJ/host_ca_key2.pub \
86 # Generate and sign host keys
91 ${SSHKEYGEN} -q -N '' -t ${ktype} \
92 -f $OBJ/cert_host_key_${ktype} || \
93 fatal "ssh-keygen of cert_host_key_${ktype} failed"
94 ${SSHKEYGEN} -ukf $OBJ/host_krl_plain \
98 rsa-sha2-*) tflag="-t $ktype"; ca="$OBJ/host_ca_key2" ;;
101 ${SSHKEYGEN} -h -q -s $ca -z $serial $tflag \
102 -I "regress host key for $USER" \
103 -n $HOSTS $OBJ/cert_host_key_${ktype} ||
105 ${SSHKEYGEN} -ukf $OBJ/host_krl_cert \
106 $OBJ/cert_host_key_${ktype}-cert.pub || \
108 cat $OBJ/cert_host_key_${ktype}-cert.pub >> $OBJ/host_revoked_cert
117 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
118 ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
119 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
120 "$@" -F $OBJ/ssh_proxy somehost true
123 if [ $_r -ne 0 ]; then
127 if [ $_r -eq 0 ]; then
139 echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
145 -oRevokedHostKeys=$OBJ/host_krl_empty
147 -oRevokedHostKeys=$OBJ/host_krl_plain
149 -oRevokedHostKeys=$OBJ/host_krl_cert
151 -oRevokedHostKeys=$OBJ/host_krl_ca
153 -oRevokedHostKeys=$OBJ/host_revoked_empty
155 -oRevokedHostKeys=$OBJ/host_revoked_plain
157 -oRevokedHostKeys=$OBJ/host_revoked_cert
159 -oRevokedHostKeys=$OBJ/host_revoked_ca
163 kh_ca host_ca_key.pub host_ca_key2.pub > $OBJ/known_hosts-cert.orig
165 test -f "$OBJ/cert_host_key_${ktype}.pub" || fatal "no pubkey"
166 kh_revoke cert_host_key_${ktype}.pub >> $OBJ/known_hosts-cert.orig
168 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
174 echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
177 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
178 ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
179 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
180 -F $OBJ/ssh_proxy somehost true >/dev/null 2>&1
181 if [ $? -eq 0 ]; then
187 kh_ca host_ca_key.pub host_ca_key2.pub > $OBJ/known_hosts-cert.orig
188 kh_revoke host_ca_key.pub host_ca_key2.pub >> $OBJ/known_hosts-cert.orig
189 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
195 echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
197 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
198 ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
199 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
200 -F $OBJ/ssh_proxy somehost true >/dev/null 2>&1
201 if [ $? -eq 0 ]; then
207 kh_ca host_ca_key.pub host_ca_key2.pub > $OBJ/known_hosts-cert.orig
208 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
217 rsa-sha2-*) tflag="-t $ktype"; ca="$OBJ/host_ca_key2" ;;
220 ${SSHKEYGEN} -q -s $ca $tflag -I "regress host key for $USER" \
226 echo HostCertificate $OBJ/cert_host_key_${kt}-cert.pub
229 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
230 ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
231 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
232 -F $OBJ/ssh_proxy somehost true >/dev/null 2>&1
235 if [ $rc -ne 0 ]; then
239 if [ $rc -eq 0 ]; then
246 test_one "user-certificate" failure "-n $HOSTS"
247 test_one "empty principals" success "-h"
248 test_one "wrong principals" failure "-h -n foo"
249 test_one "cert not yet valid" failure "-h -V20300101:20320101"
250 test_one "cert expired" failure "-h -V19800101:19900101"
251 test_one "cert valid interval" success "-h -V-1w:+2w"
252 test_one "cert has constraints" failure "-h -Oforce-command=false"
256 rm -f $OBJ/known_hosts-cert $OBJ/cert_host_key*
259 ${SSHKEYGEN} -q -N '' -t ${ktype} -f $OBJ/cert_host_key_${ktype} || \
260 fail "ssh-keygen of cert_host_key_${ktype} failed"
262 rsa-sha2-*) tflag="-t $ktype"; ca="$OBJ/host_ca_key2" ;;
265 ${SSHKEYGEN} -h -q $tflag -s $ca $tflag \
266 -I "regress host key for $USER" \
267 -n $HOSTS $OBJ/cert_host_key_${ktype} ||
272 ) > $OBJ/known_hosts-cert
276 echo HostCertificate $OBJ/cert_host_key_${ktype}-cert.pub
279 ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
280 -oGlobalKnownHostsFile=none -F $OBJ/ssh_proxy somehost true
281 if [ $? -ne 0 ]; then
286 ${SSH} -oUserKnownHostsFile="/dev/null $OBJ/known_hosts-cert" \
287 -oGlobalKnownHostsFile=none -F $OBJ/ssh_proxy somehost true
288 if [ $? -ne 0 ]; then
294 kh_ca host_ca_key.pub host_ca_key2.pub > $OBJ/known_hosts-cert.orig
295 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
298 rm -f $OBJ/cert_host_key*
299 # Self-sign key
300 ${SSHKEYGEN} -q -N '' -t ${kt} -f $OBJ/cert_host_key_${kt} || \
301 fail "ssh-keygen of cert_host_key_${kt} failed"
303 rsa-sha2-*) tflag="-t $kt" ;;
306 ${SSHKEYGEN} $tflag -h -q -s $OBJ/cert_host_key_${kt} \
307 -I "regress host key for $USER" \
308 -n $HOSTS $OBJ/cert_host_key_${kt} ||
313 echo HostCertificate $OBJ/cert_host_key_${kt}-cert.pub
316 cp $OBJ/known_hosts-cert.orig $OBJ/known_hosts-cert
317 ${SSH} -oUserKnownHostsFile=$OBJ/known_hosts-cert \
318 -oGlobalKnownHostsFile=$OBJ/known_hosts-cert \
319 -F $OBJ/ssh_proxy -q somehost true >/dev/null 2>&1
320 if [ $? -eq 0 ]; then
325 rm -f $OBJ/known_hosts-cert* $OBJ/host_ca_key* $OBJ/cert_host_key*