Skip to content

fix: Correct C14N 1.1 handling and improve ECDSA format compatibility#1

Open
atulpatildbz wants to merge 2 commits intomainfrom
canonicalize_issue_c14n11
Open

fix: Correct C14N 1.1 handling and improve ECDSA format compatibility#1
atulpatildbz wants to merge 2 commits intomainfrom
canonicalize_issue_c14n11

Conversation

@atulpatildbz
Copy link
Owner

C14N 1.1 canonicalizer was missing namespace inheritance from parent
elements, causing XML signature validation failures when signed elements
had namespace prefixes defined in ancestor elements.

The issue was already correctly handled in C14N 1.0 REC canonicalizer
which uses getParentNamespaceAndXmlAttributes() and enhanceNamespaceAttributes()
to inherit namespaces from parent elements before canonicalization.

This commit applies the same approach to c14N11Canonicalizer:
- Collect parent namespace declarations using getParentNamespaceAndXmlAttributes()
- Copy input element to avoid mutations
- Enhance element with inherited namespaces using enhanceNamespaceAttributes()
- Proceed with standard canonicalization

Added TestC14N11NamespaceInheritance to verify the fix works correctly.
The test demonstrates that canonicalized output now includes proper
xmlns declarations for inherited namespaces (e.g., xmlns:ds="...").

Fixes XML signature validation for documents using C14N 1.1 canonicalization
with namespace prefixes defined in parent elements
This commit addresses two critical issues:

1. **C14N 1.1 Integration Fix**: Modified getCanonicalSignedInfo() to respect
   the CanonicalizationMethod specified in XML signatures. Previously, the
   function ignored the XML-specified algorithm and always used basic
   canonicalization, preventing the C14N 1.1 namespace inheritance fix (b650795) from
   being applied during signature verification.

2. **ECDSA Signature Format Conversion**: Added automatic conversion from
   XML DSig IEEE P1363 format to ASN.1 DER format for ECDSA signatures.
   XML Digital Signature standard uses IEEE P1363 (r||s concatenated),
   while Go's x509.CheckSignature expects ASN.1 DER (structured sequence).

Changes:
- Modified getCanonicalSignedInfo() to extract and respect CanonicalizationMethod
- Added switch statement to apply correct canonicalizer based on algorithm
- Implemented convertXMLDSigECDSASignature() for IEEE P1363 → ASN.1 DER conversion
- Added isECDSAAlgorithm() helper for signature type detection
- Added graceful fallback when format conversion fails

Testing:
- All 27 existing tests pass (zero regressions)
- Handles both IEEE P1363 and ASN.1 DER ECDSA formats gracefully
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