Search in sources :

Example 11 with InvalidCiphertextException

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);
    }
}
Also used : DiscoveryResponse(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse) InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) HashMap(java.util.HashMap) ACI(org.whispersystems.signalservice.api.push.ACI) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) DataInputStream(java.io.DataInputStream) RemoteAttestation(org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation) ByteArrayInputStream(java.io.ByteArrayInputStream) UnauthenticatedResponseException(org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException) DiscoveryRequest(org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest) UUID(java.util.UUID)

Example 12 with InvalidCiphertextException

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);
    }
}
Also used : InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) ProfileName(org.thoughtcrime.securesms.profiles.ProfileName) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 13 with InvalidCiphertextException

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);
    }
}
Also used : InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 14 with InvalidCiphertextException

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);
    }
}
Also used : InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) ProfileName(org.thoughtcrime.securesms.profiles.ProfileName) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 15 with InvalidCiphertextException

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);
    }
}
Also used : InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Aggregations

InvalidCiphertextException (org.whispersystems.signalservice.api.crypto.InvalidCiphertextException)16 IOException (java.io.IOException)10 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)10 ProfileName (org.thoughtcrime.securesms.profiles.ProfileName)4 ByteString (com.google.protobuf.ByteString)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 BadPaddingException (javax.crypto.BadPaddingException)3 Cipher (javax.crypto.Cipher)3 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)3 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)3 GCMParameterSpec (javax.crypto.spec.GCMParameterSpec)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 RemoteAttestation (org.whispersystems.signalservice.internal.contacts.crypto.RemoteAttestation)3 UnauthenticatedResponseException (org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException)3 DiscoveryRequest (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest)3 DiscoveryResponse (org.whispersystems.signalservice.internal.contacts.entities.DiscoveryResponse)3 NonNull (androidx.annotation.NonNull)2 WorkerThread (androidx.annotation.WorkerThread)2