Search in sources :

Example 6 with IdentityRecord

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

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 7 with IdentityRecord

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

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 8 with IdentityRecord

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

the class IdentityDatabase method saveIdentityInternal.

private void saveIdentityInternal(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus, boolean firstUse, long timestamp, boolean nonBlockingApproval) {
    SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
    String identityKeyString = Base64.encodeBytes(identityKey.serialize());
    ContentValues contentValues = new ContentValues();
    contentValues.put(ADDRESS, addressName);
    contentValues.put(IDENTITY_KEY, identityKeyString);
    contentValues.put(TIMESTAMP, timestamp);
    contentValues.put(VERIFIED, verifiedStatus.toInt());
    contentValues.put(NONBLOCKING_APPROVAL, nonBlockingApproval ? 1 : 0);
    contentValues.put(FIRST_USE, firstUse ? 1 : 0);
    database.replace(TABLE_NAME, null, contentValues);
    EventBus.getDefault().post(new IdentityRecord(recipientId, identityKey, verifiedStatus, firstUse, timestamp, nonBlockingApproval));
}
Also used : ContentValues(android.content.ContentValues) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord)

Example 9 with IdentityRecord

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

the class IdentityDatabase method setVerified.

public void setVerified(@NonNull String addressName, @NonNull RecipientId recipientId, IdentityKey identityKey, VerifiedStatus verifiedStatus) {
    SQLiteDatabase database = databaseHelper.getSignalWritableDatabase();
    String query = ADDRESS + " = ? AND " + IDENTITY_KEY + " = ?";
    String[] args = SqlUtil.buildArgs(addressName, Base64.encodeBytes(identityKey.serialize()));
    ContentValues contentValues = new ContentValues(1);
    contentValues.put(VERIFIED, verifiedStatus.toInt());
    int updated = database.update(TABLE_NAME, contentValues, query, args);
    if (updated > 0) {
        Optional<IdentityRecord> record = getIdentityRecord(addressName);
        if (record.isPresent())
            EventBus.getDefault().post(record.get());
        SignalDatabase.recipients().markNeedsSync(recipientId);
    }
}
Also used : ContentValues(android.content.ContentValues) IdentityRecord(org.thoughtcrime.securesms.database.model.IdentityRecord)

Example 10 with IdentityRecord

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

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)

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