gpt4 book ai didi

android - 连接到 openfire 服务器时出现 Samck 4.1 错误(org.jivesoftware.smack.sasl.SASLErrorException : SASLError using DIGEST-MD5: not-authorized)

转载 作者:搜寻专家 更新时间:2023-11-01 07:54:27 24 4
gpt4 key购买 nike

公共(public)无效连接(){ AsyncTask connectionThread = new AsyncTask(){ @覆盖 protected Boolean doInBackground(Void... arg0){ bool 值 isConnected = false;

            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword("ahsan", "vbase123");
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setResource("test");
configBuilder.setServiceName("192.168.10.106");
configBuilder.setHost("192.168.10.106");
configBuilder.setPort(5222);
configBuilder.setSendPresence(true);
configBuilder.setDebuggerEnabled(true);
//configBuilder.setSocketFactory(SSLSocketFactory.getDefault());
/* try {
TLSUtils.acceptAllCertificates(configBuilder);
} catch (NoSuchAlgorithmException e) {
} catch (KeyManagementException e) {
}

configBuilder.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});

*/

            connection = new XMPPTCPConnection(configBuilder.build());
// Connect to the server
try {Log.d("XAMPP","connected to server");
connection.connect();
Log.d("XAMPP","connected to server");
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
// Log into the server
try {
Log.d("XAMPP","Login to server");
connection.login();
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
setConnection(connection);
Roster roster = Roster.getInstanceFor(connection);
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {

Log.d("XMPPChatDemoActivity", "--------------------------------------");
Log.d("XMPPChatDemoActivity", "RosterEntry " + entry);
Log.d("XMPPChatDemoActivity", "User: " + entry.getUser());
Log.d("XMPPChatDemoActivity", "Name: " + entry.getName());
Log.d("XMPPChatDemoActivity", "Status: " + entry.getStatus());
Log.d("XMPPChatDemoActivity", "Type: " + entry.getType());
Presence entryPresence = roster.getPresence(entry.getUser());

Log.d("XMPPChatDemoActivity", "Presence Status: "+ entryPresence.getStatus());
Log.d("XMPPChatDemoActivity", "Presence Type: " + entryPresence.getType());

Presence.Type type = entryPresence.getType();
if (type == Presence.Type.available)
Log.d("XMPPChatDemoActivity", "Presence AVIALABLE");
Log.d("XMPPChatDemoActivity", "Presence : " + entryPresence);
}
Log.d("XAMPP", "login to server");
} catch (XMPPException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

// Disconnect from the server
// connection.disconnect();

return isConnected;
}
};
connectionThread.execute();
}

此代码的错误堆栈跟踪如下:

5-08 18:24:04.162    1305-1493/com.vb.testapp D/XAMPP﹕ connected to server
05-08 18:24:04.185 1305-1502/com.vb.testapp D/SMACK﹕ SENT (0): <stream:stream xmlns='jabber:client' to='192.168.10.106' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='ahsan@virtualbase@192.168.10.106' xml:lang='en'>
05-08 18:24:04.189 1305-1503/com.vb.testapp D/SMACK﹕ RECV (0): <?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="virtualbase" id="da5ea5f2" xml:lang="en" version="1.0">
05-08 18:24:04.194 1305-1503/com.vb.testapp D/SMACK﹕ RECV (0): <stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
05-08 18:24:04.196 1305-1493/com.vb.testapp D/XAMPP﹕ connected to server
05-08 18:24:04.196 1305-1493/com.vb.testapp D/XAMPP﹕ Login to server
05-08 18:24:04.198 1305-1502/com.vb.testapp D/SMACK﹕ SENT (0): <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='DIGEST-MD5'>=</auth>
05-08 18:24:04.204 1305-1503/com.vb.testapp D/SMACK﹕ RECV (0): <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09InZpcnR1YWxiYXNlIixub25jZT0icEZvL1NsYkV3Rms3cTBRNUlpNTlEc2I5RFJMM2FRQ2NuNmF4VVdBOSIscW9wPSJhdXRoIixjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw==</challenge>
05-08 18:24:04.206 1305-1502/com.vb.testapp D/SMACK﹕ SENT (0): <response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dXNlcm5hbWU9ImFoc2FuQHZpcnR1YWxiYXNlIixyZWFsbT0iMTkyLjE2OC4xMC4xMDYiLG5vbmNlPSJwRm8vU2xiRXdGazdxMFE1SWk1OURzYjlEUkwzYVFDY242YXhVV0E5Iixjbm9uY2U9IjBWT1lBRFE4U09ZNDJDVUcxWldCSG9JMTRJbjFYdzdtIixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwLzE5Mi4xNjguMTAuMTA2IixyZXNwb25zZT0xNDkxNmJjMDFhODI3MGVmNjA4ODViZTNmNmQ1NzA2MixjaGFyc2V0PXV0Zi04</response>
05-08 18:24:04.209 1305-1503/com.vb.testapp D/SMACK﹕ RECV (0): <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
05-08 18:24:04.212 1305-1493/com.vb.testapp W/System.err﹕ org.jivesoftware.smack.sasl.SASLErrorException: SASLError using DIGEST-MD5: not-authorized
05-08 18:24:04.212 1305-1493/com.vb.testapp W/System.err﹕ at org.jivesoftware.smack.SASLAuthentication.authenticationFailed(SASLAuthentication.java:365)
05-08 18:24:04.212 1305-1493/com.vb.testapp W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1011)
05-08 18:24:04.212 1305-1493/com.vb.testapp W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:915)
05-08 18:24:04.212 1305-1493/com.vb.testapp W/System.err﹕ at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:930)
05-08 18:24:04.212 1305-1493/com.vb.testapp W/System.err﹕ at java.lang.Thread.run(Thread.java:818)

最佳答案

尝试在配置连接时添加这些行

configBuilder.setSecurityMode(XMPPTCPConnectionConfiguration.SecurityMode.required );
SASLMechanism mechanism = new SASLDigestMD5Mechanism();
SASLAuthentication.registerSASLMechanism(mechanism);
SASLAuthentication.blacklistSASLMechanism("SCRAM-SHA-1");
SASLAuthentication.unBlacklistSASLMechanism("DIGEST-MD5");

关于android - 连接到 openfire 服务器时出现 Samck 4.1 错误(org.jivesoftware.smack.sasl.SASLErrorException : SASLError using DIGEST-MD5: not-authorized),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30125363/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com