From b5a47000c9b8dd751a516c500f8dd6df212794af Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 16 Feb 2023 12:14:26 +0100 Subject: [PATCH] get rid of payment required account state --- .../conversations/android/Conversations.java | 5 --- .../conversations/android/xmpp/Closables.java | 24 ++++++++++++++ .../android/xmpp/XmppConnection.java | 33 ++++--------------- .../android/xmpp/sasl/DigestMd5.java | 11 ++----- 4 files changed, 32 insertions(+), 41 deletions(-) create mode 100644 src/main/java/im/conversations/android/xmpp/Closables.java diff --git a/src/main/java/im/conversations/android/Conversations.java b/src/main/java/im/conversations/android/Conversations.java index 2e3148c35..f34ffed9c 100644 --- a/src/main/java/im/conversations/android/Conversations.java +++ b/src/main/java/im/conversations/android/Conversations.java @@ -1,15 +1,10 @@ package im.conversations.android; import android.app.Application; -import android.util.Log; - import com.google.android.material.color.DynamicColors; - -import eu.siacs.conversations.Config; import im.conversations.android.xmpp.ConnectionPool; import java.security.SecureRandom; import java.security.Security; - import org.conscrypt.Conscrypt; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/im/conversations/android/xmpp/Closables.java b/src/main/java/im/conversations/android/xmpp/Closables.java new file mode 100644 index 000000000..03f8e6c8d --- /dev/null +++ b/src/main/java/im/conversations/android/xmpp/Closables.java @@ -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); + } + } +} diff --git a/src/main/java/im/conversations/android/xmpp/XmppConnection.java b/src/main/java/im/conversations/android/xmpp/XmppConnection.java index 597c29c2e..946d60231 100644 --- a/src/main/java/im/conversations/android/xmpp/XmppConnection.java +++ b/src/main/java/im/conversations/android/xmpp/XmppConnection.java @@ -21,11 +21,9 @@ import com.google.common.util.concurrent.SettableFuture; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.XmppDomainVerifier; -import eu.siacs.conversations.persistance.FileBackend; import eu.siacs.conversations.services.MemorizingTrustManager; import eu.siacs.conversations.services.NotificationService; import eu.siacs.conversations.ui.util.PendingItem; -import eu.siacs.conversations.utils.Patterns; import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.Resolver; 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.function.BiFunction; import java.util.function.Consumer; -import java.util.regex.Matcher; import javax.net.ssl.KeyManager; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLPeerUnverifiedException; @@ -422,7 +419,7 @@ public class XmppConnection implements Runnable { } break; // successfully connected to server that speaks xmpp } else { - FileBackend.close(localSocket); + Closables.close(localSocket); throw new StateChangingException(ConnectionState.STREAM_OPENING_ERROR); } } catch (final StateChangingException e) { @@ -895,24 +892,6 @@ public class XmppConnection implements Runnable { } if (failure.hasChild("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)) { Log.d( @@ -1193,11 +1172,11 @@ public class XmppConnection implements Runnable { Log.d( Config.LOGTAG, account.address + ": TLS certificate domain verification failed"); - FileBackend.close(sslSocket); + Closables.close(sslSocket); throw new StateChangingException(ConnectionState.TLS_ERROR_DOMAIN); } } catch (final SSLPeerUnverifiedException e) { - FileBackend.close(sslSocket); + Closables.close(sslSocket); throw new StateChangingException(ConnectionState.TLS_ERROR); } return sslSocket; @@ -1978,8 +1957,8 @@ public class XmppConnection implements Runnable { } private void forceCloseSocket() { - FileBackend.close(this.socket); - FileBackend.close(this.tagReader); + Closables.close(this.socket); + Closables.close(this.tagReader); } public void interrupt() { @@ -2025,7 +2004,7 @@ public class XmppConnection implements Runnable { + e.getMessage() + ")"); } finally { - FileBackend.close(currentSocket); + Closables.close(currentSocket); } } else { forceCloseSocket(); diff --git a/src/main/java/im/conversations/android/xmpp/sasl/DigestMd5.java b/src/main/java/im/conversations/android/xmpp/sasl/DigestMd5.java index df34a40ba..a1daae10f 100644 --- a/src/main/java/im/conversations/android/xmpp/sasl/DigestMd5.java +++ b/src/main/java/im/conversations/android/xmpp/sasl/DigestMd5.java @@ -1,18 +1,14 @@ package im.conversations.android.xmpp.sasl; import android.util.Base64; - import com.google.common.base.Strings; import com.google.common.io.BaseEncoding; - import im.conversations.android.IDs; import im.conversations.android.database.model.Account; import im.conversations.android.database.model.Credential; - import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; - import javax.net.ssl.SSLSocket; public class DigestMd5 extends SaslMechanism { @@ -71,14 +67,11 @@ public class DigestMd5 extends SaslMechanism { .getBytes(Charset.defaultCharset())); final String a2 = "AUTHENTICATE:" + digestUri; final String ha1 = bytesToHex(md.digest(a1)); - final String ha2 = - bytesToHex( - md.digest(a2.getBytes(Charset.defaultCharset()))); + final String ha2 = bytesToHex(md.digest(a2.getBytes(Charset.defaultCharset()))); final String kd = ha1 + ":" + nonce + ":" + nonceCount + ":" + cNonce + ":auth:" + ha2; final String response = - bytesToHex( - md.digest(kd.getBytes(Charset.defaultCharset()))); + bytesToHex(md.digest(kd.getBytes(Charset.defaultCharset()))); final String saslString = "username=\"" + account.address.getLocalpartOrThrow().toString()