Skip to content

Commit cd0a5f3

Browse files
authored
Merge pull request #1290 from kernelkit/hostkey-warning
Fix SSH host key generation warnings
2 parents 2e7b9a6 + d23f9ea commit cd0a5f3

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

board/common/rootfs/usr/libexec/infix/mkkeys

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ PUB=$2
88

99
mkdir -p "$(dirname "$KEY")" "$(dirname "$PUB")"
1010

11+
# openssl genpkey -quiet -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -outform PEM
1112
openssl genpkey -quiet -algorithm RSA -pkeyopt rsa_keygen_bits:$BIT -outform PEM > "$KEY"
12-
openssl rsa -RSAPublicKey_out < "$KEY" > "$PUB"
13+
openssl rsa -RSAPublicKey_out < "$KEY" 2>/dev/null > "$PUB"
1314

1415
exit 0

board/common/rootfs/usr/libexec/infix/mksshkey

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
#!/bin/bash
2-
# Store and convert RSA PUBLIC/PRIVATE KEYs to be able to use them in
3-
# OpenSSHd.
1+
#!/bin/sh
2+
# Generate OpenSSH host key pair from same keys as NETCONF
43
set -e
4+
umask 0077
55

66
NAME="$1"
77
DIR="$2"
88
PUBLIC="$3"
99
PRIVATE="$4"
1010
TMP="$(mktemp)"
1111

12-
echo -e '-----BEGIN RSA PRIVATE KEY-----' > "$DIR/$NAME"
13-
echo "$PRIVATE" >> "$DIR/$NAME"
14-
echo -e '-----END RSA PRIVATE KEY-----' >> "$DIR/$NAME"
12+
{
13+
echo '-----BEGIN PRIVATE KEY-----'
14+
printf '%s\n' "$PRIVATE" | fold -w 64
15+
echo '-----END PRIVATE KEY-----'
16+
} > "$DIR/$NAME"
1517

16-
echo -e "-----BEGIN RSA PUBLIC KEY-----" > "$TMP"
17-
echo -e "$PUBLIC" >> "$TMP"
18-
echo -e "-----END RSA PUBLIC KEY-----" >> "$TMP"
18+
{
19+
echo "-----BEGIN RSA PUBLIC KEY-----"
20+
printf '%s\n' "$PUBLIC" | fold -w 64
21+
echo "-----END RSA PUBLIC KEY-----"
22+
} > "$TMP"
1923

20-
ssh-keygen -i -m PKCS8 -f "$TMP" > "$DIR/$NAME.pub"
24+
ssh-keygen -i -f "$TMP" -m PKCS8 > "$DIR/$NAME.pub"
2125
rm "$TMP"
26+
2227
chmod 0600 "$DIR/$NAME.pub"
2328
chmod 0600 "$DIR/$NAME"
2429
chown sshd:sshd "$DIR/$NAME.pub"

doc/ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Change Log
33

44
All notable changes to the project are documented in this file.
55

6-
[v25.11.0][] - 2025-11-28
6+
[v25.11.0][UNRELEASED]
77
-------------------------
88

99
> [!NOTE]
@@ -82,6 +82,7 @@ All notable changes to the project are documented in this file.
8282
existing invalid configurations are automatically corrected during upgrade
8383
- Fix #1255: serious regression in boot time, introduced in v25.10, delays the
8484
boot step "Mounting filesystems ...", from 30 seconds up to five minutes!
85+
- Fix #1289: SSH host key generation warning at boot after factory reset
8586
- Fix broken intra-document links in container and tunnel documentation
8687
- Fix `show dhcp-server` command crashing with invalid timestamp format.
8788
DHCP lease expiry timestamps had double timezone suffix causing libyang

src/confd/src/keystore.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ static int gen_hostkey(const char *name, struct lyd_node *change)
5959
private_key = lydx_get_cattr(change, "cleartext-private-key");
6060
public_key = lydx_get_cattr(change, "public-key");
6161

62+
/* Validate keys before use */
63+
if (!private_key || !public_key || !*private_key || !*public_key)
64+
return SR_ERR_OK;
65+
6266
if (mkdir(SSH_HOSTKEYS_NEXT, 0600) && (errno != EEXIST)) {
6367
ERRNO("Failed creating %s", SSH_HOSTKEYS_NEXT);
6468
rc = SR_ERR_INTERNAL;
6569
}
6670

67-
if (systemf("/usr/libexec/infix/mksshkey %s %s %s %s", name, SSH_HOSTKEYS_NEXT, public_key, private_key))
71+
if (systemf("/usr/libexec/infix/mksshkey %s %s %s %s", name,
72+
SSH_HOSTKEYS_NEXT, public_key, private_key))
6873
rc = SR_ERR_INTERNAL;
6974

7075
return rc;
@@ -156,7 +161,7 @@ static int keystore_update(sr_session_ctx_t *session, struct lyd_node *config, s
156161
}
157162

158163
int keystore_change(sr_session_ctx_t *session, struct lyd_node *config, struct lyd_node *diff,
159-
sr_event_t event, struct confd *confd)
164+
sr_event_t event, struct confd *confd)
160165
{
161166
struct lyd_node *changes, *change;
162167
int rc = SR_ERR_OK;

0 commit comments

Comments
 (0)