Search in sources :

Example 1 with ProfileKeyVersion

use of org.signal.zkgroup.profiles.ProfileKeyVersion in project Signal-Android by WhisperSystems.

the class ProfileService method getProfile.

public Single<ServiceResponse<ProfileAndCredential>> getProfile(SignalServiceAddress address, Optional<ProfileKey> profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, SignalServiceProfile.RequestType requestType, Locale locale) {
    ServiceId serviceId = address.getServiceId();
    SecureRandom random = new SecureRandom();
    ProfileKeyCredentialRequestContext requestContext = null;
    WebSocketProtos.WebSocketRequestMessage.Builder builder = WebSocketProtos.WebSocketRequestMessage.newBuilder().setId(random.nextLong()).setVerb("GET");
    if (profileKey.isPresent()) {
        ProfileKeyVersion profileKeyIdentifier = profileKey.get().getProfileKeyVersion(serviceId.uuid());
        String version = profileKeyIdentifier.serialize();
        if (requestType == SignalServiceProfile.RequestType.PROFILE_AND_CREDENTIAL) {
            requestContext = clientZkProfileOperations.createProfileKeyCredentialRequestContext(random, serviceId.uuid(), profileKey.get());
            ProfileKeyCredentialRequest request = requestContext.getRequest();
            String credentialRequest = Hex.toStringCondensed(request.serialize());
            builder.setPath(String.format("/v1/profile/%s/%s/%s", serviceId, version, credentialRequest));
        } else {
            builder.setPath(String.format("/v1/profile/%s/%s", serviceId, version));
        }
    } else {
        builder.setPath(String.format("/v1/profile/%s", address.getIdentifier()));
    }
    builder.addHeaders(AcceptLanguagesUtil.getAcceptLanguageHeader(locale));
    WebSocketProtos.WebSocketRequestMessage requestMessage = builder.build();
    ResponseMapper<ProfileAndCredential> responseMapper = DefaultResponseMapper.extend(ProfileAndCredential.class).withResponseMapper(new ProfileResponseMapper(requestType, requestContext)).build();
    return signalWebSocket.request(requestMessage, unidentifiedAccess).map(responseMapper::map).onErrorResumeNext(t -> restFallback(address, profileKey, unidentifiedAccess, requestType, locale)).onErrorReturn(ServiceResponse::forUnknownError);
}
Also used : Single(io.reactivex.rxjava3.core.Single) AcceptLanguagesUtil(org.whispersystems.signalservice.internal.push.http.AcceptLanguagesUtil) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) VerificationFailedException(org.signal.zkgroup.VerificationFailedException) SignalWebSocket(org.whispersystems.signalservice.api.SignalWebSocket) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) SecureRandom(java.security.SecureRandom) UnidentifiedAccess(org.whispersystems.signalservice.api.crypto.UnidentifiedAccess) Pair(org.whispersystems.libsignal.util.Pair) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) Locale(java.util.Locale) Hex(org.whispersystems.signalservice.internal.util.Hex) DefaultResponseMapper(org.whispersystems.signalservice.internal.websocket.DefaultResponseMapper) ClientZkProfileOperations(org.signal.zkgroup.profiles.ClientZkProfileOperations) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) ACI(org.whispersystems.signalservice.api.push.ACI) WebSocketProtos(org.whispersystems.signalservice.internal.websocket.WebSocketProtos) ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) Function(org.whispersystems.libsignal.util.guava.Function) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) JsonUtil(org.whispersystems.signalservice.internal.util.JsonUtil) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) ProfileKeyCredentialRequestContext(org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext) ResponseMapper(org.whispersystems.signalservice.internal.websocket.ResponseMapper) ServiceResponseProcessor(org.whispersystems.signalservice.internal.ServiceResponseProcessor) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) SecureRandom(java.security.SecureRandom) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) ProfileKeyCredentialRequestContext(org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) WebSocketProtos(org.whispersystems.signalservice.internal.websocket.WebSocketProtos)

Example 2 with ProfileKeyVersion

use of org.signal.zkgroup.profiles.ProfileKeyVersion in project Signal-Android by signalapp.

the class PushServiceSocket method retrieveVersionedProfileAndCredential.

public ListenableFuture<ProfileAndCredential> retrieveVersionedProfileAndCredential(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, Locale locale) {
    ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(target);
    ProfileKeyCredentialRequestContext requestContext = clientZkProfileOperations.createProfileKeyCredentialRequestContext(random, target, profileKey);
    ProfileKeyCredentialRequest request = requestContext.getRequest();
    String version = profileKeyIdentifier.serialize();
    String credentialRequest = Hex.toStringCondensed(request.serialize());
    String subPath = String.format("%s/%s/%s", target, version, credentialRequest);
    ListenableFuture<String> response = submitServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, AcceptLanguagesUtil.getHeadersWithAcceptLanguage(locale), unidentifiedAccess);
    return FutureTransformers.map(response, body -> formatProfileAndCredentialBody(requestContext, body));
}
Also used : ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) ProfileKeyCredentialRequestContext(org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext)

