|
6 | 6 | using System.Linq;
|
7 | 7 | using System.Net;
|
8 | 8 | using System.Net.Http;
|
| 9 | +using System.Security.Cryptography.X509Certificates; |
9 | 10 | using System.Threading;
|
10 | 11 | using Microsoft.Build.Framework;
|
11 | 12 | using Microsoft.Build.Utilities;
|
@@ -123,7 +124,36 @@ private async Tasks.Task<bool> DownloadFromUriAsync(string uri) {
|
123 | 124 |
|
124 | 125 | Log.LogMessage($"Downloading '{uri}' to '{DestinationPath}'");
|
125 | 126 |
|
| 127 | + // Configure the cert revocation check in a fail-open state to avoid intermittent failures |
| 128 | + // on Mac if the endpoint is not available. This is only available on .NET Core, but has only been |
| 129 | + // observed on Mac anyway. |
| 130 | + |
| 131 | +#if NET |
| 132 | + using SocketsHttpHandler handler = new SocketsHttpHandler(); |
| 133 | + handler.SslOptions.CertificateChainPolicy = new X509ChainPolicy |
| 134 | + { |
| 135 | + // Yes, check revocation. |
| 136 | + // Yes, allow it to be downloaded if needed. |
| 137 | + // Online is the default, but it doesn't hurt to be explicit. |
| 138 | + RevocationMode = X509RevocationMode.Online, |
| 139 | + // Roots never bother with revocation. |
| 140 | + // ExcludeRoot is the default, but it doesn't hurt to be explicit. |
| 141 | + RevocationFlag = X509RevocationFlag.ExcludeRoot, |
| 142 | + // RevocationStatusUnknown at the EndEntity/Leaf certificate will not fail the chain build. |
| 143 | + // RevocationStatusUnknown for any intermediate CA will not fail the chain build. |
| 144 | + // IgnoreRootRevocationUnknown could also be specified, but it won't apply given ExcludeRoot above. |
| 145 | + // The default is that all status codes are bad, this is not the default. |
| 146 | + VerificationFlags = |
| 147 | + X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown | |
| 148 | + X509VerificationFlags.IgnoreEndRevocationUnknown, |
| 149 | + // Always use the "now" when building the chain, rather than the "now" of when this policy object was constructed. |
| 150 | + VerificationTimeIgnored = true, |
| 151 | + }; |
| 152 | + |
| 153 | + using (var httpClient = new HttpClient(handler)) |
| 154 | +#else |
126 | 155 | using (var httpClient = new HttpClient(new HttpClientHandler { CheckCertificateRevocationList = true }))
|
| 156 | +#endif |
127 | 157 | {
|
128 | 158 | httpClient.Timeout = TimeSpan.FromSeconds(TimeoutInSeconds);
|
129 | 159 | try
|
|
0 commit comments