Conversation
…ssembly When PublicSign=true with a full .snk key pair, the PublicKey property of PublicKeyOptionsSigner returned the raw .snk bytes verbatim, including private key material (PRIVATEKEYBLOB). This caused: 1. Private key material embedded in the compiled assembly's metadata 2. Malformed public key blob (bType=0x07 instead of 0x06) that fails IsValidPublicKey validation during ResolveAssemblyReference The fix detects when PublicKeyOptionsSigner holds a key pair blob and converts it to a public-key-only CLR blob via getPublicKeyForKeyPair, matching what the KeyPair case already does. Also strengthened the existing PublicSign test to verify no RSA2 (private key) magic appears in the output, and added a regression test that validates AssemblyName can load the public key without SecurityException. Fixes dotnet#19441 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
❗ Release notes requiredCaution No release notes found for the changed paths (see table below). Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format. The following format is recommended for this repository:
If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request. You can open this PR in browser to add release notes: open in github.dev
|
Summary
When
PublicSign=truewith a full.snkkey pair (the default on Linux/macOS for non-official builds), thePublicKeyproperty ofPublicKeyOptionsSignerreturned the raw.snkbytes verbatim — including all private key material. These bytes were then embedded directly into the compiled assembly's PE metadata.This caused two problems:
0x07(PRIVATEKEYBLOB) instead of0x06(PUBLICKEYBLOB), causingIsValidPublicKeyvalidation to fail duringResolveAssemblyReferenceRoot Cause
In
GetStrongNameSigner(CreateILModule.fs), whenpublicsign=true, the raw.snkfile bytes are stored inPublicKeyOptionsSigner. ThePublicKeyproperty then returned those bytes as-is, without extracting the public key. Compare with theKeyPaircase which correctly callssignerGetPublicKeyForKeyPairto strip private material.Fix
Added
isKeyPairBlobto detect raw CAPI PRIVATEKEYBLOB format, and in thePublicKeyproperty, converts key pair blobs to public-key-only CLR blobs via the existinggetPublicKeyForKeyPairpath.Impact
This unblocks the
dotnet/runtimerolling CI pipeline on Unix legs, where the only F# project (System.Formats.Cbor.Tests.DataModel.fsproj) triggersResolveAssemblyReferencefailures across 15 build legs per run.Tests
RSA2(private key) magic in output DLLAssemblyName.GetAssemblyName()succeeds withoutSecurityExceptionFixes #19441
Regression from #19242