Jan F 273d63
#!/bin/bash
Jan F 273d63
Jan F 273d63
# Create the host keys for the OpenSSH server.
00c7b7
KEYTYPE=$1
00c7b7
case $KEYTYPE in
00c7b7
	"dsa") ;& # disabled in FIPS
00c7b7
	"ed25519")
00c7b7
		FIPS=/proc/sys/crypto/fips_enabled
00c7b7
		if [[ -r "$FIPS" && $(cat $FIPS) == "1" ]]; then
00c7b7
			exit 0
00c7b7
		fi ;;
00c7b7
	"rsa") ;; # always ok
00c7b7
	"ecdsa") ;;
00c7b7
	*) # wrong argument
00c7b7
		exit 12 ;;
00c7b7
esac
00c7b7
KEY=/etc/ssh/ssh_host_${KEYTYPE}_key
Jan F 273d63
Jan F 273d63
KEYGEN=/usr/bin/ssh-keygen
00c7b7
if [[ ! -x $KEYGEN ]]; then
00c7b7
	exit 13
00c7b7
fi
1462de
00c7b7
# remove old keys
00c7b7
rm -f $KEY{,.pub}
4253bf
00c7b7
# create new keys
00c7b7
if ! $KEYGEN -q -t $KEYTYPE -f $KEY -C '' -N '' >&/dev/null; then
00c7b7
	exit 1
Jan F 273d63
fi
4253bf
00c7b7
# sanitize permissions
00c7b7
/usr/bin/chgrp ssh_keys $KEY
00c7b7
/usr/bin/chmod 640 $KEY
00c7b7
/usr/bin/chmod 644 $KEY.pub
00c7b7
if [[ -x /usr/sbin/restorecon ]]; then
00c7b7
	/usr/sbin/restorecon $KEY{,.pub}
00c7b7
fi
4253bf
00c7b7
exit 0