Skip to content

Commit

Permalink
Fixes #140 ... failed to create safe SSL/TLS context
Browse files Browse the repository at this point in the history
  • Loading branch information
3F committed Mar 28, 2020
1 parent a769b40 commit aeaeaa3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Wizard/PackageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using net.r_eg.MvsSln.Extensions;
using net.r_eg.MvsSln.Log;

namespace net.r_eg.DllExport.Wizard
Expand All @@ -53,6 +54,8 @@ public PackageInfo(IExecutor exec)
{
this.exec = exec ?? throw new ArgumentNullException(nameof(exec));
proxy = exec.Config.Proxy?.Trim();

DefineSecurityProtocol();
}

/// <summary>
Expand Down Expand Up @@ -145,5 +148,19 @@ private WebProxy GetProxy(string cfg)
)
};
}

private static void DefineSecurityProtocol()
{
// https://github.com/3F/DllExport/issues/140
// Since Tls13 (0x3000) is not available from obsolete assemblies,
// and SecurityProtocolType.SystemDefault (0) is defined only for netfx 4.7+, 4.8;
// We can try to bind this at runtime using the last available environment where this code was executed.

// NOTE: ServicePointManager.SecurityProtocol = 0 may produce the following problem: An unexpected error occurred on a receive.

Enum.GetValues(typeof(SecurityProtocolType))
.Cast<SecurityProtocolType>()
.ForEach(s => ServicePointManager.SecurityProtocol |= s);
}
}
}

0 comments on commit aeaeaa3

Please sign in to comment.