-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add signature VerifySigning for dotnet tools #39268
Changes from 13 commits
ac94e8c
00331c9
2d5f551
4bca9df
060e172
5ade9d9
ab30839
df58e0b
89b822d
aaeccf3
66fbe72
3a22067
50378d1
87520e5
2b449fc
deabd72
a7b9ae4
196ab12
131cff5
9e4910b
24658d5
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.RegularExpressions; | ||
using System.Threading; | ||
using Microsoft.DotNet.Cli.Utils; | ||
using Microsoft.DotNet.ToolPackage; | ||
using Microsoft.DotNet.Tools; | ||
using Microsoft.Extensions.EnvironmentAbstractions; | ||
using Microsoft.TemplateEngine.Abstractions; | ||
using NuGet.Common; | ||
using NuGet.Configuration; | ||
using NuGet.Credentials; | ||
|
@@ -130,8 +127,8 @@ public async Task<string> DownloadPackageAsync(PackageId packageId, | |
packageVersion.ToNormalizedString())); | ||
} | ||
|
||
VerifySigning(nupkgPath); | ||
|
||
await VerifySigning(nupkgPath, repository); | ||
return nupkgPath; | ||
} | ||
|
||
|
@@ -141,7 +138,7 @@ private bool verbosityGreaterThanMinimal() | |
&& _verbosityOptions != VerbosityOptions.minimal && _verbosityOptions != VerbosityOptions.m; | ||
} | ||
|
||
private void VerifySigning(string nupkgPath) | ||
private async Task VerifySigning(string nupkgPath, SourceRepository repository) | ||
{ | ||
if (!_verifySignatures && !_validationMessagesDisplayed) | ||
{ | ||
|
@@ -157,14 +154,22 @@ private void VerifySigning(string nupkgPath) | |
return; | ||
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. I am not sure if this is the correct location to add the comment. It could be possible that I don't have a good understanding of the code in this repo. I think we should set If we don't set nugetPackageDownloader ??= new NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreAction, verbosityOptions: _verbosity);
Suggestion is to pass the optional parameter `verifySignatures = true` here also. |
||
} | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
if (await repository.GetResourceAsync<RepositorySignatureResource>().ConfigureAwait(false) is var resource && | ||
Forgind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resource.AllRepositorySigned) | ||
{ | ||
if (!_firstPartyNuGetPackageSigningVerifier.Verify(new FilePath(nupkgPath), | ||
out string commandOutput)) | ||
if (!_shouldUsePackageSourceMapping) | ||
{ | ||
throw new NuGetPackageInstallerException(LocalizableStrings.FailedToValidatePackageSigning + | ||
Environment.NewLine + | ||
commandOutput); | ||
if (!_firstPartyNuGetPackageSigningVerifier.Verify(new FilePath(nupkgPath), out string commandOutput)) | ||
{ | ||
throw new NuGetPackageInstallerException(string.Format(LocalizableStrings.FailedToValidatePackageSigning, commandOutput)); | ||
} | ||
} | ||
else | ||
{ | ||
if (!FirstPartyNuGetPackageSigningVerifier.NuGetVerify(new FilePath(nupkgPath), out string commandOutput)) | ||
{ | ||
throw new NuGetPackageInstallerException(string.Format(LocalizableStrings.FailedToValidatePackageSigning, commandOutput)); | ||
} | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -89,7 +89,7 @@ public ToolInstallGlobalOrToolPathCommand( | |||||
NoCache: (parseResult.GetValue(ToolCommandRestorePassThroughOptions.NoCacheOption) || parseResult.GetValue(ToolCommandRestorePassThroughOptions.NoHttpCacheOption)), | ||||||
IgnoreFailedSources: parseResult.GetValue(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption), | ||||||
Interactive: parseResult.GetValue(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption)); | ||||||
nugetPackageDownloader ??= new NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreAction, verbosityOptions: _verbosity); | ||||||
nugetPackageDownloader ??= new NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreAction, verbosityOptions: _verbosity, verifySignatures: true); | ||||||
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. It looks like
Suggested change
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. This NuGetPackageDownloader is only used to find the app host, so I didn't think I needed to change this, but when I dug a little deeper just now, it does download the app host, so I think that if someone has a feed with a malicious version of the app host that returns faster than nuget.org, that could be bad, so I think you're right. Good catch. Edit: I missed that it was changed here to unconditionally be true. Since this should always be a Microsoft package, I think it should always be signed. 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. Not necessarily, what happens when you're using a daily build of .NET and pulling the apphost from the dotnet-public feed? Those would neither have repository signatures and the package would also not have publisher signatures from Microsoft. 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. Ok. Note that verifySignatures was not available here before the test change, so if the consensus is that it is needed for that nugetPackageDownloader, then we need to keep (at least part of) the test changes as well. |
||||||
_shellShimTemplateFinder = new ShellShimTemplateFinder(nugetPackageDownloader, tempDir, packageSourceLocation); | ||||||
_store = store; | ||||||
|
||||||
|
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.
This aka.ms link points to an announcement which doesn't apply to more recent versions of .NET.
Signed package verification is supported on Linux. See https://learn.microsoft.com/en-us/dotnet/core/tools/nuget-signed-package-verification#linux.