Search in sources :

Example 36 with ProfileKey

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

the class ProfileUtil method getProfileKey.

private static ProfileKey getProfileKey(@NonNull Recipient recipient) throws IOException {
    byte[] profileKeyBytes = recipient.getProfileKey();
    if (profileKeyBytes == null) {
        Log.w(TAG, "Profile key unknown for " + recipient.getId());
        throw new IOException("No profile key");
    }
    ProfileKey profileKey;
    try {
        profileKey = new ProfileKey(profileKeyBytes);
    } catch (InvalidInputException e) {
        Log.w(TAG, "Profile key invalid for " + recipient.getId());
        throw new IOException("Invalid profile key");
    }
    return profileKey;
}
Also used : InvalidInputException(org.signal.zkgroup.InvalidInputException) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 37 with ProfileKey

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

the class ProfileUtil method getAddressForRecipient.

@WorkerThread
@NonNull
public static MobileCoinPublicAddress getAddressForRecipient(@NonNull Recipient recipient) throws IOException, PaymentsAddressException {
    ProfileKey profileKey;
    try {
        profileKey = getProfileKey(recipient);
    } catch (IOException e) {
        Log.w(TAG, "Profile key not available for " + recipient.getId());
        throw new PaymentsAddressException(PaymentsAddressException.Code.NO_PROFILE_KEY);
    }
    ProfileAndCredential profileAndCredential = ProfileUtil.retrieveProfileSync(ApplicationDependencies.getApplication(), recipient, SignalServiceProfile.RequestType.PROFILE);
    SignalServiceProfile profile = profileAndCredential.getProfile();
    byte[] encryptedPaymentsAddress = profile.getPaymentAddress();
    if (encryptedPaymentsAddress == null) {
        Log.w(TAG, "Payments not enabled for " + recipient.getId());
        throw new PaymentsAddressException(PaymentsAddressException.Code.NOT_ENABLED);
    }
    try {
        IdentityKey identityKey = new IdentityKey(Base64.decode(profileAndCredential.getProfile().getIdentityKey()), 0);
        ProfileCipher profileCipher = new ProfileCipher(profileKey);
        byte[] decrypted = profileCipher.decryptWithLength(encryptedPaymentsAddress);
        SignalServiceProtos.PaymentAddress paymentAddress = SignalServiceProtos.PaymentAddress.parseFrom(decrypted);
        byte[] bytes = MobileCoinPublicAddressProfileUtil.verifyPaymentsAddress(paymentAddress, identityKey);
        MobileCoinPublicAddress mobileCoinPublicAddress = MobileCoinPublicAddress.fromBytes(bytes);
        if (mobileCoinPublicAddress == null) {
            throw new PaymentsAddressException(PaymentsAddressException.Code.INVALID_ADDRESS);
        }
        return mobileCoinPublicAddress;
    } catch (InvalidCiphertextException | IOException e) {
        Log.w(TAG, "Could not decrypt payments address, ProfileKey may be outdated for " + recipient.getId(), e);
        throw new PaymentsAddressException(PaymentsAddressException.Code.COULD_NOT_DECRYPT);
    } catch (InvalidKeyException e) {
        Log.w(TAG, "Could not verify payments address due to bad identity key " + recipient.getId(), e);
        throw new PaymentsAddressException(PaymentsAddressException.Code.INVALID_ADDRESS_SIGNATURE);
    }
}
Also used : IdentityKey(org.whispersystems.libsignal.IdentityKey) InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) ProfileCipher(org.whispersystems.signalservice.api.crypto.ProfileCipher) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) IOException(java.io.IOException) PaymentsAddressException(org.thoughtcrime.securesms.payments.PaymentsAddressException) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) SignalServiceProtos(org.whispersystems.signalservice.internal.push.SignalServiceProtos) MobileCoinPublicAddress(org.thoughtcrime.securesms.payments.MobileCoinPublicAddress) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 38 with ProfileKey

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

the class ProfileUtil method uploadProfile.

