Skip to content

Conversation

@troglobit
Copy link
Contributor

@troglobit troglobit commented Dec 1, 2025

Description

Fix several issues in SSH host key generation and import that caused warnings in system logs:

  1. mkkeys: Switch from openssl genpkey (PKCS#8) to genrsa (PKCS#1) to match the expected format in mksshkey

  2. mksshkey: Fix PEM file reconstruction by properly formatting base64 content with 64-character line wrapping using printf+fold. The previous approach concatenated the END marker to the last base64 line, causing "unrecognised raw private key format" errors

  3. mksshkey: Correct ssh-keygen format flag from PKCS8 to PEM for public key conversion

  4. confd:keystore.c: Skip gen_hostkey() when keys are empty to prevent attempting to import invalid PEM files during SR_EV_UPDATE events before keys are populated in the config tree

  5. mksshkey: Convert from bash to POSIX sh (no bashisms were used)

This eliminates the "do_convert_from_pem: unrecognised raw private key format" error messages during system boot and SSH key configuration.

Fixes #1289

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

@troglobit troglobit requested review from mattiaswal and wkz December 1, 2025 09:48
@troglobit troglobit added this to the Infix v25.11 milestone Dec 1, 2025
Copy link
Contributor

@wkz wkz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want mksshkey to generate PKCS#8 framing around the key, so that we can import ECDSA and other key types as well?

I.e., if we kept mk{keys,sshkey} as they were before this change, and ran s/ RSA//g on mksshkey's header strings, would that also work?

@troglobit
Copy link
Contributor Author

Don't we want mksshkey to generate PKCS#8 framing around the key, so that we can import ECDSA and other key types as well?

I.e., if we kept mk{keys,sshkey} as they were before this change, and ran s/ RSA//g on mksshkey's header strings, would that also work?

Good point, I'll have a look!

@troglobit
Copy link
Contributor Author

Yup, that works @wkz, thanks for pointing this out!

@troglobit troglobit requested a review from wkz December 1, 2025 12:43
Copy link
Contributor

@wkz wkz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super! ✨

Validate keys in gen_hostkey() before passing empty keys to shell scripts,
preventing:

Nov 04 2024 10:54:25 confd[2697]: SSH key (genkey) does not exist, generating...
Nov 04 2024 10:54:25 confd[2697]: writing RSA key
Nov 04 2024 10:54:26 confd[2697]: do_convert_from_pkcs8: /tmp/tmp.FH1Hr1 is not a recognised public key format

Also, fix base64 content formatting with proper 64-character line wrapping
using printf+fold instead of echo.

Use PKCS#1 RSA format for public keys as required by netopeer2-server, while
keeping PKCS#8 format for private keys.  Use proper ssh-keygen format flag
(PKCS8) for correct conversion.

Fixes #1289

Signed-off-by: Joachim Wiberg <[email protected]>
@troglobit troglobit merged commit cd0a5f3 into main Dec 2, 2025
6 checks passed
@troglobit troglobit deleted the hostkey-warning branch December 2, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worrying SSH key warning in logs after factory-reset

4 participants