Search in sources :

Example 6 with SignalServiceProfile

use of org.whispersystems.signalservice.api.profiles.SignalServiceProfile in project Signal-Android by WhisperSystems.

the class UsernameUtil method fetchAciForUsername.

@WorkerThread
@NonNull
public static Optional<ServiceId> fetchAciForUsername(@NonNull String username) {
    Optional<RecipientId> localId = SignalDatabase.recipients().getByUsername(username);
    if (localId.isPresent()) {
        Recipient recipient = Recipient.resolved(localId.get());
        if (recipient.getServiceId().isPresent()) {
            Log.i(TAG, "Found username locally -- using associated UUID.");
            return recipient.getServiceId();
        } else {
            Log.w(TAG, "Found username locally, but it had no associated UUID! Clearing it.");
            SignalDatabase.recipients().clearUsernameIfExists(username);
        }
    }
    try {
        Log.d(TAG, "No local user with this username. Searching remotely.");
        SignalServiceProfile profile = ApplicationDependencies.getSignalServiceMessageReceiver().retrieveProfileByUsername(username, Optional.absent(), Locale.getDefault());
        return Optional.fromNullable(profile.getAci());
    } catch (IOException e) {
        return Optional.absent();
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IOException(java.io.IOException) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 7 with SignalServiceProfile

use of org.whispersystems.signalservice.api.profiles.SignalServiceProfile in project Signal-Android by signalapp.

the class RetrieveProfileJob method handleIndividualRecipient.

private void handleIndividualRecipient(Recipient recipient) throws IOException, InvalidKeyException, InvalidNumberException {
    String number = recipient.getAddress().toPhoneString();
    SignalServiceProfile profile = retrieveProfile(number);
    setIdentityKey(recipient, profile.getIdentityKey());
    setProfileName(recipient, profile.getName());
    setProfileAvatar(recipient, profile.getAvatar());
}
Also used : SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile)

Example 8 with SignalServiceProfile

use of org.whispersystems.signalservice.api.profiles.SignalServiceProfile in project Signal-Android by signalapp.

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 9 with SignalServiceProfile

use of org.whispersystems.signalservice.api.profiles.SignalServiceProfile in project Signal-Android by signalapp.

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)

Aggregations

SignalServiceProfile (org.whispersystems.signalservice.api.profiles.SignalServiceProfile)9 NonNull (androidx.annotation.NonNull)4 WorkerThread (androidx.annotation.WorkerThread)4 IOException (java.io.IOException)4 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)4 ProfileKeyCredential (org.signal.zkgroup.profiles.ProfileKeyCredential)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)4 ProfileAndCredential (org.whispersystems.signalservice.api.profiles.ProfileAndCredential)4 MobileCoinPublicAddress (org.thoughtcrime.securesms.payments.MobileCoinPublicAddress)2 PaymentsAddressException (org.thoughtcrime.securesms.payments.PaymentsAddressException)2 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)2 IdentityKey (org.whispersystems.libsignal.IdentityKey)2 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2 InvalidCiphertextException (org.whispersystems.signalservice.api.crypto.InvalidCiphertextException)2 ProfileCipher (org.whispersystems.signalservice.api.crypto.ProfileCipher)2 SignalServiceProtos (org.whispersystems.signalservice.internal.push.SignalServiceProtos)2