--- files/sshd-r2.initd 2021-06-19 18:07:56.959555000 -0400 +++ /etc/init.d/sshd 2022-01-21 18:58:17.634927876 -0500 @@ -1,5 +1,5 @@ #!/sbin/openrc-run -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2022 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 extra_commands="checkconfig" @@ -10,6 +10,11 @@ extra_started_commands="reload" : ${SSHD_PIDFILE:=${RC_PREFIX%/}/run/${SVCNAME}.pid} : ${SSHD_BINARY:=${RC_PREFIX%/}/usr/sbin/sshd} : ${SSHD_KEYGEN_BINARY:=${RC_PREFIX%/}/usr/bin/ssh-keygen} +: ${SSHD_HOSTKEY_DSA_ENABLE="YES"} +: ${SSHD_HOSTKEY_ECDSA_ENABLE="YES"} +: ${SSHD_HOSTKEY_ED25519_ENABLE="YES"} +: ${SSHD_HOSTKEY_RSA_ENABLE="YES"} +: ${SSHD_HOSTKEY_XMSS_ENABLE="YES"} command="${SSHD_BINARY}" pidfile="${SSHD_PIDFILE}" @@ -46,17 +51,38 @@ depend() { fi } +gen_hostkey() { + local hkey_type="${1}" + [ -z ${hkey_type} ] && return 1 + + local hkey_file="${SSHD_CONFDIR}/ssh_host_${hkey_type}_key" + local hkey_type_upper="$(echo ${hkey_type} | tr "[:lower:]" "[:upper:]")" + local hkey_type_var="SSHD_HOSTKEY_${hkey_type_upper}_ENABLE" + local hkey_type_enable="$(eval echo "\$$hkey_type_var")" + + if yesno ${hkey_type_enable} && [ ! -f ${hkey_file} ] ; then + ${SSHD_KEYGEN_BINARY} -t ${hkey_type} -f ${hkey_file} -N '' || return 1 + fi +} + checkconfig() { checkpath --mode 0755 --directory "${RC_PREFIX%/}/var/empty" + # Check for sshd_config. if [ ! -e "${SSHD_CONFIG}" ] ; then eerror "You need an ${SSHD_CONFIG} file to run sshd" eerror "There is a sample file in /usr/share/doc/openssh" return 1 fi - ${SSHD_KEYGEN_BINARY} -A || return 2 + # HostKey generation. + gen_hostkey "dsa" || return 2 + gen_hostkey "ecdsa" || return 2 + gen_hostkey "ed25519" || return 2 + gen_hostkey "rsa" || return 2 + gen_hostkey "xmss" || return 2 + # Check sshd config file syntax "${command}" -t ${command_args} || return 3 }