use direct ssl when port was manually set to 5223

this should create a work around for the oracle xmpp server
This commit is contained in:
Daniel Gultsch 2016-08-10 12:34:05 +02:00
parent 9bfdbc708e
commit 08725ba2bb
1 changed files with 24 additions and 2 deletions

View File

@ -46,6 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.X509KeyManager; import javax.net.ssl.X509KeyManager;
@ -271,9 +272,30 @@ public class XmppConnection implements Runnable {
socket = SocksSocketFactory.createSocketOverTor(destination, account.getPort()); socket = SocksSocketFactory.createSocketOverTor(destination, account.getPort());
startXmpp(); startXmpp();
} else if (extended && account.getHostname() != null && !account.getHostname().isEmpty()) { } else if (extended && account.getHostname() != null && !account.getHostname().isEmpty()) {
socket = new Socket();
InetSocketAddress address = new InetSocketAddress(account.getHostname(), account.getPort());
features.encryptionEnabled = account.getPort() == 5223;
try { try {
socket.connect(new InetSocketAddress(account.getHostname(), account.getPort()), Config.SOCKET_TIMEOUT * 1000); if (features.encryptionEnabled) {
try {
final TlsFactoryVerifier tlsFactoryVerifier = getTlsFactoryVerifier();
socket = tlsFactoryVerifier.factory.createSocket();
socket.connect(address, Config.SOCKET_TIMEOUT * 1000);
final SSLSession session = ((SSLSocket) socket).getSession();
if (!tlsFactoryVerifier.verifier.verify(account.getServer().getDomainpart(),session)) {
Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": TLS certificate verification failed");
throw new SecurityException();
}
} catch (KeyManagementException e) {
features.encryptionEnabled = false;
socket = new Socket();
}
} else {
socket = new Socket();
socket.connect(address, Config.SOCKET_TIMEOUT * 1000);
}
} catch (IOException e) { } catch (IOException e) {
throw new UnknownHostException(); throw new UnknownHostException();
} }