use of org.whispersystems.signalservice.api.crypto.InvalidCiphertextException in project Signal-Android by signalapp.
the class SignalServiceAccountManager method getRegisteredUsers.
@SuppressWarnings("SameParameterValue")
public Map<String, ACI> getRegisteredUsers(KeyStore iasKeyStore, Set<String> e164numbers, String mrenclave) throws IOException, Quote.InvalidQuoteFormatException, UnauthenticatedQuoteException, SignatureException, UnauthenticatedResponseException, InvalidKeyException {
if (e164numbers.isEmpty()) {
return Collections.emptyMap();
}
try {
String authorization = this.pushServiceSocket.getContactDiscoveryAuthorization();
Map<String, RemoteAttestation> attestations = RemoteAttestationUtil.getAndVerifyMultiRemoteAttestation(pushServiceSocket, PushServiceSocket.ClientSet.ContactDiscovery, iasKeyStore, mrenclave, mrenclave, authorization);
List<String> addressBook = new ArrayList<>(e164numbers.size());
for (String e164number : e164numbers) {
addressBook.add(e164number.substring(1));
}
List<String> cookies = attestations.values().iterator().next().getCookies();
DiscoveryRequest request = ContactDiscoveryCipher.createDiscoveryRequest(addressBook, attestations);
DiscoveryResponse response = this.pushServiceSocket.getContactDiscoveryRegisteredUsers(authorization, request, cookies, mrenclave);
byte[] data = ContactDiscoveryCipher.getDiscoveryResponseData(response, attestations.values());
HashMap<String, ACI> results = new HashMap<>(addressBook.size());
DataInputStream uuidInputStream = new DataInputStream(new ByteArrayInputStream(data));
for (String candidate : addressBook) {
long candidateUuidHigh = uuidInputStream.readLong();
long candidateUuidLow = uuidInputStream.readLong();
if (candidateUuidHigh != 0 || candidateUuidLow != 0) {
results.put('+' + candidate, ACI.from(new UUID(candidateUuidHigh, candidateUuidLow)));
}
}
return results;
} catch (InvalidCiphertextException e) {
throw new UnauthenticatedResponseException(e);
}
}
use of org.whispersystems.signalservice.api.crypto.InvalidCiphertextException in project Signal-Android by signalapp.
the class RetrieveProfileJob method setProfileName.
private void setProfileName(Recipient recipient, String profileName) {
try {
ProfileKey profileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
if (profileKey == null)
return;
String plaintextProfileName = Util.emptyIfNull(ProfileUtil.decryptString(profileKey, profileName));
ProfileName remoteProfileName = ProfileName.fromSerialized(plaintextProfileName);
ProfileName localProfileName = recipient.getProfileName();
if (!remoteProfileName.equals(localProfileName)) {
Log.i(TAG, "Profile name updated. Writing new value.");
SignalDatabase.recipients().setProfileName(recipient.getId(), remoteProfileName);
String remoteDisplayName = remoteProfileName.toString();
String localDisplayName = localProfileName.toString();
if (!recipient.isBlocked() && !recipient.isGroup() && !recipient.isSelf() && !localDisplayName.isEmpty() && !remoteDisplayName.equals(localDisplayName)) {
Log.i(TAG, "Writing a profile name change event for " + recipient.getId());
SignalDatabase.sms().insertProfileNameChangeMessages(recipient, remoteDisplayName, localDisplayName);
} else {
Log.i(TAG, String.format(Locale.US, "Name changed, but wasn't relevant to write an event. blocked: %s, group: %s, self: %s, firstSet: %s, displayChange: %s", recipient.isBlocked(), recipient.isGroup(), recipient.isSelf(), localDisplayName.isEmpty(), !remoteDisplayName.equals(localDisplayName)));
}
}
if (TextUtils.isEmpty(plaintextProfileName)) {
Log.i(TAG, "No profile name set for " + recipient.getId());
}
} catch (InvalidCiphertextException e) {
Log.w(TAG, "Bad profile key for " + recipient.getId());
} catch (IOException e) {
Log.w(TAG, e);
}
}
use of org.whispersystems.signalservice.api.crypto.InvalidCiphertextException in project Signal-Android by signalapp.
the class RetrieveProfileJob method setProfileAbout.
private void setProfileAbout(@NonNull Recipient recipient, @Nullable String encryptedAbout, @Nullable String encryptedEmoji) {
try {
ProfileKey profileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
if (profileKey == null)
return;
String plaintextAbout = ProfileUtil.decryptString(profileKey, encryptedAbout);
String plaintextEmoji = ProfileUtil.decryptString(profileKey, encryptedEmoji);
SignalDatabase.recipients().setAbout(recipient.getId(), plaintextAbout, plaintextEmoji);
} catch (InvalidCiphertextException | IOException e) {
Log.w(TAG, e);
}
}
use of org.whispersystems.signalservice.api.crypto.InvalidCiphertextException in project Signal-Android by signalapp.
the class RefreshOwnProfileJob method setProfileName.
private void setProfileName(@Nullable String encryptedName) {
try {
ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
String plaintextName = ProfileUtil.decryptString(profileKey, encryptedName);
ProfileName profileName = ProfileName.fromSerialized(plaintextName);
Log.d(TAG, "Saving " + (!Util.isEmpty(plaintextName) ? "non-" : "") + "empty name.");
SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
} catch (InvalidCiphertextException | IOException e) {
Log.w(TAG, e);
}
}
use of org.whispersystems.signalservice.api.crypto.InvalidCiphertextException in project Signal-Android by signalapp.
the class RefreshOwnProfileJob method setProfileAbout.
private void setProfileAbout(@Nullable String encryptedAbout, @Nullable String encryptedEmoji) {
try {
ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
String plaintextAbout = ProfileUtil.decryptString(profileKey, encryptedAbout);
String plaintextEmoji = ProfileUtil.decryptString(profileKey, encryptedEmoji);
Log.d(TAG, "Saving " + (!Util.isEmpty(plaintextAbout) ? "non-" : "") + "empty about.");
Log.d(TAG, "Saving " + (!Util.isEmpty(plaintextEmoji) ? "non-" : "") + "empty emoji.");
SignalDatabase.recipients().setAbout(Recipient.self().getId(), plaintextAbout, plaintextEmoji);
} catch (InvalidCiphertextException | IOException e) {
Log.w(TAG, e);
}
}
Aggregations