Replace SHA-1/RSA-1024 test data with SHA-256/RSA-2048 equivalents - #131783
Replace SHA-1/RSA-1024 test data with SHA-256/RSA-2048 equivalents#131783joshuajyue wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR updates System.Security.Cryptography.Pkcs test data and tests to avoid SHA-1 / RSA-1024 artifacts by introducing SHA-256 / RSA-2048 CMS blobs and switching multiple tests from SHA-1-guarded [ConditionalFact] to unconditional [Fact]/[Theory], plus adding a dedicated ECDSA-SHA1 capability probe.
Changes:
- Added SHA-256 / RSA-2048 “structural twin” CMS test documents and updated tests to decode/validate these new blobs.
- Removed RSA-SHA1 conditional gating from many tests now backed by SHA-2 documents; split out an ECDSA-SHA1-only test and gated it with a new
SupportsEcdsaSha1Signaturesprobe. - Updated helper logic to support decrypting both legacy and new encrypted-content shapes via an optional certificate loader.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/SignerInfoTests.cs | Switches multiple RSA-SHA1-gated tests to SHA-256 docs; adds ECDSA-SHA1-specific conditional test. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/SignedDocuments.cs | Adds new SHA-256 / RSA-2048 CMS byte-array fixtures (including crypt32-produced variants). |
| src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/SignedCmsWholeDocumentTests.cs | Updates whole-document assertions (digest OIDs, signatures, SKI values, message-digest hashing) to match SHA-256 fixtures. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/SignedCmsTests.netcoreapp.cs | Re-enables certificate mutation tests by switching to SHA-256 countersigned fixture. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/SignedCmsTests.cs | Switches encrypted-content fixtures to SHA-256 NetFx variants and adds optional decrypt cert parameter. |
| src/libraries/System.Security.Cryptography.Pkcs/tests/SignatureSupport.cs | Adds SupportsEcdsaSha1Signatures capability probe. |
| } | ||
|
|
||
| [ConditionalFact(typeof(SignatureSupport), nameof(SignatureSupport.SupportsRsaSha1Signatures))] | ||
| [Fact] |
144f006 to
640e5dd
Compare
Platforms that enforce a strict crypto policy (e.g. CentOS Stream 10, Fedora 44) reject SHA-1 signatures and RSA keys smaller than 2048 bits, causing 29 tests in System.Security.Cryptography.Pkcs to be skipped behind [ConditionalFact(SupportsRsaSha1Signatures)]. This change replaces the pre-built test documents and the certificates used to produce them with SHA-256 / RSA-2048 equivalents, reducing the number of conditionally-skipped tests from 29 to 3. The three remaining skips are intentional: - AddCounterSigner_ECDSA_Sha1: deliberately tests SHA-1 ECDSA behavior - CheckNoSignatureDocument: uses a NoSignature primary signer that .NET Framework cannot reproduce (NullReferenceException in crypt32), so no SHA-2 twin can be generated New test documents were generated using .NET Framework (net481), which is a thin wrapper over crypt32, so the output carries the Windows-native encoding (counter-signers include a ContentType signed attribute, as crypt32 emits). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 53916e59-38f7-4bcf-beba-f9662df3975b
640e5dd to
3dbc3f8
Compare
|
Something to call out for this change, by default I don't think any of our CI pipelines actually run with the RSA+SHA1 restriction. This is a Red Hat / Fedora thing. In theory Azure Linux 4 also has the RSA+SHA1 restriction but that only runs with the |
|
(I did run this on Fedora and its green) |
Summary
Fixes #70209.
Platforms that enforce a strict crypto policy (CentOS Stream 10, Fedora 44, and similar RHEL-family distros) reject both SHA-1 signatures and RSA keys smaller than 2048 bits. This caused 29 tests in
System.Security.Cryptography.Pkcsto be skipped behind[ConditionalFact(SupportsRsaSha1Signatures)].This PR replaces the pre-built test documents and the certificates used to produce them with SHA-256 / RSA-2048 equivalents, reducing the number of conditionally-skipped tests from 29 → 3.
What changed
New test documents (
SignedDocuments.cs)Seven new pre-built CMS binary blobs were added (stored as hex byte arrays), all signed with
RSA2048Sha256KeyTransfer1(RSA-2048, SHA-256):RsaPkcs1Sha256OneSignerIssuerAndSerialNumberCounterSignedRsaPkcs1Sha256OneSignerOneRsaSignerTwoRsaCounterSigners_Sha256RsaPkcs1Sha256CounterSignedWithNoSignatureRsaSha256Transfer1_NoEmbeddedCertSignedCmsOverEnvelopedCms_IssuerSerial_Sha256_NetFxSignedCmsOverEnvelopedCms_SKID_Sha256_NetFxAll documents were generated using .NET Framework (
net481), which is a thin wrapper overcrypt32.dll. This preserves the Windows-native CMS encoding — in particular, counter-signers produced bycrypt32include aContentTypesigned attribute that managed .NET does not emit, providing better interop coverage.Tests re-enabled (removed
[ConditionalFact])SignerInfoTests.csAddCounterSigner_DuplicateCert_RSAAddCounterSigner_RSAAddCounterSigner_ECDSA(SHA-256/384/512 variants — these never required a SHA-1 guard)RemoveCounterSignature_MatchesIssuerAndSerialNumberRemoveCounterSignature_MatchesSubjectKeyIdentifierRemoveCounterSignature_MatchesNoSignatureRemoveCounterSignature_UsesLiveStateSignedCmsWholeDocumentTests.csReadRsaPkcs1SimpleDocumentReadRsaPkcs1CounterSignedReadRsaPkcs1DoubleCounterSignedNonEmbeddedCertificateSignedCmsTests.netcoreapp.csAddCertificateAddCertificateWithPrivateKeyRemoveAllCertsAddBackSignerCertSignedCmsTests.csCheckSignedEncrypted_IssuerSerial_FromNetFxCheckSignedEncrypted_SKID_FromNetFxOther changes
AddCounterSigner_ECDSA_Sha1was split out fromAddCounterSigner_ECDSAand re-guarded with the newSupportsEcdsaSha1Signaturesproperty (previously it was incorrectly gated onSupportsRsaSha1Signatures). The SHA-256/384/512 ECDSA cases are now unconditional.SignatureSupport.cs: addedSupportsEcdsaSha1Signatures— probes ECDSA SHA-1 support independently from RSA.CheckSignedEncryptedhelper: made thedecryptionCertparameter optional so the two new NetFx documents (which useRSA2048Sha256KeyTransfer1for encryption) and the existing CoreFx documents (which useRSAKeyTransferCapi1) can share the same helper.Remaining conditional tests (intentional)
AddCounterSigner_ECDSA_Sha1CheckNoSignatureDocumentNoSignatureprimary signer;.NET FrameworkthrowsNullReferenceExceptionwhen creating this shape, so no crypt32-produced SHA-2 twin can be generatedAddCounterSigner_DSATesting
Verified locally on Windows:
net11.0-windows: 959 passed, 0 failednet481: 386 passed, 0 failedNote
This PR description was generated by GitHub Copilot.