@@ -39,6 +39,10 @@ internal class NuGetPackageDownloader : INuGetPackageDownloader
39
39
private readonly ConcurrentDictionary < PackageSource , SourceRepository > _sourceRepositories ;
40
40
private readonly bool _shouldUsePackageSourceMapping ;
41
41
42
+ /// <summary>
43
+ /// If true, the package downloader will verify the signatures of the packages it downloads.
44
+ /// Temporarily disabled for macOS and Linux.
45
+ /// </summary>
42
46
private readonly bool _verifySignatures ;
43
47
private readonly VerbosityOptions _verbosityOptions ;
44
48
private readonly string _currentWorkingDirectory ;
@@ -66,7 +70,9 @@ public NuGetPackageDownloader(
66
70
_restoreActionConfig = restoreActionConfig ?? new RestoreActionConfig ( ) ;
67
71
_retryTimer = timer ;
68
72
_sourceRepositories = new ( ) ;
69
- _verifySignatures = verifySignatures ;
73
+ // If windows or env variable is set, verify signatures
74
+ _verifySignatures = verifySignatures && ( OperatingSystem . IsWindows ( ) ? true
75
+ : bool . TryParse ( Environment . GetEnvironmentVariable ( NuGetSignatureVerificationEnabler . DotNetNuGetSignatureVerification ) , out var shouldVerifySignature ) ? shouldVerifySignature : OperatingSystem . IsLinux ( ) ) ;
70
76
71
77
_cacheSettings = new SourceCacheContext
72
78
{
@@ -127,8 +133,17 @@ public async Task<string> DownloadPackageAsync(PackageId packageId,
127
133
packageVersion . ToNormalizedString ( ) ) ) ;
128
134
}
129
135
130
- await VerifySigning ( nupkgPath , repository ) ;
131
-
136
+ // Delete file if verification fails
137
+ try
138
+ {
139
+ await VerifySigning ( nupkgPath , repository ) ;
140
+ }
141
+ catch ( NuGetPackageInstallerException )
142
+ {
143
+ File . Delete ( nupkgPath ) ;
144
+ throw ;
145
+ }
146
+
132
147
return nupkgPath ;
133
148
}
134
149
0 commit comments