当前位置: 首页 > 知识库问答 >
问题:

使用asmack连接到服务器时出现SSL异常

姬翰林
2023-03-14

我正在使用asmack-android-16为我的聊天应用程序。有时,在创建连接,我得到SSL异常,然后我无法登录服务器。我的服务器正在对连接使用SSL身份验证。有人能帮帮我吗?我已经挣扎了好几周了

以下是我的连接配置:

    HOST = "my_ejabbered_url";
    PORT = "5223";
    connectionConfiguration = new ConnectionConfiguration(HOST,PORT);
    connectionConfiguration.setDebuggerEnabled(true);
    SASLAuthentication.supportSASLMechanism("PLAIN");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        connectionConfiguration.setTruststoreType("AndroidCAStore");
        connectionConfiguration.setTruststorePassword(null);
        connectionConfiguration.setTruststorePath(null);
    } else {
        connectionConfiguration.setTruststoreType("BKS");
        String path = System.getProperty("javax.net.ssl.trustStore");
        if (path == null)
            path = System.getProperty("java.home") + File.separator + "etc"
                    + File.separator + "security" + File.separator
                    + "cacerts.bks";
        connectionConfiguration.setTruststorePath(path);
    }
    connectionConfiguration.setSASLAuthenticationEnabled(true);

XMPPConnection连接=new XMPPConnection(连接配置);connection.connect (); // 调用此行会给我异常,尽管已创建连接。

以下是日志:

01-21 07:59:59.044     557-1418/app_package_name D/SMACK﹕ 07:59:59 AM SENT (1119449544): <stream:stream to="ejabbered_url" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
01-21 07:59:59.443     557-1419/app_package_name D/SMACK﹕ 07:59:59 AM RCV  (1119449544): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='635893435' from='ejabbered_url' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='IJkhK7jY9EYjAQlR7KzPYJ8ZwMo='/></stream:features>
01-21 07:59:59.443     557-1419/app_package_name D/SMACK﹕ 07:59:59 AM SENT (1119449544): <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
01-21 07:59:59.857     557-1419/app_package_name D/SMACK﹕ 07:59:59 AM RCV  (1119449544): <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
01-21 08:00:00.271     557-1418/app_package_name D/SMACK﹕ 08:00:00 AM SENT (1119449544): <presence id="bMxCR-2" type="unavailable"></presence>
01-21 08:00:00.271     557-1418/app_package_name W/System.err﹕ java.net.SocketException: Socket closed
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at libcore.io.Posix.sendtoBytes(Native Method)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at libcore.io.Posix.sendto(Posix.java:155)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at libcore.io.IoBridge.sendto(IoBridge.java:466)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at java.io.BufferedWriter.flush(BufferedWriter.java:124)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at org.jivesoftware.smack.util.ObservableWriter.flush(ObservableWriter.java:48)
01-21 08:00:00.294     557-1418/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketWriter.writePackets(PacketWriter.java:211)
01-21 08:00:00.302     557-1418/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketWriter.access$000(PacketWriter.java:40)
01-21 08:00:00.302     557-1418/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketWriter$1.run(PacketWriter.java:76)
01-21 08:00:00.302     557-1418/app_package_name D/SMACK﹕ 08:00:00 AM SENT (1119449544): </stream:stream>
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ XMPPError establishing connection with server.: remote-server-error(502) XMPPError establishing connection with server.
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ -- caused by: javax.net.ssl.SSLException: Connection closed by peer
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.XMPPConnection.initReaderAndWriter(XMPPConnection.java:699)
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:835)
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:262)
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:69)
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ Nested Exception:
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ javax.net.ssl.SSLException: Connection closed by peer
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:398)
01-21 08:00:00.419     557-1419/app_package_name W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:645)
01-21 08:00:00.427     557-1419/app_package_name W/System.err﹕ at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:616)
01-21 08:00:00.427     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.XMPPConnection.initReaderAndWriter(XMPPConnection.java:666)
01-21 08:00:00.427     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:835)
01-21 08:00:00.427     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:262)
01-21 08:00:00.427     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)
01-21 08:00:00.427     557-1419/app_package_name W/System.err﹕ at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:69)

共有1个答案

段干浩荡
2023-03-14

你的日志里有些奇怪的东西:

  1. 您正在使用端口5223,它通常是SSL
  2. 您的会话显示您正在尝试使用starttls

我本以为会是其中之一。

你试过使用端口5222吗?

 类似资料:
  • 我正在尝试使用hazelcast v3。2.4(服务器和客户端上的版本相同)。服务器(我可以安装的简单实现)正在服务器上运行。客户端尝试连接到远程服务器-服务器打印身份验证请求,但我收到以下日志输出(包括异常)-关于我可以做什么不同的想法(复制日志输出和配置文件)。我正在尝试通过TCP/IP进行连接,我检查了网络连接——我没有看到任何东西阻止连接。 堆栈中提到的代码行: 配置 日志输出 服务器输出

  • 问题内容: 尝试通过以下代码连接到 openfire 服务器时: 我得到一个异常说: 这可能是什么原因? 注意 :我已经允许openfire消防服务器通过防火墙。我也尝试过关闭防火墙,但是结果相同。服务器是我自己的机器。我尝试在其上运行程序的同一台计算机。 问题答案: 您可以使用 或者如果您想指定端口 或类似,默认为端口5222

  • 这就是第一台服务器的样子: 这是第二台服务器的样子: 第一台服务器运行良好,但当我试图运行第二台服务器时,我会得到follwing错误,这意味着到第一台服务器的连接失败。如果有人能帮助我,我会很高兴的!

  • 在我的应用程序中,我试图让python tornado服务器通过WebSockets与javascript html页面通信。我能够使用未加密的连接使连接工作,但当我试图在本文中实现解决方案时: 如何在网页环境中修改javascript代码,以便即使服务器使用自签名证书,也可以连接到服务器?

  • 初始化-iMac:桌面初始化$openssl s_client-connect gateway.sandbox.push.apple.com:2195-cert pushchatcert.pem-key pushchatkey.pem 终端响应: CONNECTED(00000003)深度=1/c=US/O=Entrust,INC./OU=www.Entrust.net/RPA是通过引用合并的/O

  • 我正在使用SunPKCS11连接到HSM设备。我有一些运行完美的单元测试(实际上他们会进行一些签名和验证),但是,当我将应用程序部署到tomcat或jetty时,我会得到这个异常(这个异常是在jetty中部署期间引发的,tomcat的异常是相似的): 下面是我如何实例化SunPKCS11的: 只是为了添加一些细节,我在windows server 2012上使用了64位java8。 更新1:我刚刚