Search in sources :

Example 1 with ProfileKeyCredential

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

the class GroupsV2Operations_decrypt_change_Test method groupCandidate.

GroupCandidate groupCandidate(UUID uuid, ProfileKey profileKey) {
    try {
        ClientZkProfileOperations profileOperations = clientZkOperations.getProfileOperations();
        ProfileKeyCommitment commitment = profileKey.getCommitment(uuid);
        ProfileKeyCredentialRequestContext requestContext = profileOperations.createProfileKeyCredentialRequestContext(uuid, profileKey);
        ProfileKeyCredentialRequest request = requestContext.getRequest();
        ProfileKeyCredentialResponse profileKeyCredentialResponse = server.getProfileKeyCredentialResponse(request, uuid, commitment);
        ProfileKeyCredential profileKeyCredential = profileOperations.receiveProfileKeyCredential(requestContext, profileKeyCredentialResponse);
        GroupCandidate groupCandidate = new GroupCandidate(uuid, Optional.of(profileKeyCredential));
        ProfileKeyCredentialPresentation presentation = profileOperations.createProfileKeyCredentialPresentation(groupSecretParams, profileKeyCredential);
        server.assertProfileKeyCredentialPresentation(groupSecretParams.getPublicParams(), presentation);
        return groupCandidate;
    } catch (VerificationFailedException e) {
        throw new AssertionError(e);
    }
}
Also used : ProfileKeyCredentialResponse(org.signal.zkgroup.profiles.ProfileKeyCredentialResponse) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) ClientZkProfileOperations(org.signal.zkgroup.profiles.ClientZkProfileOperations) ProfileKeyCredentialRequest(org.signal.zkgroup.profiles.ProfileKeyCredentialRequest) ProfileKeyCredentialPresentation(org.signal.zkgroup.profiles.ProfileKeyCredentialPresentation) ProfileKeyCommitment(org.signal.zkgroup.profiles.ProfileKeyCommitment) ProfileKeyCredentialRequestContext(org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext) VerificationFailedException(org.signal.zkgroup.VerificationFailedException)

Example 2 with ProfileKeyCredential

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

the class RetrieveProfileJob method process.

private void process(Recipient recipient, ProfileAndCredential profileAndCredential) {
    SignalServiceProfile profile = profileAndCredential.getProfile();
    ProfileKey recipientProfileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
    setProfileName(recipient, profile.getName());
    setProfileAbout(recipient, profile.getAbout(), profile.getAboutEmoji());
    setProfileAvatar(recipient, profile.getAvatar());
    setProfileBadges(recipient, profile.getBadges());
    clearUsername(recipient);
    setProfileCapabilities(recipient, profile.getCapabilities());
    setUnidentifiedAccessMode(recipient, profile.getUnidentifiedAccess(), profile.isUnrestrictedUnidentifiedAccess());
    if (recipientProfileKey != null) {
        Optional<ProfileKeyCredential> profileKeyCredential = profileAndCredential.getProfileKeyCredential();
        if (profileKeyCredential.isPresent()) {
            setProfileKeyCredential(recipient, recipientProfileKey, profileKeyCredential.get());
        }
    }
}
Also used : ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile)

Example 3 with ProfileKeyCredential

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

the class RefreshOwnProfileJob method onRun.

@Override
protected void onRun() throws Exception {
    if (!SignalStore.account().isRegistered() || TextUtils.isEmpty(SignalStore.account().getE164())) {
        Log.w(TAG, "Not yet registered!");
        return;
    }
    if (SignalStore.kbsValues().hasPin() && !SignalStore.kbsValues().hasOptedOut() && SignalStore.storageService().getLastSyncTime() == 0) {
        Log.i(TAG, "Registered with PIN but haven't completed storage sync yet.");
        return;
    }
    if (!SignalStore.registrationValues().hasUploadedProfile() && SignalStore.account().isPrimaryDevice()) {
        Log.i(TAG, "Registered but haven't uploaded profile yet.");
        return;
    }
    Recipient self = Recipient.self();
    ProfileAndCredential profileAndCredential = ProfileUtil.retrieveProfileSync(context, self, getRequestType(self), false);
    SignalServiceProfile profile = profileAndCredential.getProfile();
    setProfileName(profile.getName());
    setProfileAbout(profile.getAbout(), profile.getAboutEmoji());
    setProfileAvatar(profile.getAvatar());
    setProfileCapabilities(profile.getCapabilities());
    setProfileBadges(profile.getBadges());
    Optional<ProfileKeyCredential> profileKeyCredential = profileAndCredential.getProfileKeyCredential();
    if (profileKeyCredential.isPresent()) {
        setProfileKeyCredential(self, ProfileKeyUtil.getSelfProfileKey(), profileKeyCredential.get());
    }
}
Also used : ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile)

Example 4 with ProfileKeyCredential

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

the class GroupsV2Operations method createNewGroup.

/**
 * Creates a new group with the title and avatar.
 *
 * @param self    You will be member 0 and the only admin.
 * @param members Members must not contain self. Members will be non-admin members of the group.
 */
