Conversation
…ureValue in XMLDSig Agent-Logs-Url: https://github.com/rikulo/xml-crypto/sessions/822e4c7c-2b12-4ac6-a99f-3ff2255791e0 Co-authored-by: scribetw <6398934+scribetw@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
scribetw
March 28, 2026 03:32
View session
There was a problem hiding this comment.
Pull request overview
This PR prevents intermittent XMLDSig verification failures by ensuring RSA SignatureValue is always encoded at the full modulus width (left-padding with 0x00 when the signing library emits a shorter BigInt-derived byte sequence).
Changes:
- Added
normalizeRsaSignatureBase64(base64Sig, modulus)to left-pad decoded RSA signature bytes toceil(modulus.bitLength / 8)and throw if oversized. - Applied normalization to RSA-SHA1 / RSA-SHA256 / RSA-SHA512 signing paths using the private key modulus (
rsa.n). - Added unit tests covering passthrough, 1–2 byte short padding, oversized throw, and a 1024-bit modulus case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/src/utils.dart |
Adds signature normalization helper (pad/validate to modulus byte width). |
lib/src/signed_xml.dart |
Normalizes RSA signature output for SHA1/SHA256/SHA512 signing. |
test/utils_test.dart |
Adds focused unit tests for normalization behavior and edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ninjacan serialize RSA signatures without left-padding the resultBigIntto modulus width, silently dropping leading0x00bytes. For a 2048-bit key this produces 255 bytes (340 Base64 chars) instead of the required 256 bytes (344 Base64 chars), causing intermittent verification failures downstream with no clear error.Changes
lib/src/utils.dart— NewnormalizeRsaSignatureBase64(String base64Sig, BigInt modulus)helper:0x00toceil(modulus.bitLength / 8)when shortStateErrorif longer than the modulus width (indicates a serious upstream bug)lib/src/signed_xml.dart— Applied normalization inRSASHA1,RSASHA256, andRSASHA512getSignatureusing the private key's.n(modulus):test/utils_test.dart— Unit tests fornormalizeRsaSignatureBase64: correct-length passthrough, one- and two-byte-short padding (the ninja bug scenario), oversized throwsStateError, and 1024-bit key variant.