Example 3 with ProfileKeyVersion

use of org.signal.zkgroup.profiles.ProfileKeyVersion in project Signal-Android by signalapp.

the class PushServiceSocket method retrieveVersionedProfile.

public ListenableFuture<SignalServiceProfile> retrieveVersionedProfile(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, Locale locale) {
    ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(target);
    String version = profileKeyIdentifier.serialize();
    String subPath = String.format("%s/%s", target, version);
    ListenableFuture<String> response = submitServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, AcceptLanguagesUtil.getHeadersWithAcceptLanguage(locale), unidentifiedAccess);
    return FutureTransformers.map(response, body -> {
        try {
            return JsonUtil.fromJson(body, SignalServiceProfile.class);
        } catch (IOException e) {
            Log.w(TAG, e);
            throw new MalformedResponseException("Unable to parse entity", e);
        }
    });
}
Also used : ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) IOException(java.io.IOException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Example 4 with ProfileKeyVersion

use of org.signal.zkgroup.profiles.ProfileKeyVersion in project Signal-Android by WhisperSystems.

the class PushServiceSocket method retrieveVersionedProfile.

public ListenableFuture<SignalServiceProfile> retrieveVersionedProfile(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, Locale locale) {
    ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(target);
    String version = profileKeyIdentifier.serialize();
    String subPath = String.format("%s/%s", target, version);
    ListenableFuture<String> response = submitServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, AcceptLanguagesUtil.getHeadersWithAcceptLanguage(locale), unidentifiedAccess);
    return FutureTransformers.map(response, body -> {
        try {
            return JsonUtil.fromJson(body, SignalServiceProfile.class);
        } catch (IOException e) {
            Log.w(TAG, e);
            throw new MalformedResponseException("Unable to parse entity", e);
        }
    });
}
Also used : ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) IOException(java.io.IOException) MalformedResponseException(org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)

Example 5 with ProfileKeyVersion

use of org.signal.zkgroup.profiles.ProfileKeyVersion in project Signal-Android by WhisperSystems.

the class PushServiceSocket method retrieveVersionedProfileAndCredential.

public ListenableFuture<ProfileAndCredential> retrieveVersionedProfileAndCredential(UUID target, ProfileKey profileKey, Optional<UnidentifiedAccess> unidentifiedAccess, Locale locale) {
    ProfileKeyVersion profileKeyIdentifier = profileKey.getProfileKeyVersion(target);
    ProfileKeyCredentialRequestContext requestContext = clientZkProfileOperations.createProfileKeyCredentialRequestContext(random, target, profileKey);
    ProfileKeyCredentialRequest request = requestContext.getRequest();
    String version = profileKeyIdentifier.serialize();
    String credentialRequest = Hex.toStringCondensed(request.serialize());
    String subPath = String.format("%s/%s/%s", target, version, credentialRequest);
    ListenableFuture<String> response = submitServiceRequest(String.format(PROFILE_PATH, subPath), "GET", null, AcceptLanguagesUtil.getHeadersWithAcceptLanguage(locale), unidentifiedAccess);
    return FutureTransformers.map(response, body -> formatProfileAndCredentialBody(requestContext, body));
}
Also used : ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) ProfileKeyVersion(org.signal.zkgroup.profiles.ProfileKeyVersion) GroupsV2AuthorizationString(org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString) ProfileKeyCredentialRequestContext(org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext)

Aggregations

ProfileKeyVersion (org.signal.zkgroup.profiles.ProfileKeyVersion)6 ProfileKeyCredentialRequest (org.signal.zkgroup.profiles.ProfileKeyCredentialRequest)4 ProfileKeyCredentialRequestContext (org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext)4 GroupsV2AuthorizationString (org.whispersystems.signalservice.api.groupsv2.GroupsV2AuthorizationString)4 MalformedResponseException (org.whispersystems.signalservice.api.push.exceptions.MalformedResponseException)4 Single (io.reactivex.rxjava3.core.Single)2 IOException (java.io.IOException)2 SecureRandom (java.security.SecureRandom)2 Locale (java.util.Locale)2 TimeUnit (java.util.concurrent.TimeUnit)2 VerificationFailedException (org.signal.zkgroup.VerificationFailedException)2 ClientZkProfileOperations (org.signal.zkgroup.profiles.ClientZkProfileOperations)2 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)2 ProfileKeyCredential (org.signal.zkgroup.profiles.ProfileKeyCredential)2 Pair (org.whispersystems.libsignal.util.Pair)2 Function (org.whispersystems.libsignal.util.guava.Function)2 Optional (org.whispersystems.libsignal.util.guava.Optional)2 SignalServiceMessageReceiver (org.whispersystems.signalservice.api.SignalServiceMessageReceiver)2 SignalWebSocket (org.whispersystems.signalservice.api.SignalWebSocket)2 UnidentifiedAccess (org.whispersystems.signalservice.api.crypto.UnidentifiedAccess)2