Skip to content

Commit 3c71a3c

Browse files
authored
Hotfix: TLS 1.1/1.0 deprecation (June 30, 2023) (#29)
* Implement configuration support for setting SecurityProtocolType Adds support for explicitly setting client TLS version following TLS 1.1/1.0 deprecation announced by Duo (c. June 30, 2023). * Add missing namespace required by ConfigurationManager * Add missing project reference to System.Configuration
1 parent 5c6b376 commit 3c71a3c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

duo_api_csharp/Duo.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
using System;
7+
using System.Configuration;
78
using System.Collections.Generic;
89
using System.IO;
910
using System.Net;
@@ -38,6 +39,20 @@ public class DuoApi
3839
private RandomService randomService;
3940
private bool sslCertValidation = true;
4041
private X509CertificateCollection customRoots = null;
42+
43+
// TLS 1.0/1.1 deprecation effective June 30, 2023
44+
// Of the SecurityProtocolType enum, it should be noted that SystemDefault is not available prior to .NET 4.7 and TLS 1.3 is not available prior to .NET 4.8.
45+
private static SecurityProtocolType SelectSecurityProtocolType
46+
{
47+
get
48+
{
49+
SecurityProtocolType t;
50+
if (!Enum.TryParse(ConfigurationManager.AppSettings["DuoAPI_SecurityProtocolType"], out t))
51+
return SecurityProtocolType.Tls12;
52+
53+
return t;
54+
}
55+
}
4156

4257
/// <param name="ikey">Duo integration key</param>
4358
/// <param name="skey">Duo secret key</param>
@@ -273,6 +288,8 @@ StreamReader reader
273288
private HttpWebRequest PrepareHttpRequest(String method, String url, String auth, String date,
274289
String cannonParams, int timeout)
275290
{
291+
ServicePointManager.SecurityProtocol = SelectSecurityProtocolType;
292+
276293
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
277294
request.ServerCertificateValidationCallback = GetCertificatePinner();
278295
request.Method = method;

duo_api_csharp/duo_api_csharp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<ItemGroup>
3636
<Reference Include="Microsoft.CSharp" />
3737
<Reference Include="System" />
38+
<Reference Include="System.Configuration" />
3839
<Reference Include="System.Core" />
3940
<Reference Include="System.Data" />
4041
<Reference Include="System.Data.DataSetExtensions" />
@@ -56,4 +57,4 @@
5657
<ProjectExtensions>
5758
<VisualStudio AllowExistingFolder="true" />
5859
</ProjectExtensions>
59-
</Project>
60+
</Project>

0 commit comments

Comments
 (0)