powered by Jive Software

aSmack 4.1: SASL Authentication failed. No known authentication mechanisims

I do not understand how to connect to my ejabberd server using aSmack 4.1 alpha. Every thing I try results in SASL errors. It appears that SASLAuthentication doesn’t have any registered SASLMechanisms which doesn’t make sense to me. The read me suggest calling SmackAndroid.init(context), but there is no such class in aSmack 4.1. I have the following jars included in my Android project:

android-support-v4.jar

jxmpp-core-0.4.0.jar

jxmpp-util-cache-0.4.0.jar

smack-android-4.1.0-alpha1.jar

smack-core-4.1.0-alpha1.jar

smack-tcp-4.1.0-alpha1.jar

The following is a simplified example of the code I am running.

String userName = “bob@localhost”;

String password = “password”;

config.setSecurityMode(SecurityMode.enabled);

config.setCompressionEnabled(true);

config.setDebuggerEnabled(true);

config.setSendPresence(true);

config.setReconnectionAllowed(true);

TrustManager[] trustAllCerts = new TrustManager[] {

new X509TrustManager() {

public java.security.cert.X509Certificate[] getAcceptedIssuers() {

return new X509Certificate[0];

}

public void checkClientTrusted(

X509Certificate[] certs,

String authType) {

}

public void checkServerTrusted(

X509Certificate[] certs,

String authType) {

}

}

};

HostnameVerifier verifier = new HostnameVerifier() {

@Override

public boolean verify(String hostname, SSLSession session) {

if (BuildConfig.DEBUG) {

Log.d(ChatTranslator.APPLICATION_NAME, "Hostname: " + hostname);

}

return true;

}

};

try {

SSLContext context= SSLContext.getInstance(“SSL”);

context.init(null, trustAllCerts, new java.security.SecureRandom());

config.setCustomSSLContext(context);

config.setHostnameVerifier(verifier);

} catch (Exception e) {

if (BuildConfig.DEBUG) {

Log.e(ChatTranslator.APPLICATION_NAME, “Dummy SSL”, e);

}

}

AbstractXMPPConnection connection = new XMPPTCPConnection(config);

if (!connection.isConnected()) {

try {

this.connection.connect();

} catch (IOException e) {

throw new NetworkFault(e);

} catch (Exception e) {

throw new ConfigurationFault(e);

}

try {

connection.login(userName, password);

} catch (IOException e) {

throw new NetworkFault(e);

} catch (Exception e) {

throw new AuthenticationFault(e);

}

Roster roster = connection.getRoster();

}

I have tried to register my own SASLMechanisms but I must not have the implementation correct because those throw errors too.

How do I get aSmack 4.1 to authenticate? How do I register the necessary SASLMechanisms? Does 4.1 alpha not support SASL yet?

If you look at Smack 4.1 Readme and Upgrade Guide · igniterealtime/Smack Wiki · GitHub you will find that you did not include all required artifacts. I also don’t recommend adding the artifacts manually. You should really use a build system that is able to fetch the artifacts from maven central an do proper dependency resolution.

I am very familiar with Java and Eclipse, I don’t know how to use Maven. This is my first Android application. Also, when I read that page I saw:

Minimal Smack configuration for XMPP over TCP

dependencies {

compile “org.igniterealtime.smack:smack-android:4.1.0-alpha5”

compile “org.igniterealtime.smack:smack-tcp:4.1.0-alpha5”

}

When I look for an Android Maven tutorial online it suggest that I use Eclipse marketplace but I don’t see any such thing. I’m running Eclipse on Ubuntu. I remember adding software sites to get plugins in the past, this Marketplace thing is new to me.

Anyway, I did just notice the list of jars in the Ant solution. So maybe your answer will lead me to a solution even if I don’t figure out this Maven thing.

Thank you.

Ok, I installed Gradle in eclipse, deleted my jars from my lib folder, and added the following gradle file:

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath ‘com.android.tools.build:gradle:0.13.+’

}

}

apply plugin: ‘android’

android {

compileSdkVersion 19

buildToolsVersion “19.0.0”

defaultConfig {

minSdkVersion 14

targetSdkVersion 21

}

sourceSets {

main {

manifest.srcFile ‘AndroidManifest.xml’

java.srcDirs = [‘src’]

}

}

}

repositories {

maven {

url ‘https://oss.sonatype.org/content/repositories/snapshots

}

mavenCentral()

}

dependencies {

compile “org.igniterealtime.smack:smack-android:4.1.0-alpha5”

compile “org.igniterealtime.smack:smack-tcp:4.1.0-alpha5”

}

Unfortunately I can no longer include any of the aSmack 4.1 classes now.

So it turns out that Android ADT isn’t compatible with Gradle? I don’t get how that makes any sense, so I had to change my Gradle set up to copy the jars to a folder so that I can manually add them to the class path.

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath ‘com.android.tools.build:gradle:0.13.+’

}

}

apply plugin : ‘eclipse’

apply plugin: ‘android’

android {

compileSdkVersion 19

buildToolsVersion “19.0.0”

defaultConfig {

minSdkVersion 14

targetSdkVersion 21

}

sourceSets {

main {

manifest.srcFile ‘AndroidManifest.xml’

java.srcDirs = [‘src’]

resources.srcDirs = [‘src’]

aidl.srcDirs = [‘src’]

renderscript.srcDirs = [‘src’]

res.srcDirs = [‘res’]

assets.srcDirs = [‘assets’]

}

androidTest.setRoot(‘tests’)

}

dependencies {

compile fileTree(dir: ‘libs’, include: ‘*.jar’)

}

}

sourceSets {

main {

java {

srcDirs = [“src”,“gen”]

}

}

}

repositories {

maven {

url ‘https://oss.sonatype.org/content/repositories/snapshots

}

mavenCentral()

}

dependencies {

compile fileTree(dir: “libs”, include: ‘*.jar’)

compile “org.igniterealtime.smack:smack-android:4.1.0-alpha5”

compile “org.igniterealtime.smack:smack-tcp:4.1.0-alpha5”

compile “com.android.support:support-v4:13.0.0”

}

task copyToLibs(type: Copy) {

into “libs”

from configurations.runtime

}

build.dependsOn(copyToLibs)

And manually run gradle copyToLibs outside of Eclipse since the Gradle plugin doesn’t like Android.

Unfortunately now I’m getting this

Dx

trouble processing “javax/xml/namespace/QName.class”:

Ill-advised or mistaken usage of a core class (java.* or javax.*)

when not building a core library.

This is often due to inadvertently including a core library file

in your application’s project, when using an IDE (such as

Eclipse). If you are sure you’re not intentionally defining a

core class, then this is the most likely explanation of what’s

going on.

However, you might actually be trying to define a class in a core

namespace, the source of which you may have taken, for example,

from a non-Android virtual machine project. This will most

assuredly not work. At a minimum, it jeopardizes the

compatibility of your app with future versions of the platform.

It is also often of questionable legality.

If you really intend to build a core library – which is only

appropriate as part of creating a full virtual machine

distribution, as opposed to compiling an application – then use

the “–core-library” option to suppress this error message.

If you go ahead and use “–core-library” but are in fact

building an application, then be forewarned that your application

will still fail to build or run, at some point. Please be

prepared for angry customers who find, for example, that your

application ceases to function once they upgrade their operating

system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a

core package, then the easiest safe alternative you have is to

repackage that code. That is, move the classes in question into

your own package namespace. This means that they will never be in

conflict with core system classes. JarJar is a tool that may help

you in this endeavor. If you find that you cannot do this, then

that is an indication that the path you are on will ultimately

lead to pain, suffering, grief, and lamentation.

[2014-11-07 09:44:44 - MyApp] Dx 1 error; aborting

[2014-11-07 09:44:44 - MyApp] Conversion to Dalvik format failed with error 1

Although that might be from having to delete and reimport my project twice. First to make it a Gradle project so that I can use Gradle, and then to make it an Android project again so I can use Android. My .classpath file looks like this now:

<?xml version="1.0" encoding="UTF-8"?>

My app ran successfully once but threw a NoClassDef error on org.jivesoftware.smack.ConnectionConfiguration, so I changed everything to exported true and now I am back it not running with the previously listed “Dalvik format failed with error 1” error.

I think I’m going to be bald by the end of this… :frowning:

Ok, I finally broke down and stopped using Eclipse Android, I am now using the Intellij based Android Studio with integrated Gradle support. I should have all of the requirements now, but I am still getting authentication errors:

org.jivesoftware.smack.sasl.SASLErrorException: SASLError using SCRAM-SHA-1: not-authorized

at com.iasoftware.chattranslator.xmpp.XMPPChatService.connect(XMPPChatService.java :481)

at com.iasoftware.chattranslator.android.base.AndroidBackgroundChatService.onHandl eIntent(AndroidBackgroundChatService.java:476)

at com.iasoftware.chattranslator.android.base.AndroidBackgroundChatService$Service Handler.handleMessage(AndroidBackgroundChatService.java:416)

at android.os.Handler.dispatchMessage(Handler.java:102)

at android.os.Looper.loop(Looper.java:136)

at android.os.HandlerThread.run(HandlerThread.java:61)

I used the same login credentials that I did in Pidgin and it doesn’t work.