diff options
author | Colin Watson <cjwatson@debian.org> | 2019-10-09 22:59:48 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2019-10-09 22:59:48 +0100 |
commit | 4213eec74e74de6310c27a40c3e9759a08a73996 (patch) | |
tree | e97a6dcafc6763aea7c804e4e113c2750cb1400d /regress/hostkey-rotate.sh | |
parent | 102062f825fb26a74295a1c089c00c4c4c76b68a (diff) | |
parent | cdf1d0a9f5d18535e0a18ff34860e81a6d83aa5c (diff) |
Import openssh_8.1p1.orig.tar.gz
Diffstat (limited to 'regress/hostkey-rotate.sh')
-rw-r--r-- | regress/hostkey-rotate.sh | 74 |
1 files changed, 44 insertions, 30 deletions
diff --git a/regress/hostkey-rotate.sh b/regress/hostkey-rotate.sh index d69de3255..cc6bd9cf6 100644 --- a/regress/hostkey-rotate.sh +++ b/regress/hostkey-rotate.sh | |||
@@ -1,10 +1,10 @@ | |||
1 | # $OpenBSD: hostkey-rotate.sh,v 1.5 2015/09/04 04:23:10 djm Exp $ | 1 | # $OpenBSD: hostkey-rotate.sh,v 1.6 2019/08/30 05:08:28 dtucker Exp $ |
2 | # Placed in the Public Domain. | 2 | # Placed in the Public Domain. |
3 | 3 | ||
4 | tid="hostkey rotate" | 4 | tid="hostkey rotate" |
5 | 5 | ||
6 | # Need full names here since they are used in HostKeyAlgorithms | 6 | # Need full names here since they are used in HostKeyAlgorithms |
7 | HOSTKEY_TYPES="ecdsa-sha2-nistp256 ssh-ed25519 ssh-rsa ssh-dss" | 7 | HOSTKEY_TYPES="`${SSH} -Q key-plain`" |
8 | 8 | ||
9 | rm -f $OBJ/hkr.* $OBJ/ssh_proxy.orig | 9 | rm -f $OBJ/hkr.* $OBJ/ssh_proxy.orig |
10 | 10 | ||
@@ -12,15 +12,23 @@ grep -vi 'hostkey' $OBJ/sshd_proxy > $OBJ/sshd_proxy.orig | |||
12 | echo "UpdateHostkeys=yes" >> $OBJ/ssh_proxy | 12 | echo "UpdateHostkeys=yes" >> $OBJ/ssh_proxy |
13 | rm $OBJ/known_hosts | 13 | rm $OBJ/known_hosts |
14 | 14 | ||
15 | # The "primary" key type is ed25519 since it's supported even when built | ||
16 | # without OpenSSL. The secondary is RSA if it's supported. | ||
17 | primary="ssh-ed25519" | ||
18 | secondary="$primary" | ||
19 | |||
15 | trace "prepare hostkeys" | 20 | trace "prepare hostkeys" |
16 | nkeys=0 | 21 | nkeys=0 |
17 | all_algs="" | 22 | all_algs="" |
18 | for k in `${SSH} -Q key-plain` ; do | 23 | for k in $HOSTKEY_TYPES; do |
19 | ${SSHKEYGEN} -qt $k -f $OBJ/hkr.$k -N '' || fatal "ssh-keygen $k" | 24 | ${SSHKEYGEN} -qt $k -f $OBJ/hkr.$k -N '' || fatal "ssh-keygen $k" |
20 | echo "Hostkey $OBJ/hkr.${k}" >> $OBJ/sshd_proxy.orig | 25 | echo "Hostkey $OBJ/hkr.${k}" >> $OBJ/sshd_proxy.orig |
21 | nkeys=`expr $nkeys + 1` | 26 | nkeys=`expr $nkeys + 1` |
22 | test "x$all_algs" = "x" || all_algs="${all_algs}," | 27 | test "x$all_algs" = "x" || all_algs="${all_algs}," |
23 | all_algs="${all_algs}$k" | 28 | all_algs="${all_algs}$k" |
29 | case "$k" in | ||
30 | ssh-rsa) secondary="ssh-rsa" ;; | ||
31 | esac | ||
24 | done | 32 | done |
25 | 33 | ||
26 | dossh() { | 34 | dossh() { |
@@ -49,62 +57,68 @@ cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy | |||
49 | # Connect to sshd with StrictHostkeyChecking=no | 57 | # Connect to sshd with StrictHostkeyChecking=no |
50 | verbose "learn hostkey with StrictHostKeyChecking=no" | 58 | verbose "learn hostkey with StrictHostKeyChecking=no" |
51 | >$OBJ/known_hosts | 59 | >$OBJ/known_hosts |
52 | dossh -oHostKeyAlgorithms=ssh-ed25519 -oStrictHostKeyChecking=no | 60 | dossh -oHostKeyAlgorithms=$primary -oStrictHostKeyChecking=no |
53 | # Verify no additional keys learned | 61 | # Verify no additional keys learned |
54 | expect_nkeys 1 "unstrict connect keys" | 62 | expect_nkeys 1 "unstrict connect keys" |
55 | check_key_present ssh-ed25519 || fail "unstrict didn't learn key" | 63 | check_key_present $primary || fail "unstrict didn't learn key" |
56 | 64 | ||
57 | # Connect to sshd as usual | 65 | # Connect to sshd as usual |
58 | verbose "learn additional hostkeys" | 66 | verbose "learn additional hostkeys" |
59 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=$all_algs | 67 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=$all_algs |
60 | # Check that other keys learned | 68 | # Check that other keys learned |
61 | expect_nkeys $nkeys "learn hostkeys" | 69 | expect_nkeys $nkeys "learn hostkeys" |
62 | check_key_present ssh-rsa || fail "didn't learn keys" | 70 | for k in $HOSTKEY_TYPES; do |
71 | check_key_present $k || fail "didn't learn keytype $k" | ||
72 | done | ||
63 | 73 | ||
64 | # Check each key type | 74 | # Check each key type |
65 | for k in `${SSH} -Q key-plain` ; do | 75 | for k in $HOSTKEY_TYPES; do |
66 | verbose "learn additional hostkeys, type=$k" | 76 | verbose "learn additional hostkeys, type=$k" |
67 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=$k,$all_algs | 77 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=$k,$all_algs |
68 | expect_nkeys $nkeys "learn hostkeys $k" | 78 | expect_nkeys $nkeys "learn hostkeys $k" |
69 | check_key_present $k || fail "didn't learn $k" | 79 | check_key_present $k || fail "didn't learn $k correctly" |
70 | done | 80 | done |
71 | 81 | ||
72 | # Change one hostkey (non primary) and relearn | 82 | # Change one hostkey (non primary) and relearn |
73 | verbose "learn changed non-primary hostkey" | 83 | if [ "$primary" != "$secondary" ]; then |
74 | mv $OBJ/hkr.ssh-rsa.pub $OBJ/hkr.ssh-rsa.pub.old | 84 | verbose "learn changed non-primary hostkey type=${secondary}" |
75 | rm -f $OBJ/hkr.ssh-rsa | 85 | mv $OBJ/hkr.${secondary}.pub $OBJ/hkr.${secondary}.pub.old |
76 | ${SSHKEYGEN} -qt ssh-rsa -f $OBJ/hkr.ssh-rsa -N '' || fatal "ssh-keygen $k" | 86 | rm -f $OBJ/hkr.${secondary} |
77 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=$all_algs | 87 | ${SSHKEYGEN} -qt ${secondary} -f $OBJ/hkr.${secondary} -N '' || \ |
78 | # Check that the key was replaced | 88 | fatal "ssh-keygen $secondary" |
79 | expect_nkeys $nkeys "learn hostkeys" | 89 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=$all_algs |
80 | check_key_present ssh-rsa $OBJ/hkr.ssh-rsa.pub.old && fail "old key present" | 90 | # Check that the key was replaced |
81 | check_key_present ssh-rsa || fail "didn't learn changed key" | 91 | expect_nkeys $nkeys "learn hostkeys" |
92 | check_key_present ${secondary} $OBJ/hkr.${secondary}.pub.old && \ | ||
93 | fail "old key present" | ||
94 | check_key_present ${secondary} || fail "didn't learn changed key" | ||
95 | fi | ||
82 | 96 | ||
83 | # Add new hostkey (primary type) to sshd and connect | 97 | # Add new hostkey (primary type) to sshd and connect |
84 | verbose "learn new primary hostkey" | 98 | verbose "learn new primary hostkey" |
85 | ${SSHKEYGEN} -qt ssh-rsa -f $OBJ/hkr.ssh-rsa-new -N '' || fatal "ssh-keygen $k" | 99 | ${SSHKEYGEN} -qt ${primary} -f $OBJ/hkr.${primary}-new -N '' || fatal "ssh-keygen ed25519" |
86 | ( cat $OBJ/sshd_proxy.orig ; echo HostKey $OBJ/hkr.ssh-rsa-new ) \ | 100 | ( cat $OBJ/sshd_proxy.orig ; echo HostKey $OBJ/hkr.${primary}-new ) \ |
87 | > $OBJ/sshd_proxy | 101 | > $OBJ/sshd_proxy |
88 | # Check new hostkey added | 102 | # Check new hostkey added |
89 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=ssh-rsa,$all_algs | 103 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=${primary},$all_algs |
90 | expect_nkeys `expr $nkeys + 1` "learn hostkeys" | 104 | expect_nkeys `expr $nkeys + 1` "learn hostkeys" |
91 | check_key_present ssh-rsa || fail "current key missing" | 105 | check_key_present ${primary} || fail "current key missing" |
92 | check_key_present ssh-rsa $OBJ/hkr.ssh-rsa-new.pub || fail "new key missing" | 106 | check_key_present ${primary} $OBJ/hkr.${primary}-new.pub || fail "new key missing" |
93 | 107 | ||
94 | # Remove old hostkey (primary type) from sshd | 108 | # Remove old hostkey (primary type) from sshd |
95 | verbose "rotate primary hostkey" | 109 | verbose "rotate primary hostkey" |
96 | cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy | 110 | cp $OBJ/sshd_proxy.orig $OBJ/sshd_proxy |
97 | mv $OBJ/hkr.ssh-rsa.pub $OBJ/hkr.ssh-rsa.pub.old | 111 | mv $OBJ/hkr.${primary}.pub $OBJ/hkr.${primary}.pub.old |
98 | mv $OBJ/hkr.ssh-rsa-new.pub $OBJ/hkr.ssh-rsa.pub | 112 | mv $OBJ/hkr.${primary}-new.pub $OBJ/hkr.${primary}.pub |
99 | mv $OBJ/hkr.ssh-rsa-new $OBJ/hkr.ssh-rsa | 113 | mv $OBJ/hkr.${primary}-new $OBJ/hkr.${primary} |
100 | # Check old hostkey removed | 114 | # Check old hostkey removed |
101 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=ssh-rsa,$all_algs | 115 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=${primary},$all_algs |
102 | expect_nkeys $nkeys "learn hostkeys" | 116 | expect_nkeys $nkeys "learn hostkeys" |
103 | check_key_present ssh-rsa $OBJ/hkr.ssh-rsa.pub.old && fail "old key present" | 117 | check_key_present ${primary} $OBJ/hkr.${primary}.pub.old && fail "old key present" |
104 | check_key_present ssh-rsa || fail "didn't learn changed key" | 118 | check_key_present ${primary} || fail "didn't learn changed key" |
105 | 119 | ||
106 | # Connect again, forcing rotated key | 120 | # Connect again, forcing rotated key |
107 | verbose "check rotate primary hostkey" | 121 | verbose "check rotate primary hostkey" |
108 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=ssh-rsa | 122 | dossh -oStrictHostKeyChecking=yes -oHostKeyAlgorithms=${primary} |
109 | expect_nkeys 1 "learn hostkeys" | 123 | expect_nkeys 1 "learn hostkeys" |
110 | check_key_present ssh-rsa || fail "didn't learn changed key" | 124 | check_key_present ${primary} || fail "didn't learn changed key" |