Skip to content

Commit 22dab05

Browse files
Merge pull request #751 from jimmylewis/tls12
Add setting to force TLS 1.2
2 parents 5f16885 + f7fa376 commit 22dab05

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/LibraryManager/Cache/WebRequestHandler.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using Microsoft.Web.LibraryManager.Configuration;
1111
using Microsoft.Web.LibraryManager.Contracts;
12+
using Microsoft.Web.LibraryManager.Contracts.Configuration;
1213
using Microsoft.Web.LibraryManager.Helpers;
1314

1415
namespace Microsoft.Web.LibraryManager.Cache
@@ -20,12 +21,14 @@ internal class WebRequestHandler : IWebRequestHandler, IDisposable
2021
{
2122
private readonly ConcurrentDictionary<string, HttpClient> _cachedHttpClients = new ConcurrentDictionary<string, HttpClient>();
2223

23-
public static IWebRequestHandler Instance { get; } = new WebRequestHandler(ProxySettings.Default);
24+
public static IWebRequestHandler Instance { get; } = new WebRequestHandler(ProxySettings.Default, Settings.DefaultSettings);
2425
private readonly ProxySettings _proxySettings;
26+
private readonly ISettings _settings;
2527

26-
public WebRequestHandler(ProxySettings proxySettings)
28+
public WebRequestHandler(ProxySettings proxySettings, ISettings settings)
2729
{
2830
_proxySettings = proxySettings;
31+
_settings = settings;
2932
}
3033

3134
public void Dispose()
@@ -55,9 +58,14 @@ public async Task<Stream> GetStreamAsync(string url, CancellationToken cancellat
5558

5659
private HttpClient CreateHttpClient(string url)
5760
{
61+
5862
#pragma warning disable CA2000 // Dispose objects before losing scope
5963
var httpMessageHandler = new HttpClientHandler();
6064
#pragma warning restore CA2000 // Dispose objects before losing scope
65+
if (_settings.TryGetValue(Constants.ForceTls12, out string value) && value.Length > 0)
66+
{
67+
httpMessageHandler.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
68+
}
6169
httpMessageHandler.Proxy = _proxySettings.GetProxy(new Uri(url));
6270
var httpClient = new HttpClient(httpMessageHandler);
6371
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd($"LibraryManager/{ThisAssembly.AssemblyFileVersion}");

src/LibraryManager/Configuration/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ internal class Constants
1717
public const string HttpsProxyPassword = "https_proxy.password";
1818
public const string HttpsProxyBypass = "https_proxy.bypass";
1919

20+
public const string ForceTls12 = "forcetls12";
2021
}
2122
}

0 commit comments

Comments
 (0)