From 4253bf87ac517354b4bf92e1f29fec2625173a49 Mon Sep 17 00:00:00 2001 From: Petr Lautrbach Date: Jun 03 2014 15:41:32 +0000 Subject: add support for ED25519 keys to sshd-keygen and sshd.sysconfig --- diff --git a/sshd-keygen b/sshd-keygen index d54e4b9..eaf14f8 100644 --- a/sshd-keygen +++ b/sshd-keygen @@ -4,7 +4,7 @@ # # The creation is controlled by the $AUTOCREATE_SERVER_KEYS environment # variable. -AUTOCREATE_SERVER_KEYS=NODSA +AUTOCREATE_SERVER_KEYS="RSA ECDSA ED25519" # source function library . /etc/rc.d/init.d/functions @@ -15,6 +15,7 @@ RSA1_KEY=/etc/ssh/ssh_host_key RSA_KEY=/etc/ssh/ssh_host_rsa_key DSA_KEY=/etc/ssh/ssh_host_dsa_key ECDSA_KEY=/etc/ssh/ssh_host_ecdsa_key +ED25519_KEY=/etc/ssh/ssh_host_ed25519_key # pull in sysconfig settings [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd @@ -36,7 +37,7 @@ do_rsa1_keygen() { chmod 640 $RSA1_KEY chmod 644 $RSA1_KEY.pub if [ -x /sbin/restorecon ]; then - /sbin/restorecon $RSA1_KEY.pub + /sbin/restorecon $RSA1_KEY{,.pub} fi success $"RSA1 key generation" echo @@ -57,7 +58,7 @@ do_rsa_keygen() { chmod 640 $RSA_KEY chmod 644 $RSA_KEY.pub if [ -x /sbin/restorecon ]; then - /sbin/restorecon $RSA_KEY.pub + /sbin/restorecon $RSA_KEY{,.pub} fi success $"RSA key generation" echo @@ -78,7 +79,7 @@ do_dsa_keygen() { chmod 640 $DSA_KEY chmod 644 $DSA_KEY.pub if [ -x /sbin/restorecon ]; then - /sbin/restorecon $DSA_KEY.pub + /sbin/restorecon $DSA_KEY{,.pub} fi success $"DSA key generation" echo @@ -99,7 +100,7 @@ do_ecdsa_keygen() { chmod 640 $ECDSA_KEY chmod 644 $ECDSA_KEY.pub if [ -x /sbin/restorecon ]; then - /sbin/restorecon $ECDSA_KEY.pub + /sbin/restorecon $ECDSA_KEY{,.pub} fi success $"ECDSA key generation" echo @@ -111,13 +112,43 @@ do_ecdsa_keygen() { fi } -# Create keys if necessary -if [ "x${AUTOCREATE_SERVER_KEYS}" != xNO ]; then - do_rsa_keygen - if [ "x${AUTOCREATE_SERVER_KEYS}" != xRSAONLY ]; then - do_ecdsa_keygen - if [ "x${AUTOCREATE_SERVER_KEYS}" != xNODSA ]; then - do_dsa_keygen +do_ed25519_keygen() { + if [ ! -s $ED25519_KEY ]; then + echo -n $"Generating SSH2 ED25519 host key: " + rm -f $ED25519_KEY + if test ! -f $ED25519_KEY && $KEYGEN -q -t ed25519 -f $ED25519_KEY -C '' -N '' >&/dev/null; then + chgrp ssh_keys $ED25519_KEY + chmod 640 $ED25519_KEY + chmod 644 $ED25519_KEY.pub + if [ -x /sbin/restorecon ]; then + /sbin/restorecon $ED25519_KEY{,.pub} + fi + success $"ED25519 key generation" + echo + else + failure $"ED25519 key generation" + echo + exit 1 fi fi +} + +if [ "x${AUTOCREATE_SERVER_KEYS}" == "xNO" ]; then + exit 0 fi + +# legacy options +case $AUTOCREATE_SERVER_KEYS in + NODSA) AUTOCREATE_SERVER_KEYS="RSA ECDSA ED25519";; + RSAONLY) AUTOCREATE_SERVER_KEYS="RSA";; + YES) AUTOCREATE_SERVER_KEYS="DSA RSA ECDSA ED25519";; +esac + +for KEY in $AUTOCREATE_SERVER_KEYS; do + case $KEY in + DSA) do_dsa_keygen;; + RSA) do_rsa_keygen;; + ECDSA) do_ecdsa_keygen;; + ED25519) do_ed25519_keygen;; + esac +done diff --git a/sshd.sysconfig b/sshd.sysconfig index ddd7744..e666ab9 100644 --- a/sshd.sysconfig +++ b/sshd.sysconfig @@ -1,14 +1,12 @@ # Configuration file for the sshd service. -# The server keys are automatically generated if they omitted -# to change the automatic creation uncomment the appropriate -# line. The default is NODSA which means rsa and ecdsa keys are -# generated. +# The server keys are automatically generated if they are missing. +# To change the automatic creation uncomment and change the appropriate +# line. Accepted key types are: DSA RSA ECDSA ED25519. +# The default is "RSA ECDSA ED25519" -# AUTOCREATE_SERVER_KEYS=NODSA -# AUTOCREATE_SERVER_KEYS=RSAONLY -# AUTOCREATE_SERVER_KEYS=NO -# AUTOCREATE_SERVER_KEYS=YES +# AUTOCREATE_SERVER_KEYS="" +# AUTOCREATE_SERVER_KEYS="RSA ECDSA ED25519" # Do not change this option unless you have hardware random # generator and you REALLY know what you are doing