powered by Jive Software

Asmack-android-8-4.0.2 Sasl-error

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)

SASLAuthentication.supportSASLMechanism(“PLAIN”, 0);
Why do you do that? It appears to disable the more secure mechanisms CRAM-MD5 and DIGEST-MD5!

SASLError using PLAIN: not-authorized
Not authorized, means the client is not authorized, e.g. because the password is wrong.

Thanks Flow. I found and fixed. It would be helpfull if you give me some links to documents for making a secure connection from an android device.

Hi Ramanathan. I meet the same question, I guarantee the password is correct. Could you tell me your solution? I had found that if I set the String variable in Android client, the problem cound be tackled. So I think the key question is how to get a safe input String from the EditText in Android phone.

Hi Ramanathan,I also am android developers to develop, smack the client, but I met a big problem: sometimes, RosterListener not work, for example: entriesDeleted (), can’t listen I delete a friend. Can you help me?