Skip to content

Commit

Permalink
Add an option to specify the container name
Browse files Browse the repository at this point in the history
This is useful when strong signing C++ binaries where the container name is not automatically generated and must be passed over command line
  • Loading branch information
Jan Vratislav committed Nov 27, 2019
1 parent 8ba031d commit 37bbcd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ This command has two drawbacks
2. You have to enter PFX password. This password cannot be passed as a parameter which make things complicated in batch scenarios.

## SnInstallPFX utility
I have written a .NET utility that overcomes the aforementioned drawbacks. It computes the container name from the PFX file and accepts the password as a parameter.
I have written a .NET utility that overcomes the aforementioned drawbacks. It computes the container name from the PFX file (if not specified) and accepts the password as a parameter.

```
SnInstallPfx.exe <pfx_infile> <pfx_password>
SnInstallPfx.exe <pfx_infile> <pfx_password> <container_name>
```
The hash computing is copied from the MSBuild source code on GitHub.

Expand Down
14 changes: 8 additions & 6 deletions src/SnInstallPfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@ public static class SnInstallPfx
static int Main(string[] args)
{
// params and usage
if (args.Length == 0 || args[0] == "?" || args[0] == "-?" || args.Length != 2)
if (args.Length == 0 || args[0] == "?" || args[0] == "-?" || args.Length != 2 || args.Length != 3)
{
Console.WriteLine("By Honzajscz at 2019");
Console.WriteLine("Installs key pair from <pfx_infile> into a key container compatible for MSBuild.");
Console.WriteLine("This utility is an alternative for command sn.exe -i <infile> <container>.");
Console.WriteLine("It accepts password from command line and automatically generates a container for <pxf_infile>.");
Console.WriteLine("It accepts password from command line and automatically generates a container name for <pxf_infile> if no container name is specified via the <container_name> argument.");
Console.WriteLine();
Console.WriteLine($"Usage: {Assembly.GetEntryAssembly().GetName().Name}.exe <pfx_infile> <pfx_password>");
Console.WriteLine("Usage:");
Console.WriteLine($"{Assembly.GetEntryAssembly().GetName().Name}.exe <pfx_infile> <pfx_password>");
Console.WriteLine($"{Assembly.GetEntryAssembly().GetName().Name}.exe <pfx_infile> <pfx_password> <container_name>");
Console.WriteLine();

return -1;
}

string pfxPath = args[0];
string pfxPassword = args[1];
string pfxContainer = args.Length == 3 ? args[2] : ResolveKeySourceTask.ResolveAssemblyKey(pfxPath);

var pfxContainer = ResolveKeySourceTask.ResolveAssemblyKey(pfxPath);
if (ResolveKeySourceTask.IsContainerInstalled(pfxContainer))
{
//Installs from infile in the specified key container. The key container resides in the strong name CSP.
Console.Error.WriteLine($"The key pair is already installed in the strong name CSP key container '{pfxContainer}'.");
Console.Error.WriteLine("To delete the key container run following command from the Developer Command Prompt:");
Console.Error.WriteLine($"sn.exe -d {pfxContainer}");
Console.Error.WriteLine();
Console.Error.WriteLine($"To list all installed key containers run following command:");
Console.Error.WriteLine($"certutil -csp \"Microsoft Strong Cryptographic Provider\" -key");
Console.Error.WriteLine("To list all installed key containers run following command:");
Console.Error.WriteLine("certutil -csp \"Microsoft Strong Cryptographic Provider\" -key");
return -2;
}

Expand Down

0 comments on commit 37bbcd5

Please sign in to comment.