use of org.jivesoftware.smack.SmackException.SecurityRequiredByClientException in project Smack by igniterealtime.
the class TlsTest method tlsTest.
public static boolean tlsTest(EntityBareJid jid, String password, String host, int port, String tlsPin, boolean shouldThrow) throws KeyManagementException, NoSuchAlgorithmException {
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
// @formatter:off
builder.setUsernameAndPassword(jid.getLocalpart(), password).setXmppDomain(JidCreate.domainBareFrom(jid.getDomain())).setHost(host).setPort(port).setSecurityMode(SecurityMode.required);
// @formatter:on
builder.setDebuggerEnabled(DEBUG);
if (StringUtils.isNotEmpty(tlsPin)) {
SSLContext sslContext = Java7Pinning.forPin(tlsPin);
builder.setCustomSSLContext(sslContext);
}
XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
connection.setReplyTimeout(20000);
try {
connection.connect().login();
if (shouldThrow) {
// Test not success, should have throwed on login().
return false;
}
} catch (SecurityRequiredByClientException e) {
if (!shouldThrow) {
return false;
}
} catch (XMPPException | SmackException | IOException | InterruptedException e) {
throw new IllegalStateException(e);
} finally {
connection.disconnect();
}
return true;
}
Aggregations