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