Skip to content

fix: ECDSA signature verification for XML DSig#100

Merged
adamdecaf merged 3 commits intomoov-io:masterfrom
sirosfoundation:pr/ecdsa-fix
Mar 26, 2026
Merged

fix: ECDSA signature verification for XML DSig#100
adamdecaf merged 3 commits intomoov-io:masterfrom
sirosfoundation:pr/ecdsa-fix

Conversation

@leifj
Copy link
Copy Markdown

@leifj leifj commented Mar 24, 2026

Summary

Fix ECDSA signature verification by converting XML DSig raw r||s signatures to ASN.1 DER encoding before passing to Go's x509.Certificate.CheckSignature.

Problem

XML DSig (RFC 4050) encodes ECDSA signatures as raw r||s byte concatenation, while Go's x509.Certificate.CheckSignature expects ASN.1 DER encoding (SEQUENCE { INTEGER r, INTEGER s }). This mismatch caused valid ECDSA-signed documents (e.g., Greece EU TSL) to fail signature verification with a cryptographic error.

Changes

  • Add isECDSAAlgorithm() helper to detect ECDSA signature algorithms (SHA1/SHA256/SHA384/SHA512)
  • Add convertECDSARawToASN1() to convert raw r||s concatenation to DER SEQUENCE
  • Apply the conversion in validateSignature() before calling CheckSignature when an ECDSA algorithm is detected
  • Add comprehensive tests for both helpers:
    • P-256 and P-384 roundtrip tests (sign with ecdsa.Sign, convert to raw, convert back, verify)
    • Edge cases: empty input, odd-length input, zero values

Testing

All existing tests continue to pass. New tests in ecdsa_test.go cover the conversion logic.

XML DSig (RFC 4050) encodes ECDSA signatures as raw r||s byte
concatenation, while Go's x509.Certificate.CheckSignature expects
ASN.1 DER encoding. This mismatch caused valid ECDSA-signed documents
(e.g. Greece EU TSL) to fail signature verification.

- Add isECDSAAlgorithm() to detect ECDSA signature algorithms
- Add convertECDSARawToASN1() to convert raw r||s to DER SEQUENCE
- Apply conversion in validateSignature() before CheckSignature call
- Add tests for both helpers (P-256/P-384 roundtrip, edge cases)
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where ECDSA-signed XML documents failed verification due to a mismatch in signature encoding formats. XML DSig uses a raw r||s concatenation for ECDSA signatures, while Go's x509.Certificate.CheckSignature expects an ASN.1 DER encoding. The changes introduce a conversion mechanism to correctly transform the raw signatures to DER format, ensuring proper validation of such documents.

Highlights

  • ECDSA Algorithm Detection: Introduced isECDSAAlgorithm() to identify ECDSA signature algorithms (SHA1, SHA256, SHA384, SHA512).
  • ECDSA Signature Conversion: Implemented convertECDSARawToASN1() to transform XML DSig's raw r||s ECDSA signatures into ASN.1 DER encoding.
  • Signature Validation Logic: Modified validateSignature() to apply the ECDSA signature conversion before calling Go's x509.Certificate.CheckSignature when an ECDSA algorithm is detected.
  • Comprehensive Testing: Added new tests in ecdsa_test.go covering P-256 and P-384 roundtrip conversions and edge cases for the new helper functions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses a bug in ECDSA signature verification by converting the signature format from raw r||s to ASN.1 DER. The added logic and tests are a good addition. I've provided a few suggestions to improve the new test code's correctness regarding cryptographic best practices and to enhance the readability of a new helper function.

Comment thread ecdsa_test.go Outdated
Comment thread ecdsa_test.go Outdated
Comment thread ecdsa_test.go Outdated
Comment thread ecdsa_test.go Outdated
Comment thread validator.go
leifj pushed a commit to sirosfoundation/signedxml that referenced this pull request Mar 24, 2026
Incorporates all review feedback from upstream PRs:
- PR moov-io#98 (c14n-fixes): WriteToString error handling, redundant assignment removal
- PR moov-io#99 (rsa-pss): getDigestAlgorithm helper, rsaPSSHashAlgorithms shared map
- PR moov-io#100 (ecdsa-fix): hash messages before ECDSA sign/verify in tests, nolint:exhaustive
- PR moov-io#101 (ed25519-xmlenc-cryptosigner): error handling in xmlenc parse functions,
  gosec nolint for safe integer conversions, NewSigner error check in tests,
  .gitleaks.toml for W3C test vectors

Also updates golang.org/x/crypto to v0.49.0.
@adamdecaf
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for ECDSA signatures in the signedxml package. It adds new functions isECDSAAlgorithm and convertECDSARawToASN1 to handle the conversion of raw r||s ECDSA signatures (as used in XML DSig) to the ASN.1 DER format required by Go's x509.CheckSignature function. Corresponding unit tests for these new functions, covering different elliptic curves and edge cases, have also been added in ecdsa_test.go. No feedback to provide.

@adamdecaf adamdecaf merged commit b8a26cf into moov-io:master Mar 26, 2026
3 checks passed
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.

2 participants