Skip to content

[release/10.0] Fix EncodeUnsignedInteger for test DSA signer#128005

Open
vcsjones wants to merge 1 commit intodotnet:release/10.0from
vcsjones:backport-127979-to-release-10.0
Open

[release/10.0] Fix EncodeUnsignedInteger for test DSA signer#128005
vcsjones wants to merge 1 commit intodotnet:release/10.0from
vcsjones:backport-127979-to-release-10.0

Conversation

@vcsjones
Copy link
Copy Markdown
Member

Backport of #127979 to release/10.0

Customer Impact

No customer impact. This change fixes a test bug that would cause intermittent failures of CrlBuilderTests.DsaNotDirectlySupported on Android.

  • Customer reported
  • Found internally

Regression

  • Yes
  • No
  • Test only fix

Testing

Verified test does not fail after many runs on Android.

Risk

None, test only change.

`EncodeUnsignedInteger` did not encode ASN.1 integers correctly when
there was a leading zero and the second octet had its high bit set,
requiring a leading zero to preserve positive sign. For example,
encoding the unsigned integer `[0x00, 0xFF]` would get encoded to the
ASN.1 `0201FF`, or -1. It should be encoded to `020200FF`. Conscrypt is
picky about the ASN.1 encoding.

This test had a ~0.46% failure chance (because it would fail if either r
or s were encoded incorrectly).

The first commit to this PR fixes `EncodeUnsignedInteger`.

However all of the hand-rolled ASN.1 encoding is unnecessary. We can

1. Use `AsnWriter` to do ASN.1 encoding. Let `BigInteger` and
`AsnWriter` do the correct encoding for us.
2. Use `DSASignatureFormat.Rfc3279DerSequence` so we don't have to
convert from IEEE.

Finally, this removed the ActiveIssue attribute.
@vcsjones vcsjones added this to the 10.0.x milestone May 10, 2026
@vcsjones vcsjones self-assigned this May 10, 2026
Copilot AI review requested due to automatic review settings May 10, 2026 02:31
@vcsjones vcsjones added area-System.Security test-bug Problem in test source code (most likely) labels May 10, 2026
@vcsjones vcsjones requested a review from bartonjs May 10, 2026 02:32
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backports a test-only fix to stabilize DSA-related certificate/CRL tests on Android by avoiding hand-rolled ASN.1 integer/signature encoding that could intermittently produce invalid DER.

Changes:

  • Switch DSA signatures to DSASignatureFormat.Rfc3279DerSequence to avoid manual IEEE-to-DER conversion.
  • Replace custom ASN.1 INTEGER/length encoding with AsnWriter + BigInteger to produce correct DER for DSA parameters and public key value.
Show a summary per file
File Description
src/libraries/System.Security.Cryptography/tests/X509Certificates/CertificateCreation/DSAX509SignatureGenerator.cs Removes manual ASN.1 encoding and uses AsnWriter/BigInteger plus RFC3279 DER signatures to prevent invalid DER that can fail on Android/Conscrypt.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Security test-bug Problem in test source code (most likely)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants