forked from xamarin/xamarin-android
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled TLS 1.1 and 1.2 support on platforms >= 16 and <= 20
Context: xamarin#1615 It turns out that the older platforms do support TLS 1.1 and 1.2 protocols but that they don't enable it by default. Thanks to code provided by https://github.com/gameleon-dev in the issue linked to above we now support it too. Updated the TLS 1.2 tests to enable them on platforms >= 16
- Loading branch information
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/Mono.Android/Xamarin.Android.Net/OldAndroidSSLSocketFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Java.Net; | ||
using Javax.Net.Ssl; | ||
|
||
namespace Xamarin.Android.Net | ||
{ | ||
// Context: https://github.com/xamarin/xamarin-android/issues/1615 | ||
// | ||
// Code based on the code provided in the issue above | ||
// | ||
class OldAndroidSSLSocketFactory : SSLSocketFactory | ||
{ | ||
readonly SSLSocketFactory factory = (SSLSocketFactory)Default; | ||
|
||
public override string[] GetDefaultCipherSuites () | ||
{ | ||
return factory.GetDefaultCipherSuites (); | ||
} | ||
|
||
public override string[] GetSupportedCipherSuites () | ||
{ | ||
return factory.GetSupportedCipherSuites (); | ||
} | ||
public override Socket CreateSocket (InetAddress address, int port, InetAddress localAddress, int localPort) | ||
{ | ||
return EnableTlsOnSocket (factory.CreateSocket (address, port, localAddress, localPort)); | ||
} | ||
|
||
public override Socket CreateSocket (InetAddress host, int port) | ||
{ | ||
return EnableTlsOnSocket (factory.CreateSocket (host, port)); | ||
} | ||
|
||
public override Socket CreateSocket (string host, int port, InetAddress localHost, int localPort) | ||
{ | ||
return EnableTlsOnSocket (factory.CreateSocket (host, port, localHost, localPort)); | ||
} | ||
|
||
public override Socket CreateSocket (string host, int port) | ||
{ | ||
return EnableTlsOnSocket (factory.CreateSocket (host, port)); | ||
} | ||
|
||
public override Socket CreateSocket (Socket s, string host, int port, bool autoClose) | ||
{ | ||
return EnableTlsOnSocket (factory.CreateSocket (s, host, port, autoClose)); | ||
} | ||
|
||
public override Socket CreateSocket () | ||
{ | ||
return EnableTlsOnSocket (factory.CreateSocket ()); | ||
} | ||
|
||
private Socket EnableTlsOnSocket (Socket socket) | ||
{ | ||
if (socket is SSLSocket sslSocket) { | ||
sslSocket.SetEnabledProtocols (sslSocket.GetSupportedProtocols ()); | ||
} | ||
return socket; | ||
} | ||
} | ||
} |