Answer the question
In order to leave comments, you need to log in
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();
}
}
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)
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())
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;
}
}
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 questionAsk a Question
731 491 924 answers to any question