fix: ECDSA signature verification for XML DSig#100
Conversation
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)
Summary of ChangesHello, 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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
Summary
Fix ECDSA signature verification by converting XML DSig raw
r||ssignatures to ASN.1 DER encoding before passing to Go'sx509.Certificate.CheckSignature.Problem
XML DSig (RFC 4050) encodes ECDSA signatures as raw
r||sbyte concatenation, while Go'sx509.Certificate.CheckSignatureexpects 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
isECDSAAlgorithm()helper to detect ECDSA signature algorithms (SHA1/SHA256/SHA384/SHA512)convertECDSARawToASN1()to convert rawr||sconcatenation to DERSEQUENCEvalidateSignature()before callingCheckSignaturewhen an ECDSA algorithm is detectedecdsa.Sign, convert to raw, convert back, verify)Testing
All existing tests continue to pass. New tests in
ecdsa_test.gocover the conversion logic.