0
votes

I'am using asmack-android-16 for my chat application. Sometimes, on creating connection, i got SSL exception and then i'am unable to login on server. My server is using SSL authentication for connections. Can someone please help me? I'am struggling with this from weeks

Here is my connection configuration :

    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 connection = new XMPPConnection(connectionConfiguration); connection.connect(); // Calling this line gives me exception, though connection is created.

Here are the logs :

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

1 Answers

0
votes

There is something strange in your logs:

  1. You are using port 5223, which is typically SSL
  2. Your session show that you are trying to use starttls.

I would have expected to be one or the other.

Did you try using port 5222?