Search in sources :

Example 1 with VerifiedStatus

use of org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus in project Signal-Android by signalapp.

the class TextSecureIdentityKeyStore method saveIdentity.

public boolean saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
    synchronized (LOCK) {
        IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
        Address signalAddress = Address.fromExternal(context, address.getName());
        Optional<IdentityRecord> identityRecord = identityDatabase.getIdentity(signalAddress);
        if (!identityRecord.isPresent()) {
            Log.w(TAG, "Saving new identity...");
            identityDatabase.saveIdentity(signalAddress, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
            return false;
        }
        if (!identityRecord.get().getIdentityKey().equals(identityKey)) {
            Log.w(TAG, "Replacing existing identity...");
            VerifiedStatus verifiedStatus;
            if (identityRecord.get().getVerifiedStatus() == VerifiedStatus.VERIFIED || identityRecord.get().getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
                verifiedStatus = VerifiedStatus.UNVERIFIED;
            } else {
                verifiedStatus = VerifiedStatus.DEFAULT;
            }
            identityDatabase.saveIdentity(signalAddress, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
            IdentityUtil.markIdentityUpdate(context, Recipient.from(context, signalAddress, true));
            SessionUtil.archiveSiblingSessions(context, address);
            return true;
        }
        if (isNonBlockingApprovalRequired(identityRecord.get())) {
            Log.w(TAG, "Setting approval status...");
            identityDatabase.setApproval(signalAddress, nonBlockingApproval);
            return false;
        }
        return false;
    }
}
Also used : IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) VerifiedStatus(org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus) Address(org.thoughtcrime.securesms.database.Address) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) IdentityRecord(org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord)

Example 2 with VerifiedStatus

use of org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus in project Signal-Android by WhisperSystems.

the class SignalBaseIdentityKeyStore method saveIdentity.

@NonNull
public SaveResult saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
    synchronized (LOCK) {
        IdentityStoreRecord identityRecord = cache.get(address.getName());
        RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
        if (identityRecord == null) {
            Log.i(TAG, "Saving new identity...");
            cache.save(address.getName(), recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
            return SaveResult.NEW;
        }
        if (!identityRecord.getIdentityKey().equals(identityKey)) {
            Log.i(TAG, "Replacing existing identity... Existing: " + identityRecord.getIdentityKey().hashCode() + " New: " + identityKey.hashCode());
            VerifiedStatus verifiedStatus;
            if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED || identityRecord.getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
                verifiedStatus = VerifiedStatus.UNVERIFIED;
            } else {
                verifiedStatus = VerifiedStatus.DEFAULT;
            }
            cache.save(address.getName(), recipientId, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
            IdentityUtil.markIdentityUpdate(context, recipientId);
            ApplicationDependencies.getProtocolStore().aci().sessions().archiveSiblingSessions(address);
            SignalDatabase.senderKeyShared().deleteAllFor(recipientId);
            return SaveResult.UPDATE;
        }
        if (isNonBlockingApprovalRequired(identityRecord)) {
            Log.i(TAG, "Setting approval status...");
            cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval);
            return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED;
        }
        return SaveResult.NO_CHANGE;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) VerifiedStatus(org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus) IdentityStoreRecord(org.thoughtcrime.securesms.database.model.IdentityStoreRecord) NonNull(androidx.annotation.NonNull)

Example 3 with VerifiedStatus

use of org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus in project Signal-Android by signalapp.

the class SignalBaseIdentityKeyStore method saveIdentity.

@NonNull
public SaveResult saveIdentity(SignalProtocolAddress address, IdentityKey identityKey, boolean nonBlockingApproval) {
    synchronized (LOCK) {
        IdentityStoreRecord identityRecord = cache.get(address.getName());
        RecipientId recipientId = RecipientId.fromExternalPush(address.getName());
        if (identityRecord == null) {
            Log.i(TAG, "Saving new identity...");
            cache.save(address.getName(), recipientId, identityKey, VerifiedStatus.DEFAULT, true, System.currentTimeMillis(), nonBlockingApproval);
            return SaveResult.NEW;
        }
        if (!identityRecord.getIdentityKey().equals(identityKey)) {
            Log.i(TAG, "Replacing existing identity... Existing: " + identityRecord.getIdentityKey().hashCode() + " New: " + identityKey.hashCode());
            VerifiedStatus verifiedStatus;
            if (identityRecord.getVerifiedStatus() == VerifiedStatus.VERIFIED || identityRecord.getVerifiedStatus() == VerifiedStatus.UNVERIFIED) {
                verifiedStatus = VerifiedStatus.UNVERIFIED;
            } else {
                verifiedStatus = VerifiedStatus.DEFAULT;
            }
            cache.save(address.getName(), recipientId, identityKey, verifiedStatus, false, System.currentTimeMillis(), nonBlockingApproval);
            IdentityUtil.markIdentityUpdate(context, recipientId);
            ApplicationDependencies.getProtocolStore().aci().sessions().archiveSiblingSessions(address);
            SignalDatabase.senderKeyShared().deleteAllFor(recipientId);
            return SaveResult.UPDATE;
        }
        if (isNonBlockingApprovalRequired(identityRecord)) {
            Log.i(TAG, "Setting approval status...");
            cache.setApproval(address.getName(), recipientId, identityRecord, nonBlockingApproval);
            return SaveResult.NON_BLOCKING_APPROVAL_REQUIRED;
        }
        return SaveResult.NO_CHANGE;
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) VerifiedStatus(org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus) IdentityStoreRecord(org.thoughtcrime.securesms.database.model.IdentityStoreRecord) NonNull(androidx.annotation.NonNull)

Aggregations

VerifiedStatus (org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus)3 NonNull (androidx.annotation.NonNull)2 IdentityStoreRecord (org.thoughtcrime.securesms.database.model.IdentityStoreRecord)2 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)2 Address (org.thoughtcrime.securesms.database.Address)1 IdentityDatabase (org.thoughtcrime.securesms.database.IdentityDatabase)1 IdentityRecord (org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord)1 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)1