-
Notifications
You must be signed in to change notification settings - Fork 9
Add Nuget nupkg signing #11
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
Open
cinderblocks
wants to merge
3
commits into
Daniel15:master
Choose a base branch
from
cinderblocks:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,11 @@ public async Task<Stream> SignAsync(Stream input, X509Certificate2 cert, string | |
| File.WriteAllBytes(certFile, exportedCert); | ||
| await input.CopyToFileAsync(inputFile); | ||
|
|
||
| if (fileExtention == "nupkg") | ||
| { | ||
| return await SignUsingNugetAsync(inputFile, certFile, password); | ||
| } | ||
|
|
||
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| if (fileExtention.Contains("ps")) | ||
|
|
@@ -110,7 +115,7 @@ await RunProcessAsync( | |
| $"/p \"{CommandLineEncoder.Utils.EncodeArgText(certPassword)}\"", | ||
| $"/d \"{CommandLineEncoder.Utils.EncodeArgText(description)}\"", | ||
| $"/du \"{CommandLineEncoder.Utils.EncodeArgText(url)}\"", | ||
| "/tr http://timestamp.digicert.com", | ||
| $"/tr {_pathConfig.Timestamper}", | ||
| "/td sha256", | ||
| "/fd sha256", | ||
| $"\"{CommandLineEncoder.Utils.EncodeArgText(inputFile)}\"", | ||
|
|
@@ -137,14 +142,58 @@ await RunProcessAsync( | |
| "-command", | ||
| "\"$Cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2;", | ||
| $"$Cert.Import('{CommandLineEncoder.Utils.EncodeArgText(certFile)}','{CommandLineEncoder.Utils.EncodeArgText(certPassword)}',[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::DefaultKeySet);", | ||
| $"Set-AuthenticodeSignature '{CommandLineEncoder.Utils.EncodeArgText(inputFile)}' $Cert -Timestamp http://timestamp.digicert.com\"", | ||
| $"Set-AuthenticodeSignature '{CommandLineEncoder.Utils.EncodeArgText(inputFile)}' $Cert -Timestamp {_pathConfig.Timestamper}\"", | ||
| } | ||
| ); | ||
|
|
||
| // PowerShell signs in-place, so just return the file we were given. | ||
| return File.OpenRead(inputFile); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Signs the specified file using nuget.exe. Needs to be a nupkg | ||
| /// </summary> | ||
| /// <param name="inputFile">File to sign</param> | ||
| /// <param name="certFile">Path to the certificate to use for signing</param> | ||
| /// <param name="certPassword">Password for the certificate</param> | ||
| /// <returns>A signed copy of the file</returns> | ||
| private async Task<Stream> SignUsingNugetAsync(string inputFile, string certFile, string certPassword) | ||
| { | ||
| // if we aren't windows, we need to call nuget from mono | ||
| if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| { | ||
| await RunProcessAsync( | ||
| "mono", | ||
| new[] | ||
| { | ||
| _pathConfig.Nuget, | ||
| "sign", | ||
| $"-CertificatePath \"{CommandLineEncoder.Utils.EncodeArgText(certFile)}\"", | ||
| $"-CertificatePassword \"{CommandLineEncoder.Utils.EncodeArgText(certPassword)}\"", | ||
| $"-Timestamper {_pathConfig.Timestamper}", | ||
| $"\"{CommandLineEncoder.Utils.EncodeArgText(inputFile)}\"", | ||
| } | ||
| ); | ||
| } | ||
| else | ||
| { | ||
| await RunProcessAsync( | ||
| _pathConfig.Nuget, | ||
| new[] | ||
| { | ||
| "sign", | ||
| $"-CertificatePath \"{CommandLineEncoder.Utils.EncodeArgText(certFile)}\"", | ||
| $"-CertificatePassword \"{CommandLineEncoder.Utils.EncodeArgText(certPassword)}\"", | ||
| $"-Timestamper {_pathConfig.Timestamper}", | ||
| $"\"{CommandLineEncoder.Utils.EncodeArgText(inputFile)}\"", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These arguments are all identical across both - Can you please remove the duplication (eg. pull them out into a separate array)? |
||
| } | ||
| ); | ||
| } | ||
|
|
||
| // nuget signs in-place, so just return the file we were given. | ||
| return File.OpenRead(inputFile); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Signs the specified file using osslsigncode | ||
| /// </summary> | ||
|
|
@@ -204,7 +253,7 @@ private async Task RunOsslSignCodeAsync(string certFile, string certPasswordFile | |
| var args = new List<string> | ||
| { | ||
| "sign", | ||
| "-ts http://timestamp.digicert.com", | ||
| $"-ts {_pathConfig.Timestamper}", | ||
| $"-n \"{CommandLineEncoder.Utils.EncodeArgText(description)}\"", | ||
| $"-i \"{CommandLineEncoder.Utils.EncodeArgText(url)}\"", | ||
| $"-pkcs12 \"{CommandLineEncoder.Utils.EncodeArgText(certFile)}\"", | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Mono really needed here? Could it use .NET Core instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it doesn't work in .NET Core yet. NuGet/NuGet.Client#2545