Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to delay sign or test sign an assembly #55

Closed
aKzenT opened this issue Jan 11, 2016 · 3 comments
Closed

Unable to delay sign or test sign an assembly #55

aKzenT opened this issue Jan 11, 2016 · 3 comments

Comments

@aKzenT
Copy link

aKzenT commented Jan 11, 2016

It seems it is not possible to use dnlib to either only add the public key token to the assembly (delay signing) or to sign the assembly with a test key (signing with a key that is not the same as the public key used during delay signing). This is unfortunate as in our corporation we want to obfuscate assemblies and then only sign them on the build server while developers use test key signing as recommended by Microsoft best practices.

@aKzenT
Copy link
Author

aKzenT commented Jan 12, 2016

To add to this, it is also not possible to round trip such assemblies. When loading a delay signed assembly and then directly saving it again, the assemblies will have the "StrongName" flag set in the header, while normally delay signed assemblies do not have the flag set. The same applies to test-signed assemblies.

@0xd4d
Copy link
Collaborator

0xd4d commented Jan 13, 2016

I've added a DelaySign option to ModuleWriterOptions that you can use.

Generate the public key:

sn -p mykey.snk mypublickey.snk

Delay sign it:

var file = @"c:\some\path\DelaySigned.exe";
var snPublicKey = new StrongNamePublicKey(@"c:\some\path\mypublickey.snk");
var ctx = ModuleDef.CreateModuleContext();
var mod = ModuleDefMD.Load(file, ctx);
//...
var opts = new ModuleWriterOptions(mod);
opts.DelaySign = true;
opts.StrongNamePublicKey = snPublicKey;
mod.Write(@"c:\some\path\DelaySigned_new.exe", opts);

@aKzenT
Copy link
Author

aKzenT commented Jan 13, 2016

Great! Thank you very much. Is there also a property to check if a loaded
assembly is delay signed (ModuleDef) and in this case would the writer be
initialized correctly to roundtrip?

Thanks again!

Edit: Removed remark about public key as this is already handled. Was confused about the .snk ending.

@0xd4d 0xd4d closed this as completed Jun 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant