Search in sources :

Example 11 with IdentityRecord

use of org.thoughtcrime.securesms.database.model.IdentityRecord in project Signal-Android by signalapp.

the class MultiDeviceContactUpdateJob method generateSingleContactUpdate.

private void generateSingleContactUpdate(@NonNull RecipientId recipientId) throws IOException, UntrustedIdentityException, NetworkException {
    WriteDetails writeDetails = createTempFile();
    try {
        DeviceContactsOutputStream out = new DeviceContactsOutputStream(writeDetails.outputStream);
        Recipient recipient = Recipient.resolved(recipientId);
        if (recipient.getRegistered() == RecipientDatabase.RegisteredState.NOT_REGISTERED) {
            Log.w(TAG, recipientId + " not registered!");
            return;
        }
        Optional<IdentityRecord> identityRecord = ApplicationDependencies.getProtocolStore().aci().identities().getIdentityRecord(recipient.getId());
        Optional<VerifiedMessage> verifiedMessage = getVerifiedMessage(recipient, identityRecord);
        Map<RecipientId, Integer> inboxPositions = SignalDatabase.threads().getInboxPositions();
        Set<RecipientId> archived = SignalDatabase.threads().getArchivedRecipients();
        out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, recipient), Optional.fromNullable(recipient.isGroup() || recipient.isSystemContact() ? recipient.getDisplayName(context) : null), getAvatar(recipient.getId(), recipient.getContactUri()), Optional.of(ChatColorsMapper.getMaterialColor(recipient.getChatColors()).serialize()), verifiedMessage, ProfileKeyUtil.profileKeyOptional(recipient.getProfileKey()), recipient.isBlocked(), recipient.getExpiresInSeconds() > 0 ? Optional.of(recipient.getExpiresInSeconds()) : Optional.absent(), Optional.fromNullable(inboxPositions.get(recipientId)), archived.contains(recipientId)));
        out.close();
        long length = BlobProvider.getInstance().calculateFileSize(context, writeDetails.uri);
        sendUpdate(ApplicationDependencies.getSignalServiceMessageSender(), BlobProvider.getInstance().getStream(context, writeDetails.uri), length, false);
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
    } finally {
        BlobProvider.getInstance().delete(context, writeDetails.uri);
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)

Example 12 with IdentityRecord

use of org.thoughtcrime.securesms.database.model.IdentityRecord in project Signal-Android by WhisperSystems.

the class WebRtcCallViewModel method startCall.

public void startCall(boolean isVideoCall) {
    callStarting = true;
    Recipient recipient = getRecipient().get();
    if (recipient.isGroup()) {
        repository.getIdentityRecords(recipient, identityRecords -> {
            if (identityRecords.isUntrusted(false) || identityRecords.isUnverified(false)) {
                List<IdentityRecord> records = identityRecords.getUnverifiedRecords();
                records.addAll(identityRecords.getUntrustedRecords());
                events.postValue(new Event.ShowGroupCallSafetyNumberChange(records));
            } else {
                events.postValue(new Event.StartCall(isVideoCall));
            }
        });
    } else {
        events.postValue(new Event.StartCall(isVideoCall));
    }
}
Also used : IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) SingleLiveEvent(org.thoughtcrime.securesms.util.SingleLiveEvent) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Example 13 with IdentityRecord

use of org.thoughtcrime.securesms.database.model.IdentityRecord in project Signal-Android by WhisperSystems.

the class MultiDeviceContactUpdateJob method generateSingleContactUpdate.

private void generateSingleContactUpdate(@NonNull RecipientId recipientId) throws IOException, UntrustedIdentityException, NetworkException {
    WriteDetails writeDetails = createTempFile();
    try {
        DeviceContactsOutputStream out = new DeviceContactsOutputStream(writeDetails.outputStream);
        Recipient recipient = Recipient.resolved(recipientId);
        if (recipient.getRegistered() == RecipientDatabase.RegisteredState.NOT_REGISTERED) {
            Log.w(TAG, recipientId + " not registered!");
            return;
        }
        Optional<IdentityRecord> identityRecord = ApplicationDependencies.getProtocolStore().aci().identities().getIdentityRecord(recipient.getId());
        Optional<VerifiedMessage> verifiedMessage = getVerifiedMessage(recipient, identityRecord);
        Map<RecipientId, Integer> inboxPositions = SignalDatabase.threads().getInboxPositions();
        Set<RecipientId> archived = SignalDatabase.threads().getArchivedRecipients();
        out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, recipient), Optional.fromNullable(recipient.isGroup() || recipient.isSystemContact() ? recipient.getDisplayName(context) : null), getAvatar(recipient.getId(), recipient.getContactUri()), Optional.of(ChatColorsMapper.getMaterialColor(recipient.getChatColors()).serialize()), verifiedMessage, ProfileKeyUtil.profileKeyOptional(recipient.getProfileKey()), recipient.isBlocked(), recipient.getExpiresInSeconds() > 0 ? Optional.of(recipient.getExpiresInSeconds()) : Optional.absent(), Optional.fromNullable(inboxPositions.get(recipientId)), archived.contains(recipientId)));
        out.close();
        long length = BlobProvider.getInstance().calculateFileSize(context, writeDetails.uri);
        sendUpdate(ApplicationDependencies.getSignalServiceMessageSender(), BlobProvider.getInstance().getStream(context, writeDetails.uri), length, false);
    } catch (InvalidNumberException e) {
        Log.w(TAG, e);
    } finally {
        BlobProvider.getInstance().delete(context, writeDetails.uri);
    }
}
Also used : DeviceContact(org.whispersystems.signalservice.api.messages.multidevice.DeviceContact) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) DeviceContactsOutputStream(org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream) InvalidNumberException(org.whispersystems.signalservice.api.util.InvalidNumberException) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)

Example 14 with IdentityRecord

use of org.thoughtcrime.securesms.database.model.IdentityRecord in project Signal-Android by WhisperSystems.

the class IdentityUtil method processVerifiedMessage.

public static void processVerifiedMessage(Context context, VerifiedMessage verifiedMessage) {
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        SignalIdentityKeyStore identityStore = ApplicationDependencies.getProtocolStore().aci().identities();
        Recipient recipient = Recipient.externalPush(verifiedMessage.getDestination());
        Optional<IdentityRecord> identityRecord = identityStore.getIdentityRecord(recipient.getId());
        if (!identityRecord.isPresent() && verifiedMessage.getVerified() == VerifiedMessage.VerifiedState.DEFAULT) {
            Log.w(TAG, "No existing record for default status");
            return;
        }
        if (verifiedMessage.getVerified() == VerifiedMessage.VerifiedState.DEFAULT && identityRecord.isPresent() && identityRecord.get().getIdentityKey().equals(verifiedMessage.getIdentityKey()) && identityRecord.get().getVerifiedStatus() != IdentityDatabase.VerifiedStatus.DEFAULT) {
            identityStore.setVerified(recipient.getId(), identityRecord.get().getIdentityKey(), IdentityDatabase.VerifiedStatus.DEFAULT);
            markIdentityVerified(context, recipient, false, true);
        }
        if (verifiedMessage.getVerified() == VerifiedMessage.VerifiedState.VERIFIED && (!identityRecord.isPresent() || (identityRecord.isPresent() && !identityRecord.get().getIdentityKey().equals(verifiedMessage.getIdentityKey())) || (identityRecord.isPresent() && identityRecord.get().getVerifiedStatus() != IdentityDatabase.VerifiedStatus.VERIFIED))) {
            saveIdentity(verifiedMessage.getDestination().getIdentifier(), verifiedMessage.getIdentityKey());
            identityStore.setVerified(recipient.getId(), verifiedMessage.getIdentityKey(), IdentityDatabase.VerifiedStatus.VERIFIED);
            markIdentityVerified(context, recipient, true, true);
        }
    }
}
Also used : SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Example 15 with IdentityRecord

use of org.thoughtcrime.securesms.database.model.IdentityRecord in project Signal-Android by WhisperSystems.

the class SignalBaseIdentityKeyStore method getIdentityRecords.

@NonNull
public IdentityRecordList getIdentityRecords(@NonNull List<Recipient> recipients) {
    List<String> addressNames = recipients.stream().filter(Recipient::hasServiceId).map(Recipient::requireServiceId).map(ServiceId::toString).collect(Collectors.toList());
    if (addressNames.isEmpty()) {
        return IdentityRecordList.EMPTY;
    }
    List<IdentityRecord> records = new ArrayList<>(recipients.size());
    for (Recipient recipient : recipients) {
        if (recipient.hasServiceId()) {
            IdentityStoreRecord record = cache.get(recipient.requireServiceId().toString());
            if (record != null) {
                records.add(record.toIdentityRecord(recipient.getId()));
            }
        } else {
            Log.w(TAG, "[getIdentityRecords] No serviceId for " + recipient.getId());
        }
    }
    return new IdentityRecordList(records);
}
Also used : IdentityRecordList(org.thoughtcrime.securesms.database.identity.IdentityRecordList) ArrayList(java.util.ArrayList) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) IdentityStoreRecord(org.thoughtcrime.securesms.database.model.IdentityStoreRecord) NonNull(androidx.annotation.NonNull)

Aggregations

IdentityRecord (org.thoughtcrime.securesms.database.model.IdentityRecord)20 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 SignalIdentityKeyStore (org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore)6 SignalSessionLock (org.whispersystems.signalservice.api.SignalSessionLock)6 ContentValues (android.content.ContentValues)4 NonNull (androidx.annotation.NonNull)4 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)4 DeviceContact (org.whispersystems.signalservice.api.messages.multidevice.DeviceContact)4 DeviceContactsOutputStream (org.whispersystems.signalservice.api.messages.multidevice.DeviceContactsOutputStream)4 VerifiedMessage (org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)4 InvalidNumberException (org.whispersystems.signalservice.api.util.InvalidNumberException)4 WorkerThread (androidx.annotation.WorkerThread)2 ArrayList (java.util.ArrayList)2 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)2 IdentityRecordList (org.thoughtcrime.securesms.database.identity.IdentityRecordList)2 IdentityStoreRecord (org.thoughtcrime.securesms.database.model.IdentityStoreRecord)2 LiveRecipient (org.thoughtcrime.securesms.recipients.LiveRecipient)2 SingleLiveEvent (org.thoughtcrime.securesms.util.SingleLiveEvent)2 IdentityKey (org.whispersystems.libsignal.IdentityKey)2