Skip to content

Fix Ed25519 public key derived from PKCS#8 private keys - #1873

Open
cmclendon wants to merge 1 commit into
sshnet:developfrom
cmclendon:fix-pkcs8-ed25519-public-key
Open

cmclendon wants to merge 1 commit into
sshnet:developfrom
cmclendon:fix-pkcs8-ed25519-public-key

Conversation

@cmclendon

Copy link
Copy Markdown

RFC 8410 section 7 encodes the Ed25519 seed as a CurvePrivateKey OCTET STRING inside the PKCS#8 privateKey OCTET STRING. The PKCS#8 parser passed the outer contents (04 20 followed by the first 30 seed bytes) to ED25519Key, so the key loaded without an error but had the wrong private and public key.

Changes:

  • PrivateKeyFile.PKCS8.cs: decode the inner OCTET STRING with AsnReader (as the EC branch already does), reject trailing data, and require a 32-byte seed.
  • PrivateKeyFileTest.cs: new Test_PrivateKey_ED25519_KeyMaterial checks the private and public key of the two existing Ed25519 PKCS#8 fixtures (plain and encrypted) against the expected values of Key.OPENSSH.ED25519.txt, which is the same key. The OpenSSH row is a control. Expected values come from openssl pkey and Key.OPENSSH.ED25519.pub.

Testing:

Run on Windows Server 2025 (10.0.26100), .NET SDK 11.0.100, .NET Framework 4.8.1, from develop b0d6c59 with this commit applied:

  • dotnet build -c Release of the solution: 0 warnings, 0 errors, for every target of Renci.SshNet (net462, netstandard2.0, net10.0, net11.0) and Renci.SshNet.Tests (net462, net10.0, net11.0).
  • New test with the parser change reverted: the two PKCS#8 rows fail and the OpenSSH row passes, on net462, net10.0 and net11.0.
  • New test with the fix: 3 of 3 pass on net462, net10.0 and net11.0.
  • Full Renci.SshNet.Tests suite with the fix: no failures. net462 has 2393 passed and 26 skipped; net10.0 and net11.0 each have 2398 passed and 26 skipped. Unpatched develop on net11.0 has 2395 passed and 26 skipped, so the 26 skipped tests are the repository's own, and the only new tests are the 3 rows above.
  • Renci.SshNet.IntegrationTests with the fix, on Linux x64 with Docker (.NET SDK 11.0.100, runtimes 10.0.15 and 11.0.0): 410 of 410 pass on net10.0 and on net11.0. They also pass 410 of 410 on net11.0 on macOS arm64.
  • Renci.SshNet.IntegrationTests with the fix on net48, run on the Windows Server 2025 machine above against a remote Linux Docker engine: 406 passed, 1 skipped (the same test is skipped when no Docker engine is reachable, so the skip is the suite's own), 0 failed.

AI disclosure, per CONTRIBUTING.md: under my direction, an AI coding assistant helped stress test the edge cases and the fix across platforms, and drafted the patch, the test and this description, which I reviewed.

RFC 8410 section 7 encodes the Ed25519 seed as a CurvePrivateKey
OCTET STRING inside the PKCS#8 privateKey OCTET STRING. The PKCS#8
parser passed the outer contents (the 04 20 header followed by the
first 30 seed bytes) to ED25519Key, so the key loaded without error
but had the wrong private and public key.

Decode the inner OCTET STRING and require a 32-byte seed. Add a test
that checks the key material of the existing Ed25519 PKCS#8 fixtures
against the matching OpenSSH fixture.

This branch has not been deployed

No deployments
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.

1 participant