mirror of https://github.com/wolfSSL/wolfssh.git
wolfsshd could not load a host key stored as a PKCS#8 "-----BEGIN PRIVATE KEY-----" PEM file (the form emitted for ML-DSA keys, and by `openssl genpkey`). SetupCTX() pre-converted the file with wc_PemToDer(..., PRIVATEKEY_TYPE, ...), which only recognizes the classic "RSA/EC PRIVATE KEY" headers. On a PKCS#8 body that call returns success but produces a malformed DER (leading 0x04 rather than a 0x30 SEQUENCE); the bytes were then passed to wolfSSH_CTX_UsePrivateKey_buffer() as WOLFSSH_FORMAT_ASN1, which rejected them with WS_BAD_FILETYPE_E. Detect PEM vs DER by content and decode PEM with wc_KeyPemToDer(), which handles PKCS#1, SEC1 and PKCS#8 private-key bodies. DER keys are unchanged. Tested (master + wolfSSL master): an ML-DSA-65 PEM host key now loads (wolfSSH_CTX_UsePrivateKey_buffer ret = 0, was WS_BAD_FILETYPE_E); ML-DSA-65 DER and ECDSA SEC1 PEM host keys continue to load (no regression). Also harden the host-key load path per review: reject an empty (0-byte) key file explicitly instead of taking the PEM branch into WMALLOC(0), and zeroize the raw file buffer (not just the decoded DER) before freeing so private-key material does not linger in the heap. |
||
|---|---|---|
| .. | ||
| wolfssh | ||
| wolfsshd | ||
| include.am | ||