Fix UTF-8 string encoding and harden the certificate builder - #57
Merged
Conversation
ASCII encoding mangled every non-ASCII character to '?': the .ppk Private-MAC was computed over a mangled comment while the file carries UTF-8 (PuTTY reports "MAC failed"), certificates were minted with corrupted principals and key ids, and the SSHSIG namespace was corrupted on both sign and verify. UTF-8 is byte-identical for ASCII input, so existing output is unchanged.
Generate(Stream, info) disposed the stream it was handed, so callers could not read back what was just written.
Reject a null or empty nonce (the spec relies on CA-supplied randomness) and a validAfter later than validBefore.
The curve was mapped purely by key size, so brainpool or secp256k1 keys were silently treated as NIST curves and failed later inside SSH.NET with an opaque CryptographicException. Match the curve OID and fail fast with the curve name instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Review fixes for the string-encoding bug and a few smaller hardening items.
EncodeBinary(string)mangled every non-ASCII character to?. This made PuTTY reject exported .ppk files with a non-ASCII comment ("MAC failed": the Private-MAC was computed over the mangled comment while the file carries UTF-8), minted certificates with corrupted principals/key ids (m?llerinstead ofmüller), corrupted the SSHSIG namespace on both sign and verify (the library could not verify its own output), and corrupted the embedded OpenSSH key comment. UTF-8 is byte-identical for ASCII input, so existing output is unchanged.SshKey.Generate(Stream, info): the method disposed the stream it was handed, so callers could not read back what was just written.SshCertificateBuilderinput:WithNoncenow rejects a null/empty nonce (the spec relies on CA-supplied randomness),WithValidityrejectsvalidAfter > validBefore.SshKey.FromKey(ECDsa): curves were mapped purely by key size, so brainpool/secp256k1 keys failed later deep inside SSH.NET with an opaqueCryptographicException. The curve OID is now checked and unsupported curves fail fast with aNotSupportedExceptionnaming the curve.SshKey.FromKey/FromPem/FromEd25519), including thatFromPemthrowsPlatformNotSupportedExceptionon .NET 4.8 / netstandard 2.0.Each fix comes with a test that fails without it.
Release
Merging this publishes 2024.2.0.4. This should be merged before the SshNet.Agent release PR, whose README references the certificate API.