Skip to content

Commit 3a53853

Browse files
committed
Merged PR 48312: NuGetPackageDownloader: Only verify signing on windows by default (#47321)
NuGetPackageDownloader: Only verify signing on windows by default (#47321) Co-authored-by: Noah Gilson <[email protected]> Co-authored-by: Forgind <[email protected]> ---- #### AI description (iteration 1) #### PR Classification Bug fix to ensure package signing verification is only performed on Windows by default. #### PR Summary This pull request modifies the `NuGetPackageDownloader` to verify package signing only on Windows by default, with an option to enable it on other operating systems via an environment variable. - `src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs`: Added logic to conditionally verify package signatures based on the operating system and environment variable. Introduced error handling to delete the package file if verification fails. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->
1 parent 19b6982 commit 3a53853

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Cli/dotnet/NugetPackageDownloader/NuGetPackageDownloader.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ internal class NuGetPackageDownloader : INuGetPackageDownloader
3838
private readonly Dictionary<PackageSource, SourceRepository> _sourceRepositories;
3939
private readonly bool _shouldUsePackageSourceMapping;
4040

41+
/// <summary>
42+
/// If true, the package downloader will verify the signatures of the packages it downloads.
43+
/// Temporarily disabled for macOS and Linux.
44+
/// </summary>
4145
private readonly bool _verifySignatures;
4246
private readonly VerbosityOptions _verbosityOptions;
4347
private readonly string _currentWorkingDirectory;
@@ -65,7 +69,9 @@ public NuGetPackageDownloader(
6569
_restoreActionConfig = restoreActionConfig ?? new RestoreActionConfig();
6670
_retryTimer = timer;
6771
_sourceRepositories = new();
68-
_verifySignatures = verifySignatures;
72+
// If windows or env variable is set, verify signatures
73+
_verifySignatures = verifySignatures && (OperatingSystem.IsWindows() ? true
74+
: bool.TryParse(Environment.GetEnvironmentVariable(NuGetSignatureVerificationEnabler.DotNetNuGetSignatureVerification), out var shouldVerifySignature) ? shouldVerifySignature : OperatingSystem.IsLinux());
6975

7076
_cacheSettings = new SourceCacheContext
7177
{
@@ -130,8 +136,17 @@ public async Task<string> DownloadPackageAsync(PackageId packageId,
130136
packageVersion.ToNormalizedString()));
131137
}
132138

133-
await VerifySigning(nupkgPath, repository);
134-
139+
// Delete file if verification fails
140+
try
141+
{
142+
await VerifySigning(nupkgPath, repository);
143+
}
144+
catch (NuGetPackageInstallerException)
145+
{
146+
File.Delete(nupkgPath);
147+
throw;
148+
}
149+
135150
return nupkgPath;
136151
}
137152

0 commit comments

Comments
 (0)