1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19:39 +02:00

Add support for HostnameVerifier

SMACK-586

Conflicts:
	smack-core/src/main/java/org/jivesoftware/smack/ConnectionConfiguration.java
	smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
This commit is contained in:
Florian Schmaus 2014-07-21 18:42:44 +02:00
parent 2ca92ef601
commit 057d00c9de
3 changed files with 59 additions and 1 deletions

View file

@ -35,6 +35,7 @@ import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.dns.HostAddress;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
@ -61,6 +62,7 @@ import java.net.Socket;
import java.security.KeyStore;
import java.security.Provider;
import java.security.Security;
import java.security.cert.CertificateException;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
@ -647,14 +649,21 @@ public class XMPPTCPConnection extends XMPPConnection {
// Initialize the reader and writer with the new secured version
initReaderAndWriter();
final SSLSocket sslSocket = (SSLSocket) socket;
try {
// Proceed to do the handshake
((SSLSocket) socket).startHandshake();
sslSocket.startHandshake();
}
catch (IOException e) {
setConnectionException(e);
throw e;
}
final HostnameVerifier verifier = getConfiguration().getHostnameVerifier();
if (verifier != null && !verifier.verify(getServiceName(), sslSocket.getSession())) {
throw new CertificateException("Hostname verification of certificate failed. Certificate does not authenticate " + getServiceName());
}
//if (((SSLSocket) socket).getWantClientAuth()) {
// System.err.println("XMPPConnection wants client auth");
//}