Skip to content

Add support for delay-signing with a public only keyfile#523

Merged
SimonCropp merged 3 commits into
Fody:masterfrom
ryknuth:master
Jul 19, 2018
Merged

Add support for delay-signing with a public only keyfile#523
SimonCropp merged 3 commits into
Fody:masterfrom
ryknuth:master

Conversation

@ryknuth

@ryknuth ryknuth commented Apr 28, 2018

Copy link
Copy Markdown
Contributor

Problem:
Delay-signing allows for keyfiles to contain only the public key since the private key is not needed. Unfortunately, public key bytes do not create a valid StrongNameKeyPair. StrongNameKeyPair requires the private key to regenerate the public key. Mono.Cecil uses the StrongNameKeyPair to set the public key on the assembly and to sign the assembly. If an invalid StrongNameKeyPair is given to Mono.Cecil, an exception is thrown and Fody fails.

Fix:
Avoid creating the StrongNameKeyPair and instead use the new PublicKeyBytes on the WriterParameters from Mono.Cecil. If provided, Mono.Cecil will directly set these bytes on the AssemblyName and avoid attempting to sign the assembly.

It's a bit difficult to tell what type of keyfile is present. The simplest way is to create the StrongNameKeyPair and attempt to generate the public key. If this throws an ArgumentException, we know that the private key was not present within the keyfile. In this case, null out the StrongNameKeyPair and pass along the key file bytes as the public key bytes.

Problem:
Delay-signing allows for keyfiles to contain only the public key since the private key is not needed. Unfortunately, public key bytes do not create a valid StrongNameKeyPair.  StrongNameKeyPair requires the private key to regenerate the public key. Mono.Cecil uses the StrongNameKeyPair to set the public key on the assembly and to sign the assembly.  If an invalid StrongNameKeyPair is given to Mono.Cecil, an exception is thrown and Fody fails.

Fix:
Avoid creating the StrongNameKeyPair and instead use the new PublicKeyBytes on the WriterParameters from Mono.Cecil. If provided, Mono.Cecil will directly set these bytes on the AssemblyName and avoid attempting to sign the assembly.

It's a bit difficult to tell what type of keyfile is present. The simplest way is to create the StrongNameKeyPair and attempt to generate the public key. If this throws an ArgumentException, we know that the private key was not present within the keyfile.  In this case, null out the StrongNameKeyPair and pass along the key file bytes as the public key bytes.
@ryknuth

ryknuth commented Apr 28, 2018

Copy link
Copy Markdown
Contributor Author

The API depends on Mono.Cecil accepting my PR for them.

@ryknuth

ryknuth commented Apr 30, 2018

Copy link
Copy Markdown
Contributor Author

I found a bug in my code. I updated my branch but am unsure how to modify this PR.

@SimonCropp SimonCropp left a comment

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.

Any possibility of adding some tests to verify thie?

@SimonCropp

Copy link
Copy Markdown
Member

Pushing to your branch should automatically update this pr. U should see the commit in the commits tab of the pr

@ryknuth

ryknuth commented May 1, 2018

Copy link
Copy Markdown
Contributor Author

I would love to add tests. Could you give me a good location in your test suites to add some?

Also, how would you like to handle Mono.Cecil? Since you take a drop, you could take a build with my PR integrated without waiting for a new release.

@SimonCropp

Copy link
Copy Markdown
Member

@ryknuth unfortunately i cant accept this until it is the associated cecil PR is merged into the cecil master

@SimonCropp

Copy link
Copy Markdown
Member

i have updated cecil to 33cfa97. can u rebase this

@Kethku

Kethku commented Jul 18, 2018

Copy link
Copy Markdown

This is currently blocking me. Is there anyway I can help to push this along?

@SimonCropp
SimonCropp merged commit 44a68ca into Fody:master Jul 19, 2018
@SimonCropp SimonCropp added this to the 3.2.0 milestone Jul 19, 2018
@SimonCropp

Copy link
Copy Markdown
Member

@Kethku i merged this. but it is blocked (ie i cant release) until this PR in cecil is merged jbevain/cecil#513

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