Prevent changes to conversations while device is unregistered.

This commit is contained in:
Cody Henthorne
2021-04-14 11:48:51 -04:00
committed by Greyson Parrelli
parent 5df1fa3c65
commit ed8edb5aee
5 changed files with 82 additions and 6 deletions

View File

@@ -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;
}

View File

@@ -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());
}
}