我正在尝试从 Android 连接到本地的 Apache Vysper XMPP 服务器。我使用Smack框架执行 XMPP 操作:
AbstractXMPPConnection connection = new XMPPTCPConnection("bigdestroyer", "", ip);
try {
connection.setPacketReplyTimeout(10000);
connection.connect();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
但是我收到了这个错误:
``` javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. ```
我猜这与SSL证书有关,但我不知道该怎么做。你能帮我吗?
我已经尝试将`cert`文件(与服务器相同)放在`assets`文件夹中,并通过以下方式创建连接:
XMPPTCPConnectionConfiguration connectionConfiguration = configuration.setConnectTimeout(10000)
.setUsernameAndPassword("admin", "admin")
.setHost(ip)
.setServiceName(ip)
.setKeystorePath("file:///android_asset/bogus_mina_tls.cert")
.build();
XMPPTCPConnection connection = new XMPPTCPConnection(connectionConfiguration);
但是它仍然无法正常工作。有任何建议吗?