ejabberd和smack握手失败了

时间:2015-07-07 08:24:51

标签: java android ssl ejabberd smack

我在我的云服务器上运行ejabberd,我认为它运行良好,因为我可以使用pidgin从我的PC连接到它。(ejabberdctl connected-users-number 当我连接时回答1,当我离线时回答0。)

现在我尝试使用smack包从我的android应用程序连接到if,并且我得到IOException:

javax.net.ssl.SSLHandshakeException: Handshake failed

Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xb897c858: Failure in SSL library, usually a protocol error
error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:795 0xacf6bf89:0x00000000)
W/System.err﹕ at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
W/System.err﹕ at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:318)

这是我的应用程序代码:

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
config.setConnectTimeout(30000);
config.setUsernameAndPassword(username + "@" + service, password);
config.setServiceName(service);
config.setHost(host);
config.setCompressionEnabled(true);
config.setPort(port);
config.setDebuggerEnabled(true);
config.setSocketFactory(SSLSocketFactory.getDefault());

SmackConfiguration.DEBUG = true;
try {
    TLSUtils.acceptAllCertificates(config);
    XMPPTCPConnection connection = new XMPPTCPConnection(config.build());
    connection.connect();
    connection.login();

} catch (SmackException ex) {
    ex.printStackTrace();
    chatClient.setConnection(null);
} catch(IOException ex){
    ex.printStackTrace();
    chatClient.setConnection(null);                 
} catch ( XMPPException ex){
    ex.printStackTrace();
    chatClient.setConnection(null);                 
}catch (NoSuchAlgorithmException ex) {
    ex.printStackTrace();
    chatClient.setConnection(null);
}catch (KeyManagementException ex) {
    ex.printStackTrace();
    chatClient.setConnection(null);
}
return null;

我真的很感激任何帮助!!

1 个答案:

答案 0 :(得分:1)

如果服务器中未启用SSL,请禁用SSL。 要禁用,

config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);