Skip to content

Commit fe655a4

Browse files
[xaprepare] log exceptions, and handle CRL check failures (#9965)
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 ad86668 commit fe655a4

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

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

Lines changed: 26 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,29 @@ 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+
// Yes, check revocation.
400+
// Yes, allow it to be downloaded if needed.
401+
// Online is the default, but it doesn't hurt to be explicit.
402+
RevocationMode = X509RevocationMode.Online,
403+
// Roots never bother with revocation.
404+
// ExcludeRoot is the default, but it doesn't hurt to be explicit.
405+
RevocationFlag = X509RevocationFlag.ExcludeRoot,
406+
// RevocationStatusUnknown at the EndEntity/Leaf certificate will not fail the chain build.
407+
// RevocationStatusUnknown for any intermediate CA will not fail the chain build.
408+
// IgnoreRootRevocationUnknown could also be specified, but it won't apply given ExcludeRoot above.
409+
// The default is that all status codes are bad, this is not the default.
410+
VerificationFlags =
411+
X509VerificationFlags.IgnoreCertificateAuthorityRevocationUnknown |
412+
X509VerificationFlags.IgnoreEndRevocationUnknown,
413+
// Always use the "now" when building the chain, rather than the "now" of when this policy object was constructed.
414+
VerificationTimeIgnored = true,
393415
};
394416

395417
return new HttpClient (handler);
@@ -409,6 +431,7 @@ public static HttpClient CreateHttpClient ()
409431
return (true, (ulong) resp.Content.Headers.ContentLength.Value, resp.StatusCode);
410432
}
411433
} catch (Exception ex) {
434+
Log.WarningLine ($"GetDownloadSize of '{url}' failed: {ex}");
412435
if (i < ExceptionRetries - 1) {
413436
WaitAWhile ($"GetDownloadSize {url}", i, ref ex, ref delay);
414437
}
@@ -434,6 +457,7 @@ public static async Task<bool> Download (Uri url, string targetFile, DownloadSta
434457
succeeded = true;
435458
break;
436459
} catch (Exception ex) {
460+
Log.WarningLine ($"Download of '{url}' failed: {ex}");
437461
if (i < ExceptionRetries - 1) {
438462
WaitAWhile ($"Download {url}", i, ref ex, ref delay);
439463
}

0 commit comments

Comments
 (0)