disable quick start if fast is available but we didn’t use fast

This commit is contained in:
Daniel Gultsch 2022-11-01 18:06:32 +01:00
parent 7e29d1d862
commit dac2e17133

View file

@ -802,7 +802,7 @@ public class XmppConnection implements Runnable {
} }
final HashedToken.Mechanism tokenMechanism; final HashedToken.Mechanism tokenMechanism;
final SaslMechanism currentMechanism = this.saslMechanism; final SaslMechanism currentMechanism = this.saslMechanism;
if (currentMechanism instanceof HashedToken) { if (SaslMechanism.hashedToken(currentMechanism)) {
tokenMechanism = ((HashedToken) currentMechanism).getTokenMechanism(); tokenMechanism = ((HashedToken) currentMechanism).getTokenMechanism();
} else if (this.hashTokenRequest != null) { } else if (this.hashTokenRequest != null) {
tokenMechanism = this.hashTokenRequest; tokenMechanism = this.hashTokenRequest;
@ -840,7 +840,7 @@ public class XmppConnection implements Runnable {
} }
Log.d(Config.LOGTAG,failure.toString()); Log.d(Config.LOGTAG,failure.toString());
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": login failure " + version); Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": login failure " + version);
if (this.saslMechanism instanceof HashedToken) { if (SaslMechanism.hashedToken(this.saslMechanism)) {
Log.d(Config.LOGTAG,account.getJid().asBareJid() + ": resetting token"); Log.d(Config.LOGTAG,account.getJid().asBareJid() + ": resetting token");
account.resetFastToken(); account.resetFastToken();
mXmppConnectionService.databaseBackend.updateAccount(account); mXmppConnectionService.databaseBackend.updateAccount(account);
@ -1250,12 +1250,26 @@ public class XmppConnection implements Runnable {
account.getJid().asBareJid() account.getJid().asBareJid()
+ ": quick start in progress. ignoring features: " + ": quick start in progress. ignoring features: "
+ XmlHelper.printElementNames(this.streamFeatures)); + XmlHelper.printElementNames(this.streamFeatures));
//TODO check if 'fast' is available but we are doing something else if (SaslMechanism.hashedToken(this.saslMechanism)) {
return; return;
} }
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": server lost support for SASL 2. quick start not possible"); if (isFastTokenAvailable(
this.streamFeatures.findChild("authentication", Namespace.SASL_2))) {
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": fast token available; resetting quick start");
account.setOption(Account.OPTION_QUICKSTART_AVAILABLE, false);
mXmppConnectionService.databaseBackend.updateAccount(account);
}
return;
}
Log.d(
Config.LOGTAG,
account.getJid().asBareJid()
+ ": server lost support for SASL 2. quick start not possible");
this.account.setOption(Account.OPTION_QUICKSTART_AVAILABLE, false); this.account.setOption(Account.OPTION_QUICKSTART_AVAILABLE, false);
mXmppConnectionService.updateAccount(account); mXmppConnectionService.databaseBackend.updateAccount(account);
throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER); throw new StateChangingException(Account.State.INCOMPATIBLE_SERVER);
} }
if (this.streamFeatures.hasChild("starttls", Namespace.TLS) if (this.streamFeatures.hasChild("starttls", Namespace.TLS)
@ -1377,7 +1391,7 @@ public class XmppConnection implements Runnable {
} }
if (account.setOption(Account.OPTION_QUICKSTART_AVAILABLE, quickStartAvailable)) { if (account.setOption(Account.OPTION_QUICKSTART_AVAILABLE, quickStartAvailable)) {
mXmppConnectionService.updateAccount(account); mXmppConnectionService.databaseBackend.updateAccount(account);
} }
Log.d( Log.d(
@ -1391,6 +1405,11 @@ public class XmppConnection implements Runnable {
tagWriter.writeElement(authenticate); tagWriter.writeElement(authenticate);
} }
private static boolean isFastTokenAvailable(final Element authentication) {
final Element inline = authentication == null ? null : authentication.findChild("inline");
return inline != null && inline.hasChild("fast", Namespace.FAST);
}
@NonNull @NonNull
private SaslMechanism validate(final @Nullable SaslMechanism saslMechanism, Collection<String> mechanisms) throws StateChangingException { private SaslMechanism validate(final @Nullable SaslMechanism saslMechanism, Collection<String> mechanisms) throws StateChangingException {
if (saslMechanism == null) { if (saslMechanism == null) {