Skip to content

Commit ca3c62a

Browse files
[release/9.0] Permit fail-open to avoid CRL check failures on Mac (#15712)
Co-authored-by: Matt Mitchell <[email protected]>
1 parent 97cbc73 commit ca3c62a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Microsoft.DotNet.Arcade.Sdk/src/DownloadFile.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Net;
88
using System.Net.Http;
9+
using System.Security.Cryptography.X509Certificates;
910
using System.Threading;
1011
using Microsoft.Build.Framework;
1112
using Microsoft.Build.Utilities;
@@ -123,7 +124,36 @@ private async Tasks.Task<bool> DownloadFromUriAsync(string uri) {
123124

124125
Log.LogMessage($"Downloading '{uri}' to '{DestinationPath}'");
125126

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
126155
using (var httpClient = new HttpClient(new HttpClientHandler { CheckCertificateRevocationList = true }))
156+
#endif
127157
{
128158
httpClient.Timeout = TimeSpan.FromSeconds(TimeoutInSeconds);
129159
try

0 commit comments

Comments
 (0)