Skip to content

Key container signing fix#25426

Merged
agocke merged 4 commits intodotnet:dev15.6.xfrom
agocke:key-container-signing-fix
Mar 15, 2018
Merged

Key container signing fix#25426
agocke merged 4 commits intodotnet:dev15.6.xfrom
agocke:key-container-signing-fix

Conversation

@agocke
Copy link
Copy Markdown
Member

@agocke agocke commented Mar 12, 2018

Customer scenario(s)

There are two signing bugs. In the first, the compiler fails to sign an assembly if signing is specific using the AssemblyKeyContainer attribute and nothing else. Specifically, if key signing is requested using a key file or using a key container but provided through command line or MSBuild option, signing succeeds. In the second, the -delaysign option will fully sign an assembly if provided a key file that contains both a public and private key.

Bugs this fixes

#25340
#25424

Tracking bug https://devdiv.visualstudio.com/DevDiv/_workitems/edit/580955

Workarounds, if any

There are three possible workarounds for the key container bug for 15.6:

  1. You can switch to using a keyfile instead of a key container.
  2. You can enable a fallback mode by putting the following in your MSBuild project files
<Features>$(Features);UseLegacyStrongNameProvider</Features>
  1. You can move the name of the key container from the AssemblyAttributes C# file to your project file(s) by adding the following property:
<KeyContainerName>the-name-of-your-key-here</KeyContainerName>

For the delaysign bug, you can use the UseLegacyStrongNameProvider flag on Windows, or you can create a key file that contains only the public key, with no private key.

Risk

This change mostly moves us back to using the old signing behavior. The only change not related is the fix for delaysign on CoreCLR, which is a targeted fix to prevent us from full-signing when it was not requested. This change has been validated by unit tests.

Performance impact

Almost none -- an additional null check in the working case and only a handful of allocations.

Is this a regression from a previous update?

This is a regression, but not from another update. Key container signing using attributes previously worked.

Root cause analysis

The tests only tried to test key containers with the desktop strong name provider, assuming that only a desktop strong name provider would be provided if we require key container signing. This is incorrect. This change moves us back to the old signing code, which has proper tests for these scenarios. For the delaysign fix, appropriate tests have been added for the CoreCLR code.

How was the bug found?

Customer reported.

@agocke agocke requested a review from a team as a code owner March 12, 2018 19:09
@agocke agocke force-pushed the key-container-signing-fix branch from cb2a1a5 to 50f0cb5 Compare March 12, 2018 20:22
@agocke agocke requested a review from a team as a code owner March 12, 2018 20:22
@agocke agocke force-pushed the key-container-signing-fix branch 3 times, most recently from 8f430f0 to 4ce58fa Compare March 12, 2018 23:05
@agocke agocke changed the title [WIP] Key container signing fix Key container signing fix Mar 13, 2018
@agocke agocke force-pushed the key-container-signing-fix branch from fa200c0 to 66cda66 Compare March 14, 2018 17:51
@agocke agocke requested a review from a team as a code owner March 14, 2018 17:51
This change makes the legacy behavior contingent on the runtime of the
compiler. When the compiler is running on the desktop runtime, the
legacy signing code will be used. When running on CoreCLR, the new
portable signing code will be used. This fixes key container signing for
almost all scenarios (signing using a key container when the compiler is
running on the desktop framework). Signing using a key container on
Windows using a compiler running on CoreCLR is still broken, but that is
a far rarer case.

This change also fixes delaysign, which would full sign the file if the
keyfile passed to the compiler contains a private key.

Fixes dotnet#25340
Fixes dotnet#25424
@agocke agocke force-pushed the key-container-signing-fix branch from 66cda66 to 44f1388 Compare March 14, 2018 18:49
@jcouv
Copy link
Copy Markdown
Member

jcouv commented Mar 14, 2018

    private void DelaySignWithAssemblySignatureKeyHelper(StrongNameProvider provider)

Consider making this a local function, since used by a single test


Refers to: src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs:1594 in e1a84e2. [](commit_id = e1a84e2, deletion_comment = False)

var header = metadata.Module.PEReaderOpt.PEHeaders.CorHeader;
//confirm header has expected SN signature size
Assert.Equal(256, header.StrongNameSignatureDirectory.Size);
Assert.Equal(CorFlags.ILOnly, header.Flags);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider adding a comment ("although a private key was provided, the assembly is still not signed" or something)

@agocke agocke merged commit e2fc8d5 into dotnet:dev15.6.x Mar 15, 2018
@agocke agocke deleted the key-container-signing-fix branch March 15, 2018 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants