ejabberd和smack握手失败

6

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

现在我尝试使用smack包从我的Android应用程序连接它,并且我收到了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()); 为什么要这样做? - Flow
谢谢您的评论。我添加了它,因为我认为它对SSL非常重要(正如在几个示例中所看到的)。 当我将其删除后,我遇到了这个SmackException: java.security.cert.CertificateException:证书的主机名验证失败。证书未对localhost进行身份验证 然后我将 config.setSecurityMode(ConnectionConfiguration.SecurityMode.required); 更改为 config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled); 然后connect()通过了! 但现在我在login()中遇到了这个XMPPException: SASLError使用SCRAM-SHA-1:未经授权 - user3698465
看起来您的证书与您的域名(localhost)不匹配。您应该构建一个真正正确的证书,并可能使用同一个真实的域名。 - Mickaël Rémond
@user3698465,你有解决方案吗?我遇到了同样的问题,请发布解决方案如果成功。 - PankajAndroid
1个回答

0

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

config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接