A
A
Alexander2018-07-20 21:45:52
Java
Alexander, 2018-07-20 21:45:52

Java XMPP client Smack 4.2.4 why is there a "bad-auth/" error?

Hello everyone, I'm a beginner and found the following jabber client code on the net:

package jabberIL;

    import java.io.IOException;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.lang.InterruptedException;
    import java.net.InetAddress;
    import javax.net.ssl.HostnameVerifier;
    import javax.net.ssl.SSLSession;
    import org.jivesoftware.smack.ConnectionConfiguration;
    import org.jxmpp.jid.DomainBareJid;
    import org.jxmpp.jid.EntityBareJid;
    import org.jxmpp.jid.impl.JidCreate;
    import org.jxmpp.stringprep.XmppStringprepException;
    import org.jivesoftware.smack.tcp.XMPPTCPConnection;
    import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
    import org.jivesoftware.smack.SmackException;
    import org.jivesoftware.smack.XMPPException;
    import org.jivesoftware.smack.AbstractXMPPConnection;
    import org.jivesoftware.smack.packet.Message;
    import org.jivesoftware.smack.chat2.ChatManager;
    import org.jivesoftware.smack.chat2.Chat;
    import org.jivesoftware.smack.chat2.IncomingChatMessageListener;

    public class JabberIL { 
        public static void main(String[] args) throws XmppStringprepException, SmackException, XMPPException, IOException, InterruptedException  {
            String msg;
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            InetAddress addr = InetAddress.getByName("ip_server"); 
            HostnameVerifier verifier = new HostnameVerifier() {
                    public boolean verify(String hostname, SSLSession session) {
                        return false;  // false 
                    }
            };

            DomainBareJid serviceName = JidCreate.domainBareFrom("name_server.ru"); 
            XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()                    
                        .setUsernameAndPassword("name","pass") 
                        .setPort(5222)
                        .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                        .setXmppDomain(serviceName)
                        .setHostnameVerifier(verifier)                        
                        .setHostAddress(addr)
                        .setDebuggerEnabled(true)   
                        .setSendPresence(true)
                        .build();
            AbstractXMPPConnection conn1 = new XMPPTCPConnection(config);       

            conn1.connect();
            if(conn1.isConnected()){
                System.out.println("XMPP Connected");
            }   

            conn1.login();          

            ChatManager chatManager = ChatManager.getInstanceFor(conn1);    
            chatManager.addIncomingListener(new IncomingChatMessageListener() {
                public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {                
                    System.out.println("Received message: " + message.getBody());
                }
            });
            Chat chat = chatManager.chatWith(JidCreate.entityBareFrom("[email protected]"));
            while (!(msg = br.readLine()).equals("bye")) {
                chat.send(msg);
            }           
            //conn1.disconnect(); 
        }
    }

It works for example when connecting to jabber.ru (connecting, receiving, sending messages). But when I try to connect to my jabber server on the local corporate network, I get this error, I attach the full stacktrace:
08:50:22 SENT (0): <stream:stream xmlns='jabber:client' to='server_name' xmlns:st
ream='http://etherx.jabber.org/streams' version='1.0' from='[email protected]_name' xml
:lang='en'>
08:50:22 RECV (0): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xml
ns:stream='http://etherx.jabber.org/streams' id='3533088839' from='server_name' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml
:ns:xmpp-tls'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>P
LAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>SCRAM-SHA-1</mechani
sm></mechanisms><register xmlns='http://jabber.org/features/iq-register'/></stre
am:features>
XMPP Connected
08:50:22 SENT (0): <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='SCR
AM-SHA-1'>biwsbj1qYm90LHI9U1d4bzZqXDt2dFlZdHhlajp7WmUrMWtwZihCcTZWJGM=</auth>
08:50:22 RECV (0): <challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1TV3hvN
mpcO3Z0WVl0eGVqOntaZSsxa3BmKEJxNlYkY2NaMVVuSjVwejBCZWtPZzREbGxxNWc9PSxzPWw3VnBOS
kk1MGMzZVBLdUl2U2FnY0E9PSxpPTQwOTY=</challenge>
08:50:22 SENT (0): <response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>Yz1iaXdzLH
I9U1d4bzZqXDt2dFlZdHhlajp7WmUrMWtwZihCcTZWJGNjWjFVbko1cHowQmVrT2c0RGxscTVnPT0scD
1TUWNNTGJORHB6NnFUVi84K2s3M09McFRRSTg9</response>
08:50:22 RECV (0): <failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><bad-auth/>
</failure>
ш■ы 19, 2018 8:50:22 AM org.jivesoftware.smack.sasl.SASLError fromString
WARNING: Could not transform string 'bad_auth' to SASLError
java.lang.IllegalArgumentException: No enum constant org.jivesoftware.smack.sasl
.SASLError.bad_auth
        at java.lang.Enum.valueOf(Enum.java:238)
        at org.jivesoftware.smack.sasl.SASLError.valueOf(SASLError.java:27)
        at org.jivesoftware.smack.sasl.SASLError.fromString(SASLError.java:51)
        at org.jivesoftware.smack.sasl.packet.SaslStreamElements$SASLFailure.<in
it>(SaslStreamElements.java:209)
        at org.jivesoftware.smack.util.PacketParserUtils.parseSASLFailure(Packet
ParserUtils.java:797)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePacket
s(XMPPTCPConnection.java:1099)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(
XMPPTCPConnection.java:1000)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPT
CPConnection.java:1016)
        at java.lang.Thread.run(Thread.java:748)

Exception in thread "main" org.jivesoftware.smack.sasl.SASLErrorException: SASLE
rror using SCRAM-SHA-1: bad-auth
        at org.jivesoftware.smack.SASLAuthentication.authenticationFailed(SASLAu
thentication.java:292)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePacket
s(XMPPTCPConnection.java:1100)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(
XMPPTCPConnection.java:1000)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPT
CPConnection.java:1016)
        at java.lang.Thread.run(Thread.java:748)

When I take, for example, the Wime client, it also connects to jabber.ru without problems, but when I connect to my local server with it, a warning about a self-signed certificate comes out with a question to accept or reject it. Is it possible that the problem of my falling client is just this? or not? I understand that the problem is most likely trifling, but I still have a bad understanding of processes)))
PS I found a piece of code on the network, which, as I understand it, makes me simply ignore what is there with the server's certificate. Although I'm not sure if it's true. This is inserted into my program (in pieces in the appropriate places):
import jabberIL.X509_Trust_Manager;
import javax.net.ssl.SSLContext;
import java.security.SecureRandom;
import javax.net.ssl.TrustManager;

SSLContext Cur_SSL_Context = null;
    try	{
      Cur_SSL_Context = SSLContext.getInstance("TLS");
      Cur_SSL_Context.init(null, new TrustManager[] { new X509_Trust_Manager() }, new SecureRandom());
    } catch (Exception e) {
      e.printStackTrace();
    }

                .setSocketFactory(Cur_SSL_Context.getSocketFactory())

And the implemented X509_Trust_Manager class itself
package jabberIL;

import javax.net.ssl.X509TrustManager;
import java.security.cert.X509Certificate;
import java.security.cert.CertificateException; 

public class X509_Trust_Manager implements X509TrustManager {
    
    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {		
  }
    
    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {		
  }
    
    public X509Certificate[] getAcceptedIssuers()  {
        return null;
    }
}

But in this case my program crashes with a timeout error:
Exception in thread "main" org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 5000ms (~5s). While waiting for establishing TLS

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question