Skip to content

Return an error for non-ECDSA cert in SanitizeX509Cert - #5669

Open
amalsaidov wants to merge 1 commit into
hyperledger:mainfrom
amalsaidov:fix-sanitize-nonecdsa-panic
Open

amalsaidov wants to merge 1 commit into
hyperledger:mainfrom
amalsaidov:fix-sanitize-nonecdsa-panic

Conversation

@amalsaidov

Copy link
Copy Markdown

Type of change

  • Bug fix

Description

SanitizeX509Cert normalizes the ECDSA signature of an identity certificate to a low-S value. It unmarshals the signature as ECDSA and then reads the curve order from the certificate's own public key with an unchecked type assertion:

curveOrderUsedByCryptoGen := cert.PublicKey.(*ecdsa.PublicKey).Curve.Params().N

A certificate can carry an ECDSA signature while its subject public key is of a different type, for example an RSA key signed by an ECDSA CA. In that case UnmarshalECDSASignature succeeds on the CA signature, execution reaches the assertion, and it panics:

interface conversion: interface {} is *rsa.PublicKey, not *ecdsa.PublicKey

SanitizeX509Cert and SanitizeIdentity run on consenter and node identities taken from channel configuration in the BFT and cluster code paths (orderer/consensus/smartbft, orderer/common/cluster), so an identity like this would crash the orderer instead of being rejected with an error.

The fix guards the type assertion and returns an error, which every caller already propagates.

Additional details

Tested with go test ./common/crypto/....

Added common/crypto/sanitize_test.go covering:

  • a valid ECDSA certificate sanitizes without error,
  • a non-PEM input returns an error,
  • a certificate with a non-ECDSA subject public key (RSA key signed by an ECDSA CA) returns an error instead of panicking. This test panics (fails) without the fix and passes with it.

AI-assisted; directed, reviewed and tested by the author (amalsaidov).

Related issues

None.

SanitizeX509Cert unmarshals the certificate signature as ECDSA and then
reads the curve order from the certificate's own public key using an
unchecked type assertion to *ecdsa.PublicKey.

A certificate can carry an ECDSA signature while its subject public key is
of a different type, for example an RSA key signed by an ECDSA CA. The
signature unmarshals successfully, execution reaches the assertion, and it
panics with "interface conversion: ... not *ecdsa.PublicKey".

SanitizeX509Cert and SanitizeIdentity run on consenter and node identities
taken from channel configuration in the BFT and cluster paths, so a
certificate like this would crash the orderer rather than be rejected.
Guard the assertion and return an error, which every caller already
propagates.

Add tests covering a valid ECDSA certificate, a non-PEM input, and the
non-ECDSA public key case that previously panicked.

Signed-off-by: amalsaidov <amalsaidov@users.noreply.github.com>
@amalsaidov
amalsaidov requested a review from a team as a code owner November 13, 2026 02:20
@mergify

mergify Bot commented Nov 13, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

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