differentiate starttls failure and sasl failure

This commit is contained in:
Daniel Gultsch 2017-05-13 08:08:05 +02:00
parent 91db2023d3
commit 5056a28553
2 changed files with 19 additions and 14 deletions

View File

@ -11,4 +11,6 @@ public final class Namespace {
public static final String MAM_LEGACY = "urn:xmpp:mam:0";
public static final String IDLE = "urn:xmpp:idle:1";
public static final String OOB = "jabber:x:oob";
public static final String SASL = "urn:ietf:params:xml:ns:xmpp-sasl";
public static final String TLS = "urn:ietf:params:xml:ns:xmpp-tls";
}

View File

@ -531,6 +531,7 @@ public class XmppConnection implements Runnable {
break;
} else if (nextTag.isStart("failure")) {
final Element failure = tagReader.readElement(nextTag);
if (Namespace.SASL.equals(failure.getNamespace())) {
final String text = failure.findChildContent("text");
if (failure.hasChild("account-disabled")
&& text != null
@ -541,11 +542,14 @@ public class XmppConnection implements Runnable {
} else {
throw new StateChangingException(Account.State.UNAUTHORIZED);
}
} else if (Namespace.TLS.equals(failure.getNamespace())) {
throw new StateChangingException(Account.State.TLS_ERROR);
} else {
throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER);
}
} else if (nextTag.isStart("challenge")) {
final String challenge = tagReader.readElement(nextTag).getContent();
final Element response = new Element("response");
response.setAttribute("xmlns",
"urn:ietf:params:xml:ns:xmpp-sasl");
final Element response = new Element("response",Namespace.SASL);
try {
response.setContent(saslMechanism.getResponse(challenge));
} catch (final SaslMechanism.AuthenticationException e) {
@ -781,7 +785,7 @@ public class XmppConnection implements Runnable {
private void sendStartTLS() throws IOException {
final Tag startTLS = Tag.empty("starttls");
startTLS.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-tls");
startTLS.setAttribute("xmlns", Namespace.TLS);
tagWriter.writeTag(startTLS);
}
@ -864,8 +868,7 @@ public class XmppConnection implements Runnable {
private void authenticate() throws IOException {
final List<String> mechanisms = extractMechanisms(streamFeatures
.findChild("mechanisms"));
final Element auth = new Element("auth");
auth.setAttribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl");
final Element auth = new Element("auth",Namespace.SASL);
if (mechanisms.contains("EXTERNAL") && account.getPrivateKeyAlias() != null) {
saslMechanism = new External(tagWriter, account, mXmppConnectionService.getRNG());
} else if (mechanisms.contains("SCRAM-SHA-256")) {