Search in sources :

Example 71 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.

the class MessageContentProcessor method handleSenderKeyRetryReceipt.

private void handleSenderKeyRetryReceipt(@NonNull Recipient requester, @Nullable MessageLogEntry messageLogEntry, @NonNull SignalServiceContent content, @NonNull DecryptionErrorMessage decryptionErrorMessage) {
    long sentTimestamp = decryptionErrorMessage.getTimestamp();
    MessageRecord relatedMessage = findRetryReceiptRelatedMessage(context, messageLogEntry, sentTimestamp);
    if (relatedMessage == null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] The related message could not be found! There shouldn't be any sender key resends where we can't find the related message. Skipping.");
        return;
    }
    Recipient threadRecipient = SignalDatabase.threads().getRecipientForThreadId(relatedMessage.getThreadId());
    if (threadRecipient == null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a thread recipient! Skipping.");
        return;
    }
    if (!threadRecipient.isPushV2Group()) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Thread recipient is not a v2 group! Skipping.");
        return;
    }
    GroupId.V2 groupId = threadRecipient.requireGroupId().requireV2();
    DistributionId distributionId = SignalDatabase.groups().getOrCreateDistributionId(groupId);
    SignalProtocolAddress requesterAddress = new SignalProtocolAddress(requester.requireServiceId().toString(), content.getSenderDevice());
    SignalDatabase.senderKeyShared().delete(distributionId, Collections.singleton(requesterAddress));
    if (messageLogEntry != null) {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Found MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ". Scheduling a resend.");
        ApplicationDependencies.getJobManager().add(new ResendMessageJob(messageLogEntry.getRecipientId(), messageLogEntry.getDateSent(), messageLogEntry.getContent(), messageLogEntry.getContentHint(), groupId, distributionId));
    } else {
        warn(content.getTimestamp(), "[RetryReceipt-SK] Unable to find MSL entry for " + requester.getId() + " (" + requesterAddress + ") with timestamp " + sentTimestamp + ".");
        Optional<GroupRecord> groupRecord = SignalDatabase.groups().getGroup(groupId);
        if (!groupRecord.isPresent()) {
            warn(content.getTimestamp(), "[RetryReceipt-SK] Could not find a record for the group!");
            return;
        }
        if (!groupRecord.get().getMembers().contains(requester.getId())) {
            warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is not in the group, so we cannot send them a SenderKeyDistributionMessage.");
            return;
        }
        warn(content.getTimestamp(), "[RetryReceipt-SK] The requester is in the group, so we'll send them a SenderKeyDistributionMessage.");
        ApplicationDependencies.getJobManager().add(new SenderKeyDistributionSendJob(requester.getId(), groupRecord.get().getId().requireV2()));
    }
}
Also used : SenderKeyDistributionSendJob(org.thoughtcrime.securesms.jobs.SenderKeyDistributionSendJob) ResendMessageJob(org.thoughtcrime.securesms.jobs.ResendMessageJob) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) DistributionId(org.whispersystems.signalservice.api.push.DistributionId) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) GroupId(org.thoughtcrime.securesms.groups.GroupId)

Example 72 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.

the class IdentityUtil method saveIdentity.

public static void saveIdentity(String user, IdentityKey identityKey) {
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        SessionStore sessionStore = ApplicationDependencies.getProtocolStore().aci();
        SignalProtocolAddress address = new SignalProtocolAddress(user, SignalServiceAddress.DEFAULT_DEVICE_ID);
        if (ApplicationDependencies.getProtocolStore().aci().identities().saveIdentity(address, identityKey)) {
            if (sessionStore.containsSession(address)) {
                SessionRecord sessionRecord = sessionStore.loadSession(address);
                sessionRecord.archiveCurrentState();
                sessionStore.storeSession(address, sessionRecord);
            }
        }
    }
}
Also used : SessionStore(org.whispersystems.libsignal.state.SessionStore) SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord)

Example 73 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.

the class TextSecureSessionStore method archiveSiblingSessions.

public void archiveSiblingSessions(@NonNull SignalProtocolAddress address) {
    synchronized (LOCK) {
        List<SessionDatabase.SessionRow> sessions = SignalDatabase.sessions().getAllFor(accountId, address.getName());
        for (SessionDatabase.SessionRow row : sessions) {
            if (row.getDeviceId() != address.getDeviceId()) {
                row.getRecord().archiveCurrentState();
                storeSession(new SignalProtocolAddress(row.getAddress(), row.getDeviceId()), row.getRecord());
            }
        }
    }
}
Also used : SessionDatabase(org.thoughtcrime.securesms.database.SessionDatabase) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Example 74 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project Signal-Android by signalapp.

the class SafetyNumberChangeRepository method trustOrVerifyChangedRecipientsAndResendInternal.

@WorkerThread
private TrustAndVerifyResult trustOrVerifyChangedRecipientsAndResendInternal(@NonNull List<ChangedRecipient> changedRecipients, @NonNull MessageRecord messageRecord) {
    if (changedRecipients.isEmpty()) {
        Log.d(TAG, "No changed recipients to process, will still process message record");
    }
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        for (ChangedRecipient changedRecipient : changedRecipients) {
            SignalProtocolAddress mismatchAddress = changedRecipient.getRecipient().requireServiceId().toProtocolAddress(SignalServiceAddress.DEFAULT_DEVICE_ID);
            Log.d(TAG, "Saving identity for: " + changedRecipient.getRecipient().getId() + " " + changedRecipient.getIdentityRecord().getIdentityKey().hashCode());
            SignalIdentityKeyStore.SaveResult result = ApplicationDependencies.getProtocolStore().aci().identities().saveIdentity(mismatchAddress, changedRecipient.getIdentityRecord().getIdentityKey(), true);
            Log.d(TAG, "Saving identity result: " + result);
            if (result == SignalIdentityKeyStore.SaveResult.NO_CHANGE) {
                Log.i(TAG, "Archiving sessions explicitly as they appear to be out of sync.");
                ApplicationDependencies.getProtocolStore().aci().sessions().archiveSession(changedRecipient.getRecipient().getId(), SignalServiceAddress.DEFAULT_DEVICE_ID);
                ApplicationDependencies.getProtocolStore().aci().sessions().archiveSiblingSessions(mismatchAddress);
                SignalDatabase.senderKeyShared().deleteAllFor(changedRecipient.getRecipient().getId());
            }
        }
    }
    if (messageRecord.isOutgoing()) {
        processOutgoingMessageRecord(changedRecipients, messageRecord);
    }
    return TrustAndVerifyResult.trustVerifyAndResend(changedRecipients, messageRecord);
}
Also used : SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) WorkerThread(androidx.annotation.WorkerThread)

Example 75 with SignalProtocolAddress

use of org.whispersystems.libsignal.SignalProtocolAddress in project libsignal-service-java by signalapp.

the class SignalServiceCipher method getPreferredProtocolAddress.

private static SignalProtocolAddress getPreferredProtocolAddress(SignalProtocolStore store, SignalServiceAddress address, int sourceDevice) {
    SignalProtocolAddress uuidAddress = address.getUuid().isPresent() ? new SignalProtocolAddress(address.getUuid().get().toString(), sourceDevice) : null;
    SignalProtocolAddress e164Address = address.getNumber().isPresent() ? new SignalProtocolAddress(address.getNumber().get(), sourceDevice) : null;
    if (uuidAddress != null && store.containsSession(uuidAddress)) {
        return uuidAddress;
    } else if (e164Address != null && store.containsSession(e164Address)) {
        return e164Address;
    } else {
        return new SignalProtocolAddress(address.getIdentifier(), sourceDevice);
    }
}
Also used : SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress)

Aggregations

SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)77 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)14 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)11 SignalServiceAddress (org.whispersystems.signalservice.api.push.SignalServiceAddress)11 ArrayList (java.util.ArrayList)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 IOException (java.io.IOException)9 SessionBuilder (org.whispersystems.libsignal.SessionBuilder)9 Optional (org.whispersystems.libsignal.util.guava.Optional)9 UntrustedIdentityException (org.whispersystems.signalservice.api.crypto.UntrustedIdentityException)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 List (java.util.List)8 ContentHint (org.whispersystems.signalservice.api.crypto.ContentHint)8 DistributionId (org.whispersystems.signalservice.api.push.DistributionId)8 NonNull (androidx.annotation.NonNull)6 LinkedList (java.util.LinkedList)6 Collectors (java.util.stream.Collectors)6 SenderKeyDistributionMessage (org.whispersystems.libsignal.protocol.SenderKeyDistributionMessage)6 SignalServiceMessageSender (org.whispersystems.signalservice.api.SignalServiceMessageSender)6