summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/openssh/openssh/sshd_check_keys
diff options
context:
space:
mode:
authorJoshua Watt <jpewhacker@gmail.com>2017-07-03 20:18:18 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-09-25 14:14:16 +0100
commitae32558a19ae3b3f175365dc0e10fa74a91e28ce (patch)
tree6f5476c59bf2c89c13100f6b2ccf6497bfcf02d2 /meta/recipes-connectivity/openssh/openssh/sshd_check_keys
parentedcf39820f94c84b29c95a0d7b16b8d36857e87b (diff)
downloadpoky-ae32558a19ae3b3f175365dc0e10fa74a91e28ce.tar.gz
openssh: Fix key generation with systemd
106b59d9 broke SSH host key generation when systemd and a read-only root file system are in use because there isn't a way for systemd to get the optional weak assigment of SYSCONFDIR from /etc/default/sshd and still provide a default value if it is not specified. Instead, move the logic for determining if keys need to be created to a helper script that both the SysV init script and the systemd unit file can reference. This does mean that the systemd unit file can't check for file existence to know if it should start the service, but it wasn't able to do that correctly anyway anymore. This should be a problem since the serivce is only run once per power cycle by systemd, and should exit quickly if the keys already exist (From OE-Core rev: 7e49c5879862253ae1b6a26535d07a2740a95798) Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-connectivity/openssh/openssh/sshd_check_keys')
-rw-r--r--meta/recipes-connectivity/openssh/openssh/sshd_check_keys64
1 files changed, 64 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/openssh/openssh/sshd_check_keys b/meta/recipes-connectivity/openssh/openssh/sshd_check_keys
new file mode 100644
index 0000000000..f5bba53ca3
--- /dev/null
+++ b/meta/recipes-connectivity/openssh/openssh/sshd_check_keys
@@ -0,0 +1,64 @@
1#! /bin/sh
2
3# /etc/default/ssh may set SYSCONFDIR and SSHD_OPTS
4if test -f /etc/default/ssh; then
5 . /etc/default/ssh
6fi
7
8[ -z "$SYSCONFDIR" ] && SYSCONFDIR=/etc/ssh
9mkdir -p $SYSCONFDIR
10
11# parse sshd options
12set -- ${SSHD_OPTS} --
13sshd_config=/etc/ssh/sshd_config
14while true ; do
15 case "$1" in
16 -f*) if [ "$1" = "-f" ] ; then
17 sshd_config="$2"
18 shift
19 else
20 sshd_config="${1#-f}"
21 fi
22 shift
23 ;;
24 --) shift; break;;
25 *) shift;;
26 esac
27done
28
29# parse location of keys
30HOST_KEY_RSA=$(grep ^HostKey "${sshd_config}" | grep _rsa_ | tail -1 | awk ' { print $2 } ')
31[ -z "${HOST_KEY_RSA}" ] && HOST_KEY_RSA=$(grep HostKey "${sshd_config}" | grep _rsa_ | tail -1 | awk ' { print $2 } ')
32[ -z "${HOST_KEY_RSA}" ] && HOST_KEY_RSA=$SYSCONFDIR/ssh_host_rsa_key
33HOST_KEY_DSA=$(grep ^HostKey "${sshd_config}" | grep _dsa_ | tail -1 | awk ' { print $2 } ')
34[ -z "${HOST_KEY_DSA}" ] && HOST_KEY_DSA=$(grep HostKey "${sshd_config}" | grep _dsa_ | tail -1 | awk ' { print $2 } ')
35[ -z "${HOST_KEY_DSA}" ] && HOST_KEY_DSA=$SYSCONFDIR/ssh_host_dsa_key
36HOST_KEY_ECDSA=$(grep ^HostKey "${sshd_config}" | grep _ecdsa_ | tail -1 | awk ' { print $2 } ')
37[ -z "${HOST_KEY_ECDSA}" ] && HOST_KEY_ECDSA=$(grep HostKey "${sshd_config}" | grep _ecdsa_ | tail -1 | awk ' { print $2 } ')
38[ -z "${HOST_KEY_ECDSA}" ] && HOST_KEY_ECDSA=$SYSCONFDIR/ssh_host_ecdsa_key
39HOST_KEY_ED25519=$(grep ^HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | awk ' { print $2 } ')
40[ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$(grep HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | awk ' { print $2 } ')
41[ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key
42
43# create keys if necessary
44if [ ! -f $HOST_KEY_RSA ]; then
45 echo " generating ssh RSA key..."
46 mkdir -p $(dirname $HOST_KEY_RSA)
47 ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa
48fi
49if [ ! -f $HOST_KEY_ECDSA ]; then
50 echo " generating ssh ECDSA key..."
51 mkdir -p $(dirname $HOST_KEY_ECDSA)
52 ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa
53fi
54if [ ! -f $HOST_KEY_DSA ]; then
55 echo " generating ssh DSA key..."
56 mkdir -p $(dirname $HOST_KEY_DSA)
57 ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa
58fi
59if [ ! -f $HOST_KEY_ED25519 ]; then
60 echo " generating ssh ED25519 key..."
61 mkdir -p $(dirname $HOST_KEY_ED25519)
62 ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519
63fi
64