Search in sources :

Example 1 with IdentityRecord

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

the class IdentityDatabase method getIdentityRecord.

@NonNull
private static IdentityRecord getIdentityRecord(@NonNull Cursor cursor) throws IOException, InvalidKeyException {
    String addressName = CursorUtil.requireString(cursor, ADDRESS);
    String serializedIdentity = CursorUtil.requireString(cursor, IDENTITY_KEY);
    long timestamp = CursorUtil.requireLong(cursor, TIMESTAMP);
    int verifiedStatus = CursorUtil.requireInt(cursor, VERIFIED);
    boolean nonblockingApproval = CursorUtil.requireBoolean(cursor, NONBLOCKING_APPROVAL);
    boolean firstUse = CursorUtil.requireBoolean(cursor, FIRST_USE);
    IdentityKey identity = new IdentityKey(Base64.decode(serializedIdentity), 0);
    return new IdentityRecord(RecipientId.fromExternalPush(addressName), identity, VerifiedStatus.forState(verifiedStatus), firstUse, timestamp, nonblockingApproval);
}
Also used : IdentityKey(org.whispersystems.libsignal.IdentityKey) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) NonNull(androidx.annotation.NonNull)

Example 2 with IdentityRecord

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

the class MultiDeviceContactUpdateJob method generateFullContactUpdate.

private void generateFullContactUpdate() throws IOException, UntrustedIdentityException, NetworkException {
    boolean isAppVisible = ApplicationDependencies.getAppForegroundObserver().isForegrounded();
    long timeSinceLastSync = System.currentTimeMillis() - TextSecurePreferences.getLastFullContactSyncTime(context);
    Log.d(TAG, "Requesting a full contact sync. forced = " + forceSync + ", appVisible = " + isAppVisible + ", timeSinceLastSync = " + timeSinceLastSync + " ms");
    if (!forceSync && !isAppVisible && timeSinceLastSync < FULL_SYNC_TIME) {
        Log.i(TAG, "App is backgrounded and the last contact sync was too soon (" + timeSinceLastSync + " ms ago). Marking that we need a sync. Skipping multi-device contact update...");
        TextSecurePreferences.setNeedsFullContactSync(context, true);
        return;
    }
    TextSecurePreferences.setLastFullContactSyncTime(context, System.currentTimeMillis());
    TextSecurePreferences.setNeedsFullContactSync(context, false);
    WriteDetails writeDetails = createTempFile();
    try {
        DeviceContactsOutputStream out = new DeviceContactsOutputStream(writeDetails.outputStream);
        List<Recipient> recipients = SignalDatabase.recipients().getRecipientsForMultiDeviceSync();
        Map<RecipientId, Integer> inboxPositions = SignalDatabase.threads().getInboxPositions();
        Set<RecipientId> archived = SignalDatabase.threads().getArchivedRecipients();
        for (Recipient recipient : recipients) {
            Optional<IdentityRecord> identity = ApplicationDependencies.getProtocolStore().aci().identities().getIdentityRecord(recipient.getId());
            Optional<VerifiedMessage> verified = getVerifiedMessage(recipient, identity);
            Optional<String> name = Optional.fromNullable(recipient.isSystemContact() ? recipient.getDisplayName(context) : recipient.getGroupName(context));
            Optional<ProfileKey> profileKey = ProfileKeyUtil.profileKeyOptional(recipient.getProfileKey());
            boolean blocked = recipient.isBlocked();
            Optional<Integer> expireTimer = recipient.getExpiresInSeconds() > 0 ? Optional.of(recipient.getExpiresInSeconds()) : Optional.absent();
            Optional<Integer> inboxPosition = Optional.fromNullable(inboxPositions.get(recipient.getId()));
            out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, recipient), name, getAvatar(recipient.getId(), recipient.getContactUri()), Optional.of(ChatColorsMapper.getMaterialColor(recipient.getChatColors()).serialize()), verified, profileKey, blocked, expireTimer, inboxPosition, archived.contains(recipient.getId())));
        }
        Recipient self = Recipient.self();
        byte[] profileKey = self.getProfileKey();
        if (profileKey != null) {
            out.write(new DeviceContact(RecipientUtil.toSignalServiceAddress(context, self), Optional.absent(), Optional.absent(), Optional.of(ChatColorsMapper.getMaterialColor(self.getChatColors()).serialize()), Optional.absent(), ProfileKeyUtil.profileKeyOptionalOrThrow(self.getProfileKey()), false, self.getExpiresInSeconds() > 0 ? Optional.of(self.getExpiresInSeconds()) : Optional.absent(), Optional.fromNullable(inboxPositions.get(self.getId())), archived.contains(self.getId())));
        }
        out.close();
        long length = BlobProvider.getInstance().calculateFileSize(context, writeDetails.uri);
        sendUpdate(ApplicationDependencies.getSignalServiceMessageSender(), BlobProvider.getInstance().getStream(context, writeDetails.uri), length, true);
    } 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) ProfileKey(org.signal.zkgroup.profiles.ProfileKey) VerifiedMessage(org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage)

