Skip to content

Commit 5a4f77f

Browse files
committed
C#: Set up proxy for IsFeedReachable, if configured
1 parent 20ad190 commit 5a4f77f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using System.Collections.Generic;
44
using System.IO;
55
using System.Linq;
6+
using System.Net;
67
using System.Net.Http;
7-
using System.Security.Cryptography;
8+
using System.Security.Cryptography.X509Certificates;
89
using System.Text;
910
using System.Text.RegularExpressions;
1011
using System.Threading;
@@ -592,7 +593,26 @@ private static async Task ExecuteGetRequest(string address, HttpClient httpClien
592593
private bool IsFeedReachable(string feed, int timeoutMilliSeconds, int tryCount, bool allowExceptions = true)
593594
{
594595
logger.LogInfo($"Checking if Nuget feed '{feed}' is reachable...");
595-
using HttpClient client = new();
596+
597+
// Configure the HttpClient to be aware of the Dependabot Proxy, if used.
598+
HttpClientHandler httpClientHandler = new();
599+
if (this.dependabotProxy.IsConfigured)
600+
{
601+
httpClientHandler.Proxy = new WebProxy(this.dependabotProxy.Address);
602+
603+
if (!String.IsNullOrEmpty(this.dependabotProxy.CertificatePath))
604+
{
605+
X509Certificate2 proxyCert = new X509Certificate2(this.dependabotProxy.CertificatePath);
606+
httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, _) =>
607+
{
608+
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
609+
chain.ChainPolicy.CustomTrustStore.Add(proxyCert);
610+
return chain.Build(cert);
611+
};
612+
}
613+
}
614+
615+
using HttpClient client = new(httpClientHandler);
596616

597617
for (var i = 0; i < tryCount; i++)
598618
{

0 commit comments

Comments
 (0)