Skip to content

Commit 7bc5dbf

Browse files
committed
fix(WSConnector): Always use TLS 1.0 endpoint if users are not on .NET 4.6.
1 parent e0892dd commit 7bc5dbf

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Scripts/Connection/WSConnector.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public Dictionary<string, string> Headers {
203203
public static string FixupURL(string URL)
204204
{
205205
#if UNITY_2018_2_OR_NEWER
206+
#if NET_4_6
206207
// Use standard endpoints since 2018.2 supports TLS 1.2
207208
if (URL.StartsWith("http://stream."))
208209
{
@@ -260,6 +261,26 @@ public static string FixupURL(string URL)
260261
{
261262
Log.Warning("WSConnector", "No case for URL for wss://. Leaving URL unchanged.");
262263
}
264+
#else
265+
// Use TLS 1.0 endpoint if user is on .NET 3.5. US South is the
266+
// only region that supports this endpoint.
267+
if (URL.StartsWith("http://stream."))
268+
{
269+
URL = URL.Replace("http://stream.", "ws://stream-tls10.");
270+
}
271+
else if (URL.StartsWith("https://stream."))
272+
{
273+
URL = URL.Replace("https://stream.", "wss://stream-tls10.");
274+
}
275+
else if (URL.StartsWith("http://stream-tls10."))
276+
{
277+
URL = URL.Replace("http://stream-tls10.", "ws://stream-tls10.");
278+
}
279+
else if (URL.StartsWith("https://stream-tls10."))
280+
{
281+
URL = URL.Replace("https://stream-tls10.", "wss://stream-tls10.");
282+
}
283+
#endif
263284
#else
264285
// Redirect to TLS 1.0 endpoints.
265286
// Note frankfurt endpoint does not support TLS 1.0.
@@ -397,7 +418,7 @@ private IEnumerator ProcessReceiveQueue()
397418
#endregion
398419

399420
#region Threaded Functions
400-
// NOTE: ALl functions in this region are operating in a background thread, do NOT call any Unity functions!
421+
// NOTE: All functions in this region are operating in a background thread, do NOT call any Unity functions!
401422
#if !NETFX_CORE
402423
private void SendMessages()
403424
{
@@ -415,8 +436,10 @@ private void SendMessages()
415436
ws.OnError += OnWSError;
416437
ws.OnMessage += OnWSMessage;
417438
#if NET_4_6
439+
// Enable TLS 1.1 and TLS 1.2 if we are on .NET 4.x
418440
ws.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
419441
#else
442+
// .NET 3.x does not support TLS 1.1 or TLS 1.2
420443
ws.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls;
421444
#endif
422445
ws.Connect();

0 commit comments

Comments
 (0)