brutaldev / StrongNameSigner

Strong-name sign third party .NET assemblies without the source code.
https://brutaldev.com/post/net-assembly-strong-name-signer
Other
327 stars 68 forks source link

Assembly is invalid after signing #9

Closed danjohnso closed 9 years ago

danjohnso commented 9 years ago

I have a problem using your tool with 2 assemblies where one references the other one. When I sign the 2 assemblies separately, they pass validation. At runtime though, the reference is broken. If I put both of the assemblies in at once, it says the references got fixed, but then fails validation which causes a runtime compile exception, is there a trick to getting the references fixed without breaking the signature?

brutaldev commented 9 years ago

In your first scenario the reference will certainly be broken, if you sign assemblies separately then the reference is not corrected (since there is no knowledge of the referencing assembly).

Your second scenario is the correct way to re-sign so that all assemblies can be checked and new references created for each one.

Could you provide more detail on the runtime compile exception, a stack trace or a specific error message? If the assemblies you are signing are public, can you divulge what they are so that I can test them myself?

danjohnso commented 9 years ago

The assemblies are private so I can't share them. I looked closer at the output and I guess the dependency is actually Assembly A and Assembly B both depend on Assembly C. Assembly C passes verification, Assembly A and B do not: C:\SNK>sn -v AssemblyA.dll

Microsoft (R) .NET Framework Strong Name Utility Version 4.0.30319.17929 Copyright (c) Microsoft Corporation. All rights reserved.

Failed to verify assembly -- Strong name validation failed.

The runtime exception is basically just that the assemblies are not signed correctly:

FileLoadException: Could not load file or assembly 'AssemblyA.dll' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)]

No errors in the output log either, I passed an input/ouput directory and my own key + password as params (also tried without my own key + password, same result):

Strong-name signing C:\AssemblyA.dll... C:\AssemblyA.dll was strong-name signed successfully!

Strong-name signing C:\AssemblyC.dll... C:\AssemblyC.dll was strong-name signed successfully!

Strong-name signing C:\AssemblyB.dll... C:\AssemblyB.dll was strong-name signed successfully!

Fixing references to 'C:\AssemblyC.dll' in 'C:\AssemblyA.dll'... References were fixed successfully!

Fixing references to 'C:\AssemblyB.dll' in 'C:\AssemblyA.dll'... Nothing to fix...

Fixing references to 'C:\AssemblyA.dll' in 'C:\AssemblyC.dll'... Nothing to fix...

Fixing references to 'C:\AssemblyB.dll' in 'C:\AssemblyC.dll'... Nothing to fix...

Fixing references to 'C:\AssemblyA.dll' in 'C:\AssemblyB.dll'... Nothing to fix...

Fixing references to 'C:\AssemblyC.dll' in 'C:\AssemblyB.dll'... References were fixed successfully!

3 file(s) were strong-name signed. 2 references(s) were fixed.

brutaldev commented 9 years ago

Might be the same issue that @Bringer128 is having in Issue #8.

It's late here so I'll take a look in the morning to see if there might be a problem with reference correction invalidating the strong-name key again.

danjohnso commented 9 years ago

Thanks for looking. I was looking around for other options and came across this nuget package that has a set of powershell scripts that successfully sign the dlls: https://www.nuget.org/packages/Nivot.StrongNaming/

Bringer128 commented 9 years ago

I created a pull request that I think fixes this issue (it fixes it on my assemblies).

brutaldev commented 9 years ago

Fixed by @Bringer128 in pull request #10.

Download the latest release (including isntaller) here: https://github.com/brutaldev/StrongNameSigner/releases/tag/1.4.3

danjohnso commented 9 years ago

Yup, that fixes it , thanks!