get rid of payment required account state
This commit is contained in:
parent
7d34c894d0
commit
b5a47000c9
|
@ -1,15 +1,10 @@
|
||||||
package im.conversations.android;
|
package im.conversations.android;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.google.android.material.color.DynamicColors;
|
import com.google.android.material.color.DynamicColors;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
|
||||||
import im.conversations.android.xmpp.ConnectionPool;
|
import im.conversations.android.xmpp.ConnectionPool;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
|
||||||
import org.conscrypt.Conscrypt;
|
import org.conscrypt.Conscrypt;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
24
src/main/java/im/conversations/android/xmpp/Closables.java
Normal file
24
src/main/java/im/conversations/android/xmpp/Closables.java
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package im.conversations.android.xmpp;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public final class Closables {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Closables.class);
|
||||||
|
|
||||||
|
private Closables() {}
|
||||||
|
|
||||||
|
public static void close(final Closeable closeable) {
|
||||||
|
if (closeable == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
closeable.close();
|
||||||
|
} catch (final IOException e) {
|
||||||
|
LOGGER.warn("Could not close closable", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,11 +21,9 @@ import com.google.common.util.concurrent.SettableFuture;
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.crypto.XmppDomainVerifier;
|
import eu.siacs.conversations.crypto.XmppDomainVerifier;
|
||||||
import eu.siacs.conversations.persistance.FileBackend;
|
|
||||||
import eu.siacs.conversations.services.MemorizingTrustManager;
|
import eu.siacs.conversations.services.MemorizingTrustManager;
|
||||||
import eu.siacs.conversations.services.NotificationService;
|
import eu.siacs.conversations.services.NotificationService;
|
||||||
import eu.siacs.conversations.ui.util.PendingItem;
|
import eu.siacs.conversations.ui.util.PendingItem;
|
||||||
import eu.siacs.conversations.utils.Patterns;
|
|
||||||
import eu.siacs.conversations.utils.PhoneHelper;
|
import eu.siacs.conversations.utils.PhoneHelper;
|
||||||
import eu.siacs.conversations.utils.Resolver;
|
import eu.siacs.conversations.utils.Resolver;
|
||||||
import eu.siacs.conversations.utils.SocksSocketFactory;
|
import eu.siacs.conversations.utils.SocksSocketFactory;
|
||||||
|
@ -96,7 +94,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import javax.net.ssl.KeyManager;
|
import javax.net.ssl.KeyManager;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||||
|
@ -422,7 +419,7 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
break; // successfully connected to server that speaks xmpp
|
break; // successfully connected to server that speaks xmpp
|
||||||
} else {
|
} else {
|
||||||
FileBackend.close(localSocket);
|
Closables.close(localSocket);
|
||||||
throw new StateChangingException(ConnectionState.STREAM_OPENING_ERROR);
|
throw new StateChangingException(ConnectionState.STREAM_OPENING_ERROR);
|
||||||
}
|
}
|
||||||
} catch (final StateChangingException e) {
|
} catch (final StateChangingException e) {
|
||||||
|
@ -895,24 +892,6 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
if (failure.hasChild("temporary-auth-failure")) {
|
if (failure.hasChild("temporary-auth-failure")) {
|
||||||
throw new StateChangingException(ConnectionState.TEMPORARY_AUTH_FAILURE);
|
throw new StateChangingException(ConnectionState.TEMPORARY_AUTH_FAILURE);
|
||||||
} else if (failure.hasChild("account-disabled")) {
|
|
||||||
final String text = failure.findChildContent("text");
|
|
||||||
if (Strings.isNullOrEmpty(text)) {
|
|
||||||
throw new StateChangingException(ConnectionState.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
final Matcher matcher = Patterns.AUTOLINK_WEB_URL.matcher(text);
|
|
||||||
if (matcher.find()) {
|
|
||||||
final HttpUrl url;
|
|
||||||
try {
|
|
||||||
url = HttpUrl.get(text.substring(matcher.start(), matcher.end()));
|
|
||||||
} catch (final IllegalArgumentException e) {
|
|
||||||
throw new StateChangingException(ConnectionState.UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
if (url.isHttps()) {
|
|
||||||
this.redirectionUrl = url;
|
|
||||||
throw new StateChangingException(ConnectionState.PAYMENT_REQUIRED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (SaslMechanism.hashedToken(this.saslMechanism)) {
|
if (SaslMechanism.hashedToken(this.saslMechanism)) {
|
||||||
Log.d(
|
Log.d(
|
||||||
|
@ -1193,11 +1172,11 @@ public class XmppConnection implements Runnable {
|
||||||
Log.d(
|
Log.d(
|
||||||
Config.LOGTAG,
|
Config.LOGTAG,
|
||||||
account.address + ": TLS certificate domain verification failed");
|
account.address + ": TLS certificate domain verification failed");
|
||||||
FileBackend.close(sslSocket);
|
Closables.close(sslSocket);
|
||||||
throw new StateChangingException(ConnectionState.TLS_ERROR_DOMAIN);
|
throw new StateChangingException(ConnectionState.TLS_ERROR_DOMAIN);
|
||||||
}
|
}
|
||||||
} catch (final SSLPeerUnverifiedException e) {
|
} catch (final SSLPeerUnverifiedException e) {
|
||||||
FileBackend.close(sslSocket);
|
Closables.close(sslSocket);
|
||||||
throw new StateChangingException(ConnectionState.TLS_ERROR);
|
throw new StateChangingException(ConnectionState.TLS_ERROR);
|
||||||
}
|
}
|
||||||
return sslSocket;
|
return sslSocket;
|
||||||
|
@ -1978,8 +1957,8 @@ public class XmppConnection implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forceCloseSocket() {
|
private void forceCloseSocket() {
|
||||||
FileBackend.close(this.socket);
|
Closables.close(this.socket);
|
||||||
FileBackend.close(this.tagReader);
|
Closables.close(this.tagReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void interrupt() {
|
public void interrupt() {
|
||||||
|
@ -2025,7 +2004,7 @@ public class XmppConnection implements Runnable {
|
||||||
+ e.getMessage()
|
+ e.getMessage()
|
||||||
+ ")");
|
+ ")");
|
||||||
} finally {
|
} finally {
|
||||||
FileBackend.close(currentSocket);
|
Closables.close(currentSocket);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
forceCloseSocket();
|
forceCloseSocket();
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
package im.conversations.android.xmpp.sasl;
|
package im.conversations.android.xmpp.sasl;
|
||||||
|
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.io.BaseEncoding;
|
import com.google.common.io.BaseEncoding;
|
||||||
|
|
||||||
import im.conversations.android.IDs;
|
import im.conversations.android.IDs;
|
||||||
import im.conversations.android.database.model.Account;
|
import im.conversations.android.database.model.Account;
|
||||||
import im.conversations.android.database.model.Credential;
|
import im.conversations.android.database.model.Credential;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import javax.net.ssl.SSLSocket;
|
import javax.net.ssl.SSLSocket;
|
||||||
|
|
||||||
public class DigestMd5 extends SaslMechanism {
|
public class DigestMd5 extends SaslMechanism {
|
||||||
|
@ -71,14 +67,11 @@ public class DigestMd5 extends SaslMechanism {
|
||||||
.getBytes(Charset.defaultCharset()));
|
.getBytes(Charset.defaultCharset()));
|
||||||
final String a2 = "AUTHENTICATE:" + digestUri;
|
final String a2 = "AUTHENTICATE:" + digestUri;
|
||||||
final String ha1 = bytesToHex(md.digest(a1));
|
final String ha1 = bytesToHex(md.digest(a1));
|
||||||
final String ha2 =
|
final String ha2 = bytesToHex(md.digest(a2.getBytes(Charset.defaultCharset())));
|
||||||
bytesToHex(
|
|
||||||
md.digest(a2.getBytes(Charset.defaultCharset())));
|
|
||||||
final String kd =
|
final String kd =
|
||||||
ha1 + ":" + nonce + ":" + nonceCount + ":" + cNonce + ":auth:" + ha2;
|
ha1 + ":" + nonce + ":" + nonceCount + ":" + cNonce + ":auth:" + ha2;
|
||||||
final String response =
|
final String response =
|
||||||
bytesToHex(
|
bytesToHex(md.digest(kd.getBytes(Charset.defaultCharset())));
|
||||||
md.digest(kd.getBytes(Charset.defaultCharset())));
|
|
||||||
final String saslString =
|
final String saslString =
|
||||||
"username=\""
|
"username=\""
|
||||||
+ account.address.getLocalpartOrThrow().toString()
|
+ account.address.getLocalpartOrThrow().toString()
|
||||||
|
|
Loading…
Reference in a new issue