【问题标题】:Android exception SASL authentication failed using mechanism DIGEST-MD5Android异常SASL身份验证失败使用机制DIGEST-MD5
【发布时间】:2014-07-18 12:39:47
【问题描述】:

我正在使用以下代码进行 xmpp 连接,但使用机制 DIGEST-MD5 出现异常 SASL 身份验证失败

 public static boolean XMPPConnect() {
            try {
                System.setProperty("java.net.preferIPv6Addresses", "false");
config = new ConnectionConfiguration(Constant._hostName);
                config.setRosterLoadedAtLogin(true);
                config.setSendPresence(true);
                config.setSASLAuthenticationEnabled(true);
                config.setCompressionEnabled(true);
                config.setSecurityMode(SecurityMode.enabled);


                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    config.setTruststoreType("AndroidCAStore");
                    config.setTruststorePassword(null);
                    config.setTruststorePath(null);
                } else {
                    config.setTruststoreType("BKS");
                    String path = System.getProperty("javax.net.ssl.trustStore");
                    if (path == null)
                        path = System.getProperty("java.home") + File.separator + "etc"
                                + File.separator + "security" + File.separator
                                + "cacerts.bks";
                    config.setTruststorePath(path);
                }

                connection = new XMPPConnection(config);
                connection.connect();
                debugEnabledReset();


            } catch (Exception e) {
                XMPPConstants.XMPP_ERROR="socket_timeout";
                e.printStackTrace();
                if(connection.DEBUG_ENABLED==true)
                    connection.DEBUG_ENABLED = false;
                return false;
            }
            return true;
        }

用于登录

public static boolean XMPPLogin(String uname, String password) {
        Roster roster = connection.getRoster();
        roster.addRosterListener(new RosterListener() {
            public void presenceChanged(Presence arg0) {}
            public void entriesUpdated(Collection<String> arg0) {}
            public void entriesDeleted(Collection<String> arg0) {}
            public void entriesAdded(Collection<String> arg0) {}
        });

        try {


            //SASLAuthentication.supportSASLMechanism("PLAIN", 0);
            connection.login(uname, password);
        } catch (Exception e) {
            XMPPConstants.XMPP_ERROR="Username or password is incorrect";
            if(e.getMessage().toString().contains("No response")){
                XMPPConstants.XMPP_ERROR="Server communication failed";
            }
            e.printStackTrace();

            return false;
        }
        return true;
    }

请帮帮我..我已经尝试了很多东西,但注意到工作正常。 提前致谢

【问题讨论】:

标签: android xmpp sasl


【解决方案1】:

如果您仍然没有找到合适的解决方案,请使用 tr 禁用 SASL 身份验证。

config.setSASLAuthenticationEnabled(false);

这可能会奏效一段时间,但仍然不是永久的解决方案。

【讨论】:

    【解决方案2】:
    // I was same problem and i have solved by following way.
    
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
            configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
            configBuilder.setServiceName(Constant.SERVICE_NAME);
            configBuilder.setHost(Constant.HOST);
            configBuilder.setPort(5222);
            configBuilder.setConnectTimeout(10000);
            configBuilder.setSendPresence(true);
    
    AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
            connection.setPacketReplyTimeout(10000);
    
    // If the above code is not working than change AbstractXMPPConnection to XMPPTCPConnection and than try i have solved using this way
    

    【讨论】:

      猜你喜欢
      • 2013-03-26
      • 1970-01-01
      • 2012-07-11
      • 1970-01-01
      • 2016-08-20
      • 1970-01-01
      • 2013-03-09
      • 2012-10-12
      • 1970-01-01
      相关资源
      最近更新 更多