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