Search in sources :

Example 1 with SignalIdentityKeyStore

use of org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore 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 2 with SignalIdentityKeyStore

use of org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore 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 3 with SignalIdentityKeyStore

use of org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore in project Signal-Android by WhisperSystems.

the class ApplicationDependencyProvider method provideProtocolStore.

@Override
@NonNull
public SignalServiceDataStoreImpl provideProtocolStore() {
    ACI localAci = SignalStore.account().getAci();
    PNI localPni = SignalStore.account().getPni();
    if (localAci == null) {
        throw new IllegalStateException("No ACI set!");
    }
    if (localPni == null) {
        throw new IllegalStateException("No PNI set!");
    }
    if (!SignalStore.account().hasPniIdentityKey()) {
        SignalStore.account().generatePniIdentityKeyIfNecessary();
        CreateSignedPreKeyJob.enqueueIfNeeded();
    }
    SignalBaseIdentityKeyStore baseIdentityStore = new SignalBaseIdentityKeyStore(context);
    SignalServiceAccountDataStoreImpl aciStore = new SignalServiceAccountDataStoreImpl(context, new TextSecurePreKeyStore(localAci), new SignalIdentityKeyStore(baseIdentityStore, () -> SignalStore.account().getAciIdentityKey()), new TextSecureSessionStore(localAci), new SignalSenderKeyStore(context));
    SignalServiceAccountDataStoreImpl pniStore = new SignalServiceAccountDataStoreImpl(context, new TextSecurePreKeyStore(localPni), new SignalIdentityKeyStore(baseIdentityStore, () -> SignalStore.account().getPniIdentityKey()), new TextSecureSessionStore(localPni), new SignalSenderKeyStore(context));
    return new SignalServiceDataStoreImpl(context, aciStore, pniStore);
}
Also used : TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) TextSecurePreKeyStore(org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore) ACI(org.whispersystems.signalservice.api.push.ACI) SignalSenderKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalSenderKeyStore) PNI(org.whispersystems.signalservice.api.push.PNI) SignalIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore) SignalBaseIdentityKeyStore(org.thoughtcrime.securesms.crypto.storage.SignalBaseIdentityKeyStore) SignalServiceAccountDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl) SignalServiceDataStoreImpl(org.thoughtcrime.securesms.crypto.storage.SignalServiceDataStoreImpl) NonNull(androidx.annotation.NonNull)

Example 4 with SignalIdentityKeyStore

use of org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore 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)

Aggregations

SignalIdentityKeyStore (org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore)4 IdentityRecord (org.thoughtcrime.securesms.database.model.IdentityRecord)3 SignalSessionLock (org.whispersystems.signalservice.api.SignalSessionLock)3 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 SignalBaseIdentityKeyStore (org.thoughtcrime.securesms.crypto.storage.SignalBaseIdentityKeyStore)1 SignalSenderKeyStore (org.thoughtcrime.securesms.crypto.storage.SignalSenderKeyStore)1 SignalServiceAccountDataStoreImpl (org.thoughtcrime.securesms.crypto.storage.SignalServiceAccountDataStoreImpl)1 SignalServiceDataStoreImpl (org.thoughtcrime.securesms.crypto.storage.SignalServiceDataStoreImpl)1 TextSecurePreKeyStore (org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore)1 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1 ACI (org.whispersystems.signalservice.api.push.ACI)1 PNI (org.whispersystems.signalservice.api.push.PNI)1