summaryrefslogtreecommitdiffstats
path: root/meta/recipes-connectivity/openssh/openssh/init
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/init
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/init')
-rw-r--r--meta/recipes-connectivity/openssh/openssh/init69
1 files changed, 3 insertions, 66 deletions
diff --git a/meta/recipes-connectivity/openssh/openssh/init b/meta/recipes-connectivity/openssh/openssh/init
index 386628afc8..34ba0f8460 100644
--- a/meta/recipes-connectivity/openssh/openssh/init
+++ b/meta/recipes-connectivity/openssh/openssh/init
@@ -19,25 +19,6 @@ fi
19[ -z "$SYSCONFDIR" ] && SYSCONFDIR=/etc/ssh 19[ -z "$SYSCONFDIR" ] && SYSCONFDIR=/etc/ssh
20mkdir -p $SYSCONFDIR 20mkdir -p $SYSCONFDIR
21 21
22parse_sshd_opts() {
23 set -- ${SSHD_OPTS} --
24 sshd_config=/etc/ssh/sshd_config
25 while true ; do
26 case "$1" in
27 -f*) if [ "$1" = "-f" ] ; then
28 sshd_config="$2"
29 shift
30 else
31 sshd_config="${1#-f}"
32 fi
33 shift
34 ;;
35 --) shift; break;;
36 *) shift;;
37 esac
38 done
39}
40
41check_for_no_start() { 22check_for_no_start() {
42 # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists 23 # forget it if we're trying to start, and /etc/ssh/sshd_not_to_be_run exists
43 if [ -e $SYSCONFDIR/sshd_not_to_be_run ]; then 24 if [ -e $SYSCONFDIR/sshd_not_to_be_run ]; then
@@ -58,57 +39,13 @@ check_config() {
58 /usr/sbin/sshd -t $SSHD_OPTS || exit 1 39 /usr/sbin/sshd -t $SSHD_OPTS || exit 1
59} 40}
60 41
61check_keys() {
62 # parse location of keys
63 local HOST_KEY_RSA
64 local HOST_KEY_DSA
65 local HOST_KEY_ECDSA
66 local HOST_KEY_ED25519
67
68 parse_sshd_opts
69 HOST_KEY_RSA=$(grep ^HostKey "${sshd_config}" | grep _rsa_ | tail -1 | awk ' { print $2 } ')
70 [ -z "${HOST_KEY_RSA}" ] && HOST_KEY_RSA=$(grep HostKey "${sshd_config}" | grep _rsa_ | tail -1 | awk ' { print $2 } ')
71 [ -z "${HOST_KEY_RSA}" ] && HOST_KEY_RSA=$SYSCONFDIR/ssh_host_rsa_key
72 HOST_KEY_DSA=$(grep ^HostKey "${sshd_config}" | grep _dsa_ | tail -1 | awk ' { print $2 } ')
73 [ -z "${HOST_KEY_DSA}" ] && HOST_KEY_DSA=$(grep HostKey "${sshd_config}" | grep _dsa_ | tail -1 | awk ' { print $2 } ')
74 [ -z "${HOST_KEY_DSA}" ] && HOST_KEY_DSA=$SYSCONFDIR/ssh_host_dsa_key
75 HOST_KEY_ECDSA=$(grep ^HostKey "${sshd_config}" | grep _ecdsa_ | tail -1 | awk ' { print $2 } ')
76 [ -z "${HOST_KEY_ECDSA}" ] && HOST_KEY_ECDSA=$(grep HostKey "${sshd_config}" | grep _ecdsa_ | tail -1 | awk ' { print $2 } ')
77 [ -z "${HOST_KEY_ECDSA}" ] && HOST_KEY_ECDSA=$SYSCONFDIR/ssh_host_ecdsa_key
78 HOST_KEY_ED25519=$(grep ^HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | awk ' { print $2 } ')
79 [ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$(grep HostKey "${sshd_config}" | grep _ed25519_ | tail -1 | awk ' { print $2 } ')
80 [ -z "${HOST_KEY_ED25519}" ] && HOST_KEY_ED25519=$SYSCONFDIR/ssh_host_ed25519_key
81
82 # create keys if necessary
83 if [ ! -f $HOST_KEY_RSA ]; then
84 echo " generating ssh RSA key..."
85 mkdir -p $(dirname $HOST_KEY_RSA)
86 ssh-keygen -q -f $HOST_KEY_RSA -N '' -t rsa
87 fi
88 if [ ! -f $HOST_KEY_ECDSA ]; then
89 echo " generating ssh ECDSA key..."
90 mkdir -p $(dirname $HOST_KEY_ECDSA)
91 ssh-keygen -q -f $HOST_KEY_ECDSA -N '' -t ecdsa
92 fi
93 if [ ! -f $HOST_KEY_DSA ]; then
94 echo " generating ssh DSA key..."
95 mkdir -p $(dirname $HOST_KEY_DSA)
96 ssh-keygen -q -f $HOST_KEY_DSA -N '' -t dsa
97 fi
98 if [ ! -f $HOST_KEY_ED25519 ]; then
99 echo " generating ssh ED25519 key..."
100 mkdir -p $(dirname $HOST_KEY_ED25519)
101 ssh-keygen -q -f $HOST_KEY_ED25519 -N '' -t ed25519
102 fi
103}
104
105export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" 42export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
106 43
107case "$1" in 44case "$1" in
108 start) 45 start)
109 check_for_no_start 46 check_for_no_start
110 echo "Starting OpenBSD Secure Shell server: sshd" 47 echo "Starting OpenBSD Secure Shell server: sshd"
111 check_keys 48 @LIBEXECDIR@/sshd_check_keys
112 check_privsep_dir 49 check_privsep_dir
113 start-stop-daemon -S -p $PIDFILE -x /usr/sbin/sshd -- $SSHD_OPTS 50 start-stop-daemon -S -p $PIDFILE -x /usr/sbin/sshd -- $SSHD_OPTS
114 echo "done." 51 echo "done."
@@ -121,7 +58,7 @@ case "$1" in
121 58
122 reload|force-reload) 59 reload|force-reload)
123 check_for_no_start 60 check_for_no_start
124 check_keys 61 @LIBEXECDIR@/sshd_check_keys
125 check_config 62 check_config
126 echo -n "Reloading OpenBSD Secure Shell server's configuration" 63 echo -n "Reloading OpenBSD Secure Shell server's configuration"
127 start-stop-daemon -K -p $PIDFILE -s 1 -x /usr/sbin/sshd 64 start-stop-daemon -K -p $PIDFILE -s 1 -x /usr/sbin/sshd
@@ -129,7 +66,7 @@ case "$1" in
129 ;; 66 ;;
130 67
131 restart) 68 restart)
132 check_keys 69 @LIBEXECDIR@/sshd_check_keys
133 check_config 70 check_config
134 echo -n "Restarting OpenBSD Secure Shell server: sshd" 71 echo -n "Restarting OpenBSD Secure Shell server: sshd"
135 start-stop-daemon -K -p $PIDFILE --oknodo -x /usr/sbin/sshd 72 start-stop-daemon -K -p $PIDFILE --oknodo -x /usr/sbin/sshd