0
votes

Working on a live chat app on Android using XMPP framework / OpenFire and just transferred to a new cloud server but I’m having some problems with the old Android Users Connecting. New users can log in fine and connect to the OpenFire Server.

With the old user accounts it fails the connection the 1st time, but then the 2nd time it connects. Anyone knows what the issue could be?

Can't figure out what the issue is.

2
"it fails the connection the 1st time, but then the 2nd time it connects" Can you provide the exception you get on client side when 1st time connection fails?Shoaib Ahmad Gondal

2 Answers

1
votes

hi if your trying to connect xmpp with openfire then just give ssl permission to XMPPTCPConnectionConfiguration with smack library,

 private XMPPTCPConnectionConfiguration buildConfiguration() throws XmppStringprepException {
    XMPPTCPConnectionConfiguration.Builder builder =
            XMPPTCPConnectionConfiguration.builder();

    builder.setHost(Common.HOST);
    builder.setPort(PORT);
    builder.setCompressionEnabled(false);
    builder.setDebuggerEnabled(true);
    builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    builder.setSendPresence(true);

    if (Build.VERSION.SDK_INT >= 14) {
        builder.setKeystoreType("AndroidCAStore");
        builder.setKeystorePath(null);
    } else {
        builder.setKeystoreType("BKS");
        String str = System.getProperty("javax.net.ssl.trustStore");
        if (str == null) {
            str = System.getProperty("java.home") + File.separator + "etc" + File.separator + "security"
                    + File.separator + "cacerts.bks";
        }
        builder.setKeystorePath(str);
    }
    DomainBareJid serviceName = JidCreate.domainBareFrom(Common.HOST);
    builder.setServiceName(serviceName);


    return builder.build();
}

and call this when you are connecting with server here is example see

XMPPTCPConnectionConfiguration config = buildConfiguration();
            SmackConfiguration.DEBUG = true;
            this.connection = new XMPPTCPConnection(config);
            this.connection.connect();

for more details visit this example

thanks hope this will help you to solve your problem (Y).

0
votes

To connect to openfire ( any xmpp server ) from android device using SSL follow this with Smack

// Set key for SSL connection
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    config.setKeystoreType("AndroidCAStore");
    config.setKeystorekeyPath(null);
} else {
    config.setKeystoreType("BKS");
    String keyPath = System.getProperty("javax.net.ssl.trustStore");
    if (keyPath == null)
        keyPath = System.getProperty("java.home") + File.separator + "etc"
                + File.separator + "security" + File.separator + "certs.bks";
        config.setKeystorekeyPath(keyPath);
    }
}

// Now set custom SSL to configuration
try {
    SSLContext ssl = SSLContext.getInstance("TLS");
    ssl.init(null, new TrustManager[]{new TLSUtils.AcceptAllTrustManager()}, null);
    ssl.getServerSessionContext().setSessionTimeout(10 * 1000);
    config.setCustomSSLContext(ssl);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
} catch (KeyManagementException e) {
    e.printStackTrace();
}

config.setSecurityMode(Connectionconfig.SecurityMode.required);
// config is type of XMPPTCPConnectionConfiguration