private static void uploadProfile(@NonNull Context context, @NonNull ProfileName profileName, @Nullable String about, @Nullable String aboutEmoji, @Nullable SignalServiceProtos.PaymentAddress paymentsAddress, @Nullable StreamDetails avatar, @NonNull List<Badge> badges) throws IOException {
    List<String> badgeIds = badges.stream().filter(Badge::getVisible).map(Badge::getId).collect(Collectors.toList());
    Log.d(TAG, "Uploading " + (!profileName.isEmpty() ? "non-" : "") + "empty profile name.");
    Log.d(TAG, "Uploading " + (!Util.isEmpty(about) ? "non-" : "") + "empty about.");
    Log.d(TAG, "Uploading " + (!Util.isEmpty(aboutEmoji) ? "non-" : "") + "empty emoji.");
    Log.d(TAG, "Uploading " + (paymentsAddress != null ? "non-" : "") + "empty payments address.");
    Log.d(TAG, "Uploading " + (avatar != null && avatar.getLength() != 0 ? "non-" : "") + "empty avatar.");
    Log.d(TAG, "Uploading " + ((!badgeIds.isEmpty()) ? "non-" : "") + "empty badge list");
    ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
    SignalServiceAccountManager accountManager = ApplicationDependencies.getSignalServiceAccountManager();
    String avatarPath = accountManager.setVersionedProfile(SignalStore.account().requireAci(), profileKey, profileName.serialize(), about, aboutEmoji, Optional.fromNullable(paymentsAddress), avatar, badgeIds).orNull();
    SignalStore.registrationValues().markHasUploadedProfile();
    SignalDatabase.recipients().setProfileAvatar(Recipient.self().getId(), avatarPath);
}
Also used : SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) Badge(org.thoughtcrime.securesms.badges.models.Badge) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 39 with ProfileKey

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

the class TextSecurePreferences method clearLocalCredentials.

private static void clearLocalCredentials(Context context) {
    ProfileKey newProfileKey = ProfileKeyUtil.createNew();
    Recipient self = Recipient.self();
    SignalDatabase.recipients().setProfileKey(self.getId(), newProfileKey);
    ApplicationDependencies.getGroupsV2Authorization().clear();
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 40 with ProfileKey

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

the class MessageContentProcessor method handleProfileKey.

private void handleProfileKey(@NonNull SignalServiceContent content, @NonNull byte[] messageProfileKeyBytes, @NonNull Recipient senderRecipient) {
    RecipientDatabase database = SignalDatabase.recipients();
    ProfileKey messageProfileKey = ProfileKeyUtil.profileKeyOrNull(messageProfileKeyBytes);
    if (senderRecipient.isSelf()) {
        if (!Objects.equals(ProfileKeyUtil.getSelfProfileKey(), messageProfileKey)) {
            warn(content.getTimestamp(), "Saw a sync message whose profile key doesn't match our records. Scheduling a storage sync to check.");
            StorageSyncHelper.scheduleSyncForDataChange();
        }
    } else if (messageProfileKey != null) {
        if (database.setProfileKey(senderRecipient.getId(), messageProfileKey)) {
            log(content.getTimestamp(), "Profile key on message from " + senderRecipient.getId() + " didn't match our local store. It has been updated.");
            ApplicationDependencies.getJobManager().add(RetrieveProfileJob.forRecipient(senderRecipient.getId()));
        }
    } else {
        warn(String.valueOf(content.getTimestamp()), "Ignored invalid profile key seen in message");
    }
}
Also used : RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Aggregations

ProfileKey (org.signal.zkgroup.profiles.ProfileKey)150 Test (org.junit.Test)102 UUID (java.util.UUID)90 DecryptedGroup (org.signal.storageservice.protos.groups.local.DecryptedGroup)50 ProtoTestUtils.randomProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.randomProfileKey)50 DecryptedGroupChange (org.signal.storageservice.protos.groups.local.DecryptedGroupChange)34 ProtoTestUtils.newProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.newProfileKey)28 ProtoTestUtils.withProfileKey (org.whispersystems.signalservice.api.groupsv2.ProtoTestUtils.withProfileKey)28 IOException (java.io.IOException)24 GroupChange (org.signal.storageservice.protos.groups.GroupChange)14 DecryptedMember (org.signal.storageservice.protos.groups.local.DecryptedMember)14 InvalidCiphertextException (org.whispersystems.signalservice.api.crypto.InvalidCiphertextException)12 InvalidInputException (org.signal.zkgroup.InvalidInputException)8 ProfileKeyCredential (org.signal.zkgroup.profiles.ProfileKeyCredential)8 Recipient (org.thoughtcrime.securesms.recipients.Recipient)8 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)8 NonNull (androidx.annotation.NonNull)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 RecipientDatabase (org.thoughtcrime.securesms.database.RecipientDatabase)6 IdentityKey (org.whispersystems.libsignal.IdentityKey)6