Skip to content

Commit db04004

Browse files
[xaprepare] log exceptions, and handle CRL check failures
Context: dotnet/arcade#15546 Right now failures just print: Downloading dotnet-install script... -> https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.sh Error: Download of dotnet-install from 'https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.sh' failed Let's log the exception message, as it retries. After this change, we get the intermittent error on macOS only: Warning: Download of 'https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.sh' failed: System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: RevocationStatusUnknown In dotnet/arcade#15546, they addressed this problem by using `SocketsHttpHandler` and configuring the `CertificateChainPolicy` to ignore the `RevocationStatusUnknown` error. Let's use the same approach here.
1 parent 1ff5658 commit db04004

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

build-tools/xaprepare/xaprepare/Application/Utilities.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Net;
66
using System.Net.Http;
7+
using System.Security.Cryptography.X509Certificates;
78
using System.Reflection;
89
using System.Text;
910
using System.Threading;
@@ -388,8 +389,30 @@ static decimal SignificantDigits (decimal number, int maxDigitCount)
388389

389390
public static HttpClient CreateHttpClient ()
390391
{
391-
var handler = new HttpClientHandler {
392-
CheckCertificateRevocationList = true,
392+
// Originally from: https://github.com/dotnet/arcade/pull/15546
393+
// Configure the cert revocation check in a fail-open state to avoid intermittent failures
394+
// on Mac if the endpoint is not available. This is only available on .NET Core, but has only been
395+
// observed on Mac anyway.
396+
397+
var handler = new SocketsHttpHandler ();
398+
handler.SslOptions.CertificateChainPolicy = new X509ChainPolicy
399+
{
400+
// Yes, check revocation.
401+
// Yes, allow it to be downloaded if needed.
402+
// Online is the default, but it doesn't hurt to be explicit.
403+
RevocationMode = X509RevocationMode.Online,
404+
// Roots never bother with revocation.
405+
// ExcludeRoot is the default, but it doesn't hurt to be explicit.
406+
RevocationFlag = X509RevocationFlag.ExcludeRoot,
407+
// RevocationStatusUnknown at the EndEntity/Leaf certificate will not fail the chain build.
408+
// RevocationStatusUnknown for any intermediate CA will not fail the chain build.
409+
// IgnoreRootRevocationUnknown could also be specified, but it won't apply given ExcludeRoot above.
410+
// The default is that all status codes are bad, this is not the default.
411+
VerificationFlags =
412+
X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown |
413+
X509VerificationFlags.IgnoreEndRevocationUnknown,
414+
// Always use the "now" when building the chain, rather than the "now" of when this policy object was constructed.
415+
VerificationTimeIgnored = true,
393416
};
394417

395418
return new HttpClient (handler);
@@ -409,6 +432,7 @@ public static HttpClient CreateHttpClient ()
409432
return (true, (ulong) resp.Content.Headers.ContentLength.Value, resp.StatusCode);
410433
}
411434
} catch (Exception ex) {
435+
Log.WarningLine ($"GetDownloadSize of '{url}' failed: {ex}");
412436
if (i < ExceptionRetries - 1) {
413437
WaitAWhile ($"GetDownloadSize {url}", i, ref ex, ref delay);
414438
}
@@ -434,6 +458,7 @@ public static async Task<bool> Download (Uri url, string targetFile, DownloadSta
434458
succeeded = true;
435459
break;
436460
} catch (Exception ex) {
461+
Log.WarningLine ($"Download of '{url}' failed: {ex}");
437462
if (i < ExceptionRetries - 1) {
438463
WaitAWhile ($"Download {url}", i, ref ex, ref delay);
439464
}

0 commit comments

Comments
 (0)