【问题标题】:ejabberd and smack handshake failsejabberd 和 smack 握手失败
【发布时间】:2015-09-24 15:16:03
【问题描述】:

我在我的云服务器中运行 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;

非常感谢任何帮助!

【问题讨论】:

  • config.setSocketFactory(SSLSocketFactory.getDefault()); 你为什么要这样做?
  • 感谢您的评论。我添加它是因为我认为它对 SSL 至关重要。 (如几个示例所示)当我删除它时,我得到了这个 SmackException:java.security.cert.CertificateException:证书的主机名验证失败。证书不对本地主机进行身份验证,然后我更改了 config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);到 config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);然后connect()通过了!但现在我在 login(): SASLError using SCRAM-SHA-1: not-authorized 得到这个 XMPPException:(
  • 您的证书似乎与您的域 (localhost) 不匹配。您应该建立一个真正正确的证书,并且可能使用相同的真实域。
  • @user3698465 你有任何解决方案我有同样的问题,如果达到了就发布解决方案

标签: java android ssl ejabberd smack


【解决方案1】:

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

config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

【讨论】:

    猜你喜欢
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 2018-07-28
    • 2017-06-19
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多