|
Jan F |
273d63 |
#!/bin/bash
|
|
Jan F |
273d63 |
|
|
Jan F |
273d63 |
# Create the host keys for the OpenSSH server.
|
|
Jan F |
273d63 |
#
|
|
Jan F |
273d63 |
# The creation is controlled by the $AUTOCREATE_SERVER_KEYS environment
|
|
Jan F |
273d63 |
# variable.
|
|
Jan F |
273d63 |
|
|
Jan F |
273d63 |
# source function library
|
|
Jan F |
273d63 |
. /etc/rc.d/init.d/functions
|
|
Jan F |
273d63 |
|
|
Jan F |
273d63 |
# Some functions to make the below more readable
|
|
Jan F |
273d63 |
KEYGEN=/usr/bin/ssh-keygen
|
|
Jan F |
273d63 |
RSA1_KEY=/etc/ssh/ssh_host_key
|
|
Jan F |
273d63 |
RSA_KEY=/etc/ssh/ssh_host_rsa_key
|
|
Jan F |
273d63 |
DSA_KEY=/etc/ssh/ssh_host_dsa_key
|
|
Jan F |
273d63 |
|
|
Petr Lautrbach |
811ec1 |
# pull in sysconfig settings
|
|
Petr Lautrbach |
811ec1 |
[ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd
|
|
Petr Lautrbach |
811ec1 |
|
|
Petr Lautrbach |
2539b1 |
fips_enabled() {
|
|
Petr Lautrbach |
2539b1 |
if [ -r /proc/sys/crypto/fips_enabled ]; then
|
|
Petr Lautrbach |
2539b1 |
cat /proc/sys/crypto/fips_enabled
|
|
Petr Lautrbach |
2539b1 |
else
|
|
Petr Lautrbach |
2539b1 |
echo 0
|
|
Petr Lautrbach |
2539b1 |
fi
|
|
Petr Lautrbach |
2539b1 |
}
|
|
Petr Lautrbach |
2539b1 |
|
|
Jan F |
273d63 |
do_rsa1_keygen() {
|
|
Petr Lautrbach |
2539b1 |
if [ ! -s $RSA1_KEY -a `fips_enabled` -eq 0 ]; then
|
|
Jan F |
273d63 |
echo -n $"Generating SSH1 RSA host key: "
|
|
Jan F |
273d63 |
rm -f $RSA1_KEY
|
|
Jan F |
273d63 |
if test ! -f $RSA1_KEY && $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
|
|
Jan F |
273d63 |
chgrp ssh_keys $RSA1_KEY
|
|
Petr Lautrbach |
c4fd06 |
chmod 640 $RSA1_KEY
|
|
Jan F |
273d63 |
chmod 644 $RSA1_KEY.pub
|
|
Jan F |
273d63 |
if [ -x /sbin/restorecon ]; then
|
|
Jan F |
273d63 |
/sbin/restorecon $RSA1_KEY.pub
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
success $"RSA1 key generation"
|
|
Jan F |
273d63 |
echo
|
|
Jan F |
273d63 |
else
|
|
Jan F |
273d63 |
failure $"RSA1 key generation"
|
|
Jan F |
273d63 |
echo
|
|
Jan F |
273d63 |
exit 1
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
}
|
|
Jan F |
273d63 |
|
|
Jan F |
273d63 |
do_rsa_keygen() {
|
|
Jan F |
273d63 |
if [ ! -s $RSA_KEY ]; then
|
|
Jan F |
273d63 |
echo -n $"Generating SSH2 RSA host key: "
|
|
Jan F |
273d63 |
rm -f $RSA_KEY
|
|
Jan F |
273d63 |
if test ! -f $RSA_KEY && $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
|
|
Jan F |
273d63 |
chgrp ssh_keys $RSA_KEY
|
|
Petr Lautrbach |
c4fd06 |
chmod 640 $RSA_KEY
|
|
Jan F |
273d63 |
chmod 644 $RSA_KEY.pub
|
|
Jan F |
273d63 |
if [ -x /sbin/restorecon ]; then
|
|
Jan F |
273d63 |
/sbin/restorecon $RSA_KEY.pub
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
success $"RSA key generation"
|
|
Jan F |
273d63 |
echo
|
|
Jan F |
273d63 |
else
|
|
Jan F |
273d63 |
failure $"RSA key generation"
|
|
Jan F |
273d63 |
echo
|
|
Jan F |
273d63 |
exit 1
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
}
|
|
Jan F |
273d63 |
|
|
Jan F |
273d63 |
do_dsa_keygen() {
|
|
Jan F |
273d63 |
if [ ! -s $DSA_KEY ]; then
|
|
Jan F |
273d63 |
echo -n $"Generating SSH2 DSA host key: "
|
|
Jan F |
273d63 |
rm -f $DSA_KEY
|
|
Jan F |
273d63 |
if test ! -f $DSA_KEY && $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
|
|
Jan F |
273d63 |
chgrp ssh_keys $DSA_KEY
|
|
Petr Lautrbach |
c4fd06 |
chmod 640 $DSA_KEY
|
|
Jan F |
273d63 |
chmod 644 $DSA_KEY.pub
|
|
Jan F |
273d63 |
if [ -x /sbin/restorecon ]; then
|
|
Jan F |
273d63 |
/sbin/restorecon $DSA_KEY.pub
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
success $"DSA key generation"
|
|
Jan F |
273d63 |
echo
|
|
Jan F |
273d63 |
else
|
|
Jan F |
273d63 |
failure $"DSA key generation"
|
|
Jan F |
273d63 |
echo
|
|
Jan F |
273d63 |
exit 1
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
}
|
|
Jan F |
273d63 |
|
|
Jan F |
273d63 |
# Create keys if necessary
|
|
Jan F |
273d63 |
if [ "x${AUTOCREATE_SERVER_KEYS}" != xNO ]; then
|
|
Jan F |
273d63 |
do_rsa_keygen
|
|
Jan F |
273d63 |
if [ "x${AUTOCREATE_SERVER_KEYS}" != xRSAONLY ]; then
|
|
Jan F |
273d63 |
do_rsa1_keygen
|
|
Jan F |
273d63 |
do_dsa_keygen
|
|
Jan F |
273d63 |
fi
|
|
Jan F |
273d63 |
fi
|