@@ -38,6 +38,10 @@ internal class NuGetPackageDownloader : INuGetPackageDownloader
38
38
private readonly Dictionary < PackageSource , SourceRepository > _sourceRepositories ;
39
39
private readonly bool _shouldUsePackageSourceMapping ;
40
40
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>
41
45
private readonly bool _verifySignatures ;
42
46
private readonly VerbosityOptions _verbosityOptions ;
43
47
private readonly string _currentWorkingDirectory ;
@@ -65,7 +69,9 @@ public NuGetPackageDownloader(
65
69
_restoreActionConfig = restoreActionConfig ?? new RestoreActionConfig ( ) ;
66
70
_retryTimer = timer ;
67
71
_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 ( ) ) ;
69
75
70
76
_cacheSettings = new SourceCacheContext
71
77
{
@@ -130,8 +136,17 @@ public async Task<string> DownloadPackageAsync(PackageId packageId,
130
136
packageVersion . ToNormalizedString ( ) ) ) ;
131
137
}
132
138
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
+
135
150
return nupkgPath ;
136
151
}
137
152
0 commit comments