Skip to content

fix: support parsing SM2 certificates in X.509 operation#2630

Open
mansiverma897993 wants to merge 1 commit into
gchq:masterfrom
mansiverma897993:fix/parse-sm2-certificate
Open

fix: support parsing SM2 certificates in X.509 operation#2630
mansiverma897993 wants to merge 1 commit into
gchq:masterfrom
mansiverma897993:fix/parse-sm2-certificate

Conversation

@mansiverma897993

@mansiverma897993 mansiverma897993 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description
Resolves the "unsupported curve name" error when parsing certificates signed with SM2 public keys.

The jsrsasign library used by CyberChef lacks native mappings for the SM2 curve OID (1.2.156.10197.1.301) and the SM2-with-SM3 signature algorithm OID (1.2.156.10197.1.501). This caused the parser to throw a hard exception during public key name resolution and fail to parse the certificate.

This PR implements the following:

  1. Dynamic SM2 Registration: Registers the SM2 curve parameters (sm2p256v1) in r.crypto.ECParameterDB and registers the OID mappings inside ParseX509Certificate.mjs runtime context.
  2. Dynamic Name Mapping: Monkeypatches r.crypto.ECDSA.getName to return "sm2p256v1" when resolving the SM2 OIDs.
  3. Graceful Fallback: Wraps cert.getPublicKey() in a try-catch block to prevent hard crashes on other unrecognized curves, gracefully falling back to displaying the Raw SPKI Hex and the associated error message.

Existing Issue
Fixes #2629

Screenshots
None (non-visual parser backend change).

AI disclosure
This code was created with the assistance of Antigravity, an AI assistant powered by Google DeepMind.

Test Coverage
Added automated test cases covering RSA, EC, and SM2 parsing in tests/operations/tests/ParseX509Certificate.mjs. All 2,062 tests pass successfully.

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.

Bug report: X.509 parser fails on SM2 certificates due to unsupported curve name

1 participant