I am developing a im app in Android with Open Fire as my xmpp server. I am having trouble with logging into the server (SASLError using PLAIN: not-authorized) with Moto-G devices and not with all other devices. I am using **asmack-android-8-4.0.2.jar **library and following is my code for logging in.
ConnectionConfiguration conConFig;
XMPPConnection localConnection = null;
SmackConfiguration.DEBUG_ENABLED = true;
Roster.setDefaultSubscriptionMode(SubscriptionMode.accept_all);
SASLAuthentication.supportSASLMechanism(“PLAIN”, 0);
SmackAndroid.init(context);
conConFig = new ConnectionConfiguration(host,
port);
conConFig
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
conConFig.setCompressionEnabled(false);
//I think this wont make any effect since I set SecurityMode.disabled
conConFig.setCustomSSLContext(createContext());
localConnection = new XMPPTCPConnection(conConFig);
localConnection.connect();
localConnection.login(username, password);
public static SSLContext createContext() throws KeyStoreException,
NoSuchAlgorithmException, KeyManagementException {
KeyStore trustStore;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
trustStore = KeyStore.getInstance(“AndroidCAStore”);
} else {
trustStore = KeyStore.getInstance(“BKS”);
}
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(KeyManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
SSLContext sslContext = SSLContext.getInstance(“TLS”);
sslContext.init(null, trustManagerFactory.getTrustManagers(),
new SecureRandom());
return sslContext;
}
Foloowing is the error trace…
<stream:stream to=“server” xmlns=“jabber:client” xmlns:stream=“http://etherx.jabber.org/streams” version=“1.0”>
<?xml version='1.0' encoding='UTF-8'?>stream:featuresDIGEST-MD5PLAINANONYMOUSCRAM-MD5</mech anism>zlib</stream:features>
ACs5MTk1OTcxNjk2OTIAKzkxOTU5NzE2OTY5Mg ==
org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java: 342)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.login(XMPPTCPConnection.java:244)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:442)