4
4
using System . Linq ;
5
5
using System . Net ;
6
6
using System . Net . Http ;
7
+ using System . Security . Cryptography . X509Certificates ;
7
8
using System . Reflection ;
8
9
using System . Text ;
9
10
using System . Threading ;
@@ -388,8 +389,30 @@ static decimal SignificantDigits (decimal number, int maxDigitCount)
388
389
389
390
public static HttpClient CreateHttpClient ( )
390
391
{
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 ,
393
416
} ;
394
417
395
418
return new HttpClient ( handler ) ;
@@ -409,6 +432,7 @@ public static HttpClient CreateHttpClient ()
409
432
return ( true , ( ulong ) resp . Content . Headers . ContentLength . Value , resp . StatusCode ) ;
410
433
}
411
434
} catch ( Exception ex ) {
435
+ Log . WarningLine ( $ "GetDownloadSize of '{ url } ' failed: { ex } ") ;
412
436
if ( i < ExceptionRetries - 1 ) {
413
437
WaitAWhile ( $ "GetDownloadSize { url } ", i , ref ex , ref delay ) ;
414
438
}
@@ -434,6 +458,7 @@ public static async Task<bool> Download (Uri url, string targetFile, DownloadSta
434
458
succeeded = true ;
435
459
break ;
436
460
} catch ( Exception ex ) {
461
+ Log . WarningLine ( $ "Download of '{ url } ' failed: { ex } ") ;
437
462
if ( i < ExceptionRetries - 1 ) {
438
463
WaitAWhile ( $ "Download { url } ", i , ref ex , ref delay ) ;
439
464
}
0 commit comments