openssh: Validate keys and regenerate if needed.
authorMarkus Gothe <markus.gothe@genexis.eu>
Wed, 15 Jan 2025 17:54:29 +0000 (18:54 +0100)
committerMichael Heimpold <mhei@heimpold.de>
Sat, 25 Jan 2025 10:09:48 +0000 (11:09 +0100)
Imitate dropbear init.d-script and make sure we
don't end up with corrupt keys.

This can happen if we use a caching filesystem,
like 'ubifs', and the DUT is powered off during
boot-up.

Signed-off-by: Markus Gothe <markus.gothe@genexis.eu>
net/openssh/files/sshd.init

index 8dce2a1e6c1cbcdf35ee71168914432cd159e4b0..998b9a58692e8efcfcb83b58fda8250ac091497b 100644 (file)
@@ -12,6 +12,13 @@ start_service() {
        do
                # check for keys
                key=/etc/ssh/ssh_host_${type}_key
+               [ -f $key ] && {
+                       [ -x /usr/bin/ssh-keygen ] && {
+                               if ! /usr/bin/ssh-keygen -y -f $key > /dev/null 2>&1; then
+                                       rm -rf $key
+                               fi
+                       }
+               }
                [ ! -f $key ] && {
                        # generate missing keys
                        [ -x /usr/bin/ssh-keygen ] && {