mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-25 05:27:42 +00:00
Convert storage service auth to WebSocket.
This commit is contained in:
committed by
Greyson Parrelli
parent
6aca7c9194
commit
86b2fe9742
@@ -393,7 +393,7 @@ object AppDependencies {
|
||||
fun provideAttachmentApi(authWebSocket: SignalWebSocket.AuthenticatedWebSocket, pushServiceSocket: PushServiceSocket): AttachmentApi
|
||||
fun provideLinkDeviceApi(authWebSocket: SignalWebSocket.AuthenticatedWebSocket): LinkDeviceApi
|
||||
fun provideRegistrationApi(pushServiceSocket: PushServiceSocket): RegistrationApi
|
||||
fun provideStorageServiceApi(pushServiceSocket: PushServiceSocket): StorageServiceApi
|
||||
fun provideStorageServiceApi(authWebSocket: SignalWebSocket.AuthenticatedWebSocket, pushServiceSocket: PushServiceSocket): StorageServiceApi
|
||||
fun provideAuthWebSocket(signalServiceConfigurationSupplier: Supplier<SignalServiceConfiguration>, libSignalNetworkSupplier: Supplier<Network>): SignalWebSocket.AuthenticatedWebSocket
|
||||
fun provideUnauthWebSocket(signalServiceConfigurationSupplier: Supplier<SignalServiceConfiguration>, libSignalNetworkSupplier: Supplier<Network>): SignalWebSocket.UnauthenticatedWebSocket
|
||||
fun provideAccountApi(authWebSocket: SignalWebSocket.AuthenticatedWebSocket): AccountApi
|
||||
|
||||
@@ -487,8 +487,8 @@ public class ApplicationDependencyProvider implements AppDependencies.Provider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull StorageServiceApi provideStorageServiceApi(@NonNull PushServiceSocket pushServiceSocket) {
|
||||
return new StorageServiceApi(pushServiceSocket);
|
||||
public @NonNull StorageServiceApi provideStorageServiceApi(@NonNull SignalWebSocket.AuthenticatedWebSocket authWebSocket, @NonNull PushServiceSocket pushServiceSocket) {
|
||||
return new StorageServiceApi(authWebSocket, pushServiceSocket);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -154,7 +154,7 @@ class NetworkDependenciesModule(
|
||||
}
|
||||
|
||||
val storageServiceApi: StorageServiceApi by lazy {
|
||||
provider.provideStorageServiceApi(pushServiceSocket)
|
||||
provider.provideStorageServiceApi(authWebSocket, pushServiceSocket)
|
||||
}
|
||||
|
||||
val accountApi: AccountApi by lazy {
|
||||
|
||||
@@ -234,7 +234,7 @@ class MockApplicationDependencyProvider : AppDependencies.Provider {
|
||||
return mockk(relaxed = true)
|
||||
}
|
||||
|
||||
override fun provideStorageServiceApi(pushServiceSocket: PushServiceSocket): StorageServiceApi {
|
||||
override fun provideStorageServiceApi(authWebSocket: SignalWebSocket.AuthenticatedWebSocket, pushServiceSocket: PushServiceSocket): StorageServiceApi {
|
||||
return mockk(relaxed = true)
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,24 @@
|
||||
|
||||
package org.whispersystems.signalservice.api.storage
|
||||
|
||||
import okhttp3.Credentials
|
||||
import org.whispersystems.signalservice.api.NetworkResult
|
||||
import org.whispersystems.signalservice.api.websocket.SignalWebSocket
|
||||
import org.whispersystems.signalservice.internal.get
|
||||
import org.whispersystems.signalservice.internal.push.PushServiceSocket
|
||||
import org.whispersystems.signalservice.internal.storage.protos.ReadOperation
|
||||
import org.whispersystems.signalservice.internal.storage.protos.StorageItems
|
||||
import org.whispersystems.signalservice.internal.storage.protos.StorageManifest
|
||||
import org.whispersystems.signalservice.internal.storage.protos.WriteOperation
|
||||
import org.whispersystems.signalservice.internal.websocket.WebSocketRequestMessage
|
||||
|
||||
/**
|
||||
* Class to interact with storage service endpoints.
|
||||
*/
|
||||
class StorageServiceApi(private val pushServiceSocket: PushServiceSocket) {
|
||||
class StorageServiceApi(
|
||||
private val authWebSocket: SignalWebSocket.AuthenticatedWebSocket,
|
||||
private val pushServiceSocket: PushServiceSocket
|
||||
) {
|
||||
|
||||
/**
|
||||
* Retrieves an auth string that's needed to make other storage requests.
|
||||
@@ -23,9 +30,9 @@ class StorageServiceApi(private val pushServiceSocket: PushServiceSocket) {
|
||||
* GET /v1/storage/auth
|
||||
*/
|
||||
fun getAuth(): NetworkResult<String> {
|
||||
return NetworkResult.fromFetch {
|
||||
pushServiceSocket.getStorageAuth()
|
||||
}
|
||||
val request = WebSocketRequestMessage.get("/v1/storage/auth")
|
||||
return NetworkResult.fromWebSocketRequest(authWebSocket, request, StorageAuthResponse::class)
|
||||
.map { Credentials.basic(it.username, it.password) }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -88,7 +88,6 @@ import org.whispersystems.signalservice.api.push.exceptions.SubmitVerificationCo
|
||||
import org.whispersystems.signalservice.api.push.exceptions.TokenNotAcceptedException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||
import org.whispersystems.signalservice.api.registration.RestoreMethodBody;
|
||||
import org.whispersystems.signalservice.api.storage.StorageAuthResponse;
|
||||
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription;
|
||||
import org.whispersystems.signalservice.api.subscriptions.PayPalConfirmPaymentIntentResponse;
|
||||
import org.whispersystems.signalservice.api.subscriptions.PayPalCreatePaymentIntentResponse;
|
||||
@@ -175,7 +174,6 @@ import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.Credentials;
|
||||
import okhttp3.Dns;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Interceptor;
|
||||
@@ -1113,13 +1111,6 @@ public class PushServiceSocket {
|
||||
}
|
||||
}
|
||||
|
||||
public String getStorageAuth() throws IOException {
|
||||
String response = makeServiceRequest("/v1/storage/auth", "GET", null);
|
||||
StorageAuthResponse authResponse = JsonUtil.fromJson(response, StorageAuthResponse.class);
|
||||
|
||||
return Credentials.basic(authResponse.getUsername(), authResponse.getPassword());
|
||||
}
|
||||
|
||||
public StorageManifest getStorageManifest(String authToken) throws IOException {
|
||||
try (Response response = makeStorageRequest(authToken, "/v1/storage/manifest", "GET", null, NO_HANDLER)) {
|
||||
return StorageManifest.ADAPTER.decode(readBodyBytes(response));
|
||||
|
||||
Reference in New Issue
Block a user