Example 3 with IdentityRecord

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

the class SafetyNumberChangeRepository method trustOrVerifyChangedRecipientsInternal.

@WorkerThread
private TrustAndVerifyResult trustOrVerifyChangedRecipientsInternal(@NonNull List<ChangedRecipient> changedRecipients) {
    SignalIdentityKeyStore identityStore = ApplicationDependencies.getProtocolStore().aci().identities();
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        for (ChangedRecipient changedRecipient : changedRecipients) {
            IdentityRecord identityRecord = changedRecipient.getIdentityRecord();
            if (changedRecipient.isUnverified()) {
                Log.d(TAG, "Setting " + identityRecord.getRecipientId() + " as verified");
                ApplicationDependencies.getProtocolStore().aci().identities().setVerified(identityRecord.getRecipientId(), identityRecord.getIdentityKey(), IdentityDatabase.VerifiedStatus.DEFAULT);
            } else {
                Log.d(TAG, "Setting " + identityRecord.getRecipientId() + " as approved");
                identityStore.setApproval(identityRecord.getRecipientId(), true);
            }
        }
    }
    return TrustAndVerifyResult.trustAndVerify(changedRecipients);
}
Also used : SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) WorkerThread(androidx.annotation.WorkerThread)

Example 4 with IdentityRecord

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

the class UntrustedSendDialog method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    final SignalIdentityKeyStore identityStore = ApplicationDependencies.getProtocolStore().aci().identities();
    SimpleTask.run(() -> {
        try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
            for (IdentityRecord identityRecord : untrustedRecords) {
                identityStore.setApproval(identityRecord.getRecipientId(), true);
            }
        }
        return null;
    }, unused -> resendListener.onResendMessage());
}
Also used : SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore)

Example 5 with IdentityRecord

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

the class SafetyNumberChangeRepository method trustOrVerifyChangedRecipientsInternal.

@WorkerThread
private TrustAndVerifyResult trustOrVerifyChangedRecipientsInternal(@NonNull List<ChangedRecipient> changedRecipients) {
    SignalIdentityKeyStore identityStore = ApplicationDependencies.getProtocolStore().aci().identities();
    try (SignalSessionLock.Lock unused = ReentrantSessionLock.INSTANCE.acquire()) {
        for (ChangedRecipient changedRecipient : changedRecipients) {
            IdentityRecord identityRecord = changedRecipient.getIdentityRecord();
            if (changedRecipient.isUnverified()) {
                Log.d(TAG, "Setting " + identityRecord.getRecipientId() + " as verified");
                ApplicationDependencies.getProtocolStore().aci().identities().setVerified(identityRecord.getRecipientId(), identityRecord.getIdentityKey(), IdentityDatabase.VerifiedStatus.DEFAULT);
            } else {
                Log.d(TAG, "Setting " + identityRecord.getRecipientId() + " as approved");
                identityStore.setApproval(identityRecord.getRecipientId(), true);
            }
        }
    }
    return TrustAndVerifyResult.trustAndVerify(changedRecipients);
}
Also used : SignalSessionLock(org.whispersystems.signalservice.api.SignalSessionLock) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) WorkerThread(androidx.annotation.WorkerThread)

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