mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-22 02:36:55 +00:00
Prevent changes to conversations while device is unregistered.
This commit is contained in:
committed by
Greyson Parrelli
parent
5df1fa3c65
commit
ed8edb5aee
@@ -70,6 +70,10 @@ public class PipeConnectivityListener implements ConnectivityListener {
|
||||
Log.w(TAG, "Encountered an error while we had a proxy set! Terminating the connection to prevent retry spam.");
|
||||
ApplicationDependencies.closeConnections();
|
||||
return false;
|
||||
} else if (TextSecurePreferences.isUnauthorizedRecieved(ApplicationDependencies.getApplication())) {
|
||||
Log.w(TAG, "Encountered an error while unregistered! Terminating the connection to prevent retry spam.");
|
||||
ApplicationDependencies.closeConnections();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.thoughtcrime.securesms.net;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.signalservice.internal.push.PushServiceSocket;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
/**
|
||||
* Blocks network access when device is unregistered.
|
||||
*/
|
||||
public final class UnregisteredBlockingInterceptor implements Interceptor {
|
||||
|
||||
private static final String TAG = Log.tag(UnregisteredBlockingInterceptor.class);
|
||||
|
||||
@Override
|
||||
public @NonNull Response intercept(@NonNull Chain chain) throws IOException {
|
||||
if (TextSecurePreferences.isUnauthorizedRecieved(ApplicationDependencies.getApplication()) &&
|
||||
PushServiceSocket.isNotRegistrationPath(chain.request().url().encodedPath()))
|
||||
{
|
||||
Log.w(TAG, "Preventing request because device is unregistered.");
|
||||
return new Response.Builder().request(chain.request())
|
||||
.protocol(Protocol.HTTP_1_1)
|
||||
.receivedResponseAtMillis(System.currentTimeMillis())
|
||||
.message("")
|
||||
.body(ResponseBody.create(null, ""))
|
||||
.code(508)
|
||||
.build();
|
||||
}
|
||||
|
||||
return chain.proceed(chain.request());
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package org.thoughtcrime.securesms.push;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore;
|
||||
@@ -16,6 +16,7 @@ import org.thoughtcrime.securesms.net.DeviceTransferBlockingInterceptor;
|
||||
import org.thoughtcrime.securesms.net.RemoteDeprecationDetectorInterceptor;
|
||||
import org.thoughtcrime.securesms.net.SequentialDns;
|
||||
import org.thoughtcrime.securesms.net.StandardUserAgentInterceptor;
|
||||
import org.thoughtcrime.securesms.net.UnregisteredBlockingInterceptor;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
@@ -34,8 +35,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import okhttp3.CipherSuite;
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.Dns;
|
||||
@@ -185,6 +184,7 @@ public class SignalServiceNetworkAccess {
|
||||
final List<Interceptor> interceptors = Arrays.asList(new StandardUserAgentInterceptor(),
|
||||
new RemoteDeprecationDetectorInterceptor(),
|
||||
new DeprecatedClientPreventionInterceptor(),
|
||||
new UnregisteredBlockingInterceptor(),
|
||||
DeviceTransferBlockingInterceptor.getInstance());
|
||||
final Optional<Dns> dns = Optional.of(DNS);
|
||||
|
||||
|
||||
@@ -466,6 +466,12 @@ public class TextSecurePreferences {
|
||||
}
|
||||
|
||||
public static void setUnauthorizedReceived(Context context, boolean value) {
|
||||
if (value) {
|
||||
ApplicationDependencies.closeConnections();
|
||||
} else {
|
||||
ApplicationDependencies.getIncomingMessageObserver();
|
||||
}
|
||||
|
||||
setBooleanPreference(context, UNAUTHORIZED_RECEIVED, value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user