mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-21 16:35:09 -05:00
Set SNI hostname if we can for TLS connections
This commit is contained in:
parent
2282784df2
commit
ebbdc383ec
@ -165,6 +165,7 @@ public abstract class PircBot implements ReplyConstants {
|
||||
context.init(null, new X509TrustManager[] { new NaiveTrustManager() }, null);
|
||||
SSLSocketFactory factory = context.getSocketFactory();
|
||||
SSLSocket ssocket = (SSLSocket) factory.createSocket(hostname, port);
|
||||
setSNIHost(factory, ssocket, hostname);
|
||||
ssocket.startHandshake();
|
||||
_socket = ssocket;
|
||||
}
|
||||
@ -265,6 +266,17 @@ public abstract class PircBot implements ReplyConstants {
|
||||
this.onConnect();
|
||||
}
|
||||
|
||||
private void setSNIHost(final SSLSocketFactory factory, final SSLSocket socket, final String hostname) {
|
||||
if (factory instanceof android.net.SSLCertificateSocketFactory && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
((android.net.SSLCertificateSocketFactory)factory).setHostname(socket, hostname);
|
||||
} else {
|
||||
try {
|
||||
socket.getClass().getMethod("setHostname", String.class).invoke(socket, hostname);
|
||||
} catch (Throwable e) {
|
||||
// ignore any error, we just can't set the hostname...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconnects to the IRC server that we were previously connected to.
|
||||
|
Loading…
Reference in New Issue
Block a user