-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Enlighten SignFile for multithreaded mode #13621
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,11 @@ namespace Microsoft.Build.Tasks | |
| /// It can sign ClickOnce manifests as well as exe's. | ||
| /// </summary> | ||
| [SupportedOSPlatform("windows")] | ||
| public sealed class SignFile : Task | ||
| [MSBuildMultiThreadableTask] | ||
| public sealed class SignFile : Task, IMultiThreadableTask | ||
| { | ||
| public TaskEnvironment TaskEnvironment { get; set; } = TaskEnvironment.Fallback; | ||
|
|
||
| public SignFile() | ||
| : base(AssemblyResources.PrimaryResources, "MSBuild.") | ||
| { | ||
|
|
@@ -49,12 +52,14 @@ public override bool Execute() | |
| Log.LogErrorWithCodeFromResources("General.TaskRequiresWindows", nameof(SignFile)); | ||
| return false; | ||
| } | ||
| AbsolutePath signingTargetPath = TaskEnvironment.GetAbsolutePath(SigningTarget.ItemSpec); | ||
| string SanitizeMessage(string msg) => msg?.Replace((string)signingTargetPath, signingTargetPath.OriginalValue) ?? msg; | ||
| try | ||
| { | ||
| SecurityUtilities.SignFile( | ||
| CertificateThumbprint, | ||
| TimestampUrl == null ? null : new Uri(TimestampUrl), | ||
| SigningTarget.ItemSpec, | ||
| signingTargetPath, | ||
| TargetFrameworkVersion, | ||
| TargetFrameworkIdentifier, | ||
| DisallowMansignTimestampFallback); | ||
|
Comment on lines
59
to
65
|
||
|
|
@@ -65,29 +70,29 @@ public override bool Execute() | |
| Log.LogErrorWithCodeFromResources("SignFile.CertNotInStore"); | ||
| return false; | ||
| } | ||
| catch (FileNotFoundException ex) | ||
| catch (FileNotFoundException) | ||
| { | ||
| Log.LogErrorWithCodeFromResources("SignFile.TargetFileNotFound", ex.FileName); | ||
| Log.LogErrorWithCodeFromResources("SignFile.TargetFileNotFound", signingTargetPath.OriginalValue); | ||
| return false; | ||
| } | ||
| catch (ApplicationException ex) | ||
| { | ||
| Log.LogErrorWithCodeFromResources("SignFile.SignToolError", ex.Message.Trim()); | ||
| Log.LogErrorWithCodeFromResources("SignFile.SignToolError", SanitizeMessage(ex.Message).Trim()); | ||
| return false; | ||
| } | ||
| catch (WarningException ex) | ||
| { | ||
| Log.LogWarningWithCodeFromResources("SignFile.SignToolWarning", ex.Message.Trim()); | ||
| Log.LogWarningWithCodeFromResources("SignFile.SignToolWarning", SanitizeMessage(ex.Message).Trim()); | ||
| return true; | ||
| } | ||
| catch (CryptographicException ex) | ||
| { | ||
| Log.LogErrorWithCodeFromResources("SignFile.SignToolError", ex.Message.Trim()); | ||
| Log.LogErrorWithCodeFromResources("SignFile.SignToolError", SanitizeMessage(ex.Message).Trim()); | ||
| return false; | ||
| } | ||
| catch (Win32Exception ex) | ||
| { | ||
| Log.LogErrorWithCodeFromResources("SignFile.SignToolError", ex.Message.Trim()); | ||
| Log.LogErrorWithCodeFromResources("SignFile.SignToolError", SanitizeMessage(ex.Message).Trim()); | ||
| return false; | ||
| } | ||
| catch (UriFormatException ex) | ||
|
|
||
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.
the insides of SecurityUtilities.SignFile depend on process global state