Stugal
Stugal

Reputation: 880

SSL error while connecting to Openfire from java-smack client

I am recently working on Openfire client. I've got this strange issue that I couldn't figure out so far (i've got some clues, but still no solid solution). We've got 2 openfire servers:

Now when connecting to production from our client we experianced following issue when trying to authenticate:

javax.net.ssl.SSLException: Received fatal alert: internal_error at sun.security.ssl.Alerts.getSSLException(Unknown Source) at sun.security.ssl.Alerts.getSSLException(Unknown Source) at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source) at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source) at org.jivesoftware.smack.XMPPConnection.proceedTLSReceived(XMPPConnection.java:806) at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:267) at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43) at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70) java.lang.IllegalStateException: Not connected to server. at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:445) at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:69) at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:352) at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203) at Main.connectToJabber(Main.java:31) at Main.main(Main.java:16) Exception in thread "main" java.lang.IllegalStateException: Not connected to server. at org.jivesoftware.smack.XMPPConnection.sendPacket(XMPPConnection.java:445) at org.jivesoftware.smack.NonSASLAuthentication.authenticate(NonSASLAuthentication.java:69) at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:362) at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:203) at Main.connectToJabber(Main.java:31) at Main.main(Main.java:16)

Now the funniest part: when I connect to the production server using our client from my flat i don't see that error, when we are connecting to the production from other developer flat we've got this error, we've got different internet providers (i don't know if that may have something to do with that). We've spent all night looking at it and so far no clue. We wrote basic code just to check the connection:

public static void connect() {
    ConnectionConfiguration cc = new ConnectionConfiguration("prod ip",
            5222);
    cc.setCompressionEnabled(true);
    cc.setSASLAuthenticationEnabled(true);
    Connection connection = new XMPPConnection(cc);
    try {
        connection.connect();
        connection.login(login, pass, "resource");
        System.out.println(connection.isSecureConnection() +  " " + connection.isUsingCompression());

    } catch (XMPPException e1) {
        e1.getStackTrace();
    }
}

Some observations:

Connection with testing environment works always, with production: from my location - no problem, other location - mentioned error, we use SMACK API 3.2.1

One of the ideas was that it has to do something with the certificates.

Any hints or ideas highly appriciated

Upvotes: 2

Views: 4398

Answers (3)

Vic
Vic

Reputation: 53

I also use a sleep after connect() also... it's not ideal sure, but it's a reliable workaround.

Upvotes: 0

Sadegh
Sadegh

Reputation: 2669

Bad bad solution! because u don't know connection speed and also u stop your app from continuing to login if connection established at early moments. A solution that I can offer for now is to addConnectionListener and call login() in 'reconnectionSuccessful()' function, and I hope this function will call for the first time not just after connection dropped and connected again! if not, It shows the bad architecture of smack library.

Upvotes: 2

Flow
Flow

Reputation: 24043

Maybe a sleep(x) between the connect() and the login() call could fix this. A few seconds for the sleep() should be enough. Source

Upvotes: 1

Related Questions