public NewGroup createNewGroup(final GroupSecretParams groupSecretParams, final String title, final Optional<byte[]> avatar, final GroupCandidate self, final Set<GroupCandidate> members, final Member.Role memberRole, final int disappearingMessageTimerSeconds) {
    if (members.contains(self)) {
        throw new IllegalArgumentException("Members must not contain self");
    }
    final GroupOperations groupOperations = forGroup(groupSecretParams);
    Group.Builder group = Group.newBuilder().setRevision(0).setPublicKey(ByteString.copyFrom(groupSecretParams.getPublicParams().serialize())).setTitle(groupOperations.encryptTitle(title)).setDisappearingMessagesTimer(groupOperations.encryptTimer(disappearingMessageTimerSeconds)).setAccessControl(AccessControl.newBuilder().setAttributes(AccessControl.AccessRequired.MEMBER).setMembers(AccessControl.AccessRequired.MEMBER));
    group.addMembers(groupOperations.member(self.getProfileKeyCredential().get(), Member.Role.ADMINISTRATOR));
    for (GroupCandidate credential : members) {
        ProfileKeyCredential profileKeyCredential = credential.getProfileKeyCredential().orNull();
        if (profileKeyCredential != null) {
            group.addMembers(groupOperations.member(profileKeyCredential, memberRole));
        } else {
            group.addPendingMembers(groupOperations.invitee(credential.getUuid(), memberRole));
        }
    }
    return new NewGroup(groupSecretParams, group.build(), avatar);
}
Also used : Group(org.signal.storageservice.protos.groups.Group) DecryptedGroup(org.signal.storageservice.protos.groups.local.DecryptedGroup) ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential)

Example 5 with ProfileKeyCredential

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

the class GroupCandidateHelper method recipientIdToCandidate.

/**
 * Given a recipient will create a {@link GroupCandidate} which may or may not have a profile key credential.
 * <p>
 * It will try to find missing profile key credentials from the server and persist locally.
 */
@WorkerThread
@NonNull
public GroupCandidate recipientIdToCandidate(@NonNull RecipientId recipientId) throws IOException {
    final Recipient recipient = Recipient.resolved(recipientId);
    ServiceId serviceId = recipient.getServiceId().orNull();
    if (serviceId == null) {
        throw new AssertionError("Non UUID members should have need detected by now");
    }
    Optional<ProfileKeyCredential> profileKeyCredential = Optional.fromNullable(recipient.getProfileKeyCredential());
    GroupCandidate candidate = new GroupCandidate(serviceId.uuid(), profileKeyCredential);
    if (!candidate.hasProfileKeyCredential()) {
        ProfileKey profileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
        if (profileKey != null) {
            Log.i(TAG, String.format("No profile key credential on recipient %s, fetching", recipient.getId()));
            Optional<ProfileKeyCredential> profileKeyCredentialOptional = signalServiceAccountManager.resolveProfileKeyCredential(serviceId, profileKey, Locale.getDefault());
            if (profileKeyCredentialOptional.isPresent()) {
                boolean updatedProfileKey = recipientDatabase.setProfileKeyCredential(recipient.getId(), profileKey, profileKeyCredentialOptional.get());
                if (!updatedProfileKey) {
                    Log.w(TAG, String.format("Failed to update the profile key credential on recipient %s", recipient.getId()));
                } else {
                    Log.i(TAG, String.format("Got new profile key credential for recipient %s", recipient.getId()));
                    candidate = candidate.withProfileKeyCredential(profileKeyCredentialOptional.get());
                }
            }
        }
    }
    return candidate;
}
Also used : ProfileKeyCredential(org.signal.zkgroup.profiles.ProfileKeyCredential) GroupCandidate(org.whispersystems.signalservice.api.groupsv2.GroupCandidate) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) ServiceId(org.whispersystems.signalservice.api.push.ServiceId) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Aggregations

ProfileKeyCredential (org.signal.zkgroup.profiles.ProfileKeyCredential)5 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 SignalServiceProfile (org.whispersystems.signalservice.api.profiles.SignalServiceProfile)2 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 Group (org.signal.storageservice.protos.groups.Group)1 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)1 VerificationFailedException (org.signal.zkgroup.VerificationFailedException)1 ClientZkProfileOperations (org.signal.zkgroup.profiles.ClientZkProfileOperations)1 ProfileKeyCommitment (org.signal.zkgroup.profiles.ProfileKeyCommitment)1 ProfileKeyCredentialPresentation (org.signal.zkgroup.profiles.ProfileKeyCredentialPresentation)1 ProfileKeyCredentialRequest (org.signal.zkgroup.profiles.ProfileKeyCredentialRequest)1 ProfileKeyCredentialRequestContext (org.signal.zkgroup.profiles.ProfileKeyCredentialRequestContext)1 ProfileKeyCredentialResponse (org.signal.zkgroup.profiles.ProfileKeyCredentialResponse)1 GroupCandidate (org.whispersystems.signalservice.api.groupsv2.GroupCandidate)1 ProfileAndCredential (org.whispersystems.signalservice.api.profiles.ProfileAndCredential)1 ServiceId (org.whispersystems.signalservice.api.push.ServiceId)1