Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized #694

Closed
ThameemAK opened this issue Mar 30, 2017 · 4 comments

Comments

@ThameemAK
Copy link

ThameemAK commented Mar 30, 2017

Hi.. Am new to Chat Application.. For server am using openfire 3.10.2, i got the error like this

W/System.err: org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized
03-31 10:52:36.492 27403-10572/com.dating W/System.err: at org.jivesoftware.smack.SASLAuthentication.authenticationFailed(SASLAuthentication.java:365)
03-31 10:52:36.492 27403-10572/com.dating W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1044)
03-31 10:52:36.502 27403-10572/com.dating W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:948)
03-31 10:52:36.502 27403-10572/com.dating W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:963)
03-31 10:52:36.502 27403-10573/com.dating W/System.err: at org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized
03-31 10:52:36.502 27403-10572/com.dating W/System.err: java.lang.Thread.run(Thread.java:841)
03-31 10:52:36.502 27403-10573/com.dating W/System.err: at org.jivesoftware.smack.SASLAuthentication.authenticationFailed(SASLAuthentication.java:365)
03-31 10:52:36.502 27403-10573/com.dating W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1044)
03-31 10:52:36.502 27403-10573/com.dating W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:948)
03-31 10:52:36.502 27403-10573/com.dating W/System.err: at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:963)

private void createConnection(String fqdn, int port, boolean useSRVLookup) {
XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
if (useSRVLookup) {
builder.setServiceName(serverName);
} else {
builder.setHost(fqdn);
builder.setPort(port);
builder.setServiceName(serverName);
}

    onReady(builder);
}

private void onReady(XMPPTCPConnectionConfiguration.Builder builder) {
    builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    builder.setCompressionEnabled(compression);
    builder.setSendPresence(false);

    try {
        if (SettingsManager.securityCheckCertificate()) {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            MemorizingTrustManager mtm = new MemorizingTrustManager(Application.getInstance());
            sslContext.init(null, new X509TrustManager[]{mtm}, new java.security.SecureRandom());
            builder.setCustomSSLContext(sslContext);
            builder.setHostnameVerifier(
                    mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier()));
        } else {
            TLSUtils.acceptAllCertificates(builder);
            TLSUtils.disableHostnameVerificationForTlsCertificicates(builder);
        }
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        e.printStackTrace();
    }

  //  setUpSASL();
    final Map<String, String> registeredSASLMechanisms = SASLAuthentication.getRegisterdSASLMechanisms();
    for (String mechanism : registeredSASLMechanisms.values()) {
        SASLAuthentication.blacklistSASLMechanism(mechanism);
    }
    /*SASLAuthentication.blacklistSASLMechanism("DIGEST-MD5");*/
    SASLAuthentication.unBlacklistSASLMechanism(SASLPlainMechanism.NAME);

    xmppConnection = new XMPPTCPConnection(builder.build());
    xmppConnection.addAsyncStanzaListener(this, ACCEPT_ALL);
    xmppConnection.addConnectionListener(this);

    // by default Smack disconnects in case of parsing errors
    xmppConnection.setParsingExceptionCallback(new ExceptionLoggingCallback());

    AccountRosterListener rosterListener = new AccountRosterListener(((AccountItem)connectionItem).getAccount());
    final Roster roster = Roster.getInstanceFor(xmppConnection);
    roster.addRosterListener(rosterListener);
    roster.addRosterLoadedListener(rosterListener);
    roster.setSubscriptionMode(Roster.SubscriptionMode.manual);

    org.jivesoftware.smackx.ping.PingManager.getInstanceFor(xmppConnection).registerPingFailedListener(this);

    connectionItem.onSRVResolved(this);
    final String password = OAuthManager.getInstance().getPassword(protocol, token);
    if (password != null) {
        runOnConnectionThread(new Runnable() {
            @Override
            public void run() {
                connect(password);
            }
        });
    } else {
        runOnConnectionThread(new Runnable() {
            @Override
            public void run() {
                passwordRequest();
            }
        });
    }
}

xmppConnection.login(login, password, resource);

Anyone faced this issue?

@ThameemAK ThameemAK changed the title getAppKeyStore(/data/data/packageName/app_KeyStore/KeyStore.bks) - exception loading file key store org.jivesoftware.smack.sasl.SASLErrorException: SASLError using PLAIN: not-authorized Mar 31, 2017
@castilma
Copy link

@ThameemAK why did you close the issue? if you were able to resolve it, please post your solution. I have the problem with another server, too.

@ThameemAK
Copy link
Author

We set false to this boolean(security_check_certificate_default) in preference.xml.. After that It won't ask for certificate verification. If you want to use SASL in your application, we have to create SASL certification, There are different types in SASL mechanism.

@huilgolAni19
Copy link

@ThameemAK can you please tell how did you set false to this boolean(security_check_certificate_default) in preference.xml

@ThameemAK
Copy link
Author

ThameemAK commented Nov 7, 2019

@huilgolAni19 In preference.xml(https://github.com/redsolution/xabber-android/blob/33314e05d69eadf012bd91bd00dbca03961a8e67/xabber/src/main/res/values/preferences.xml). I downloaded the project and add as module in my Project and changed the flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants