Search in sources :

Example 1 with IdentityRecord

use of org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord 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 IdentityRecord

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

the class UntrustedSendDialog method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    final IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(getContext());
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            synchronized (SESSION_LOCK) {
                for (IdentityRecord identityRecord : untrustedRecords) {
                    identityDatabase.setApproval(identityRecord.getAddress(), true);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            resendListener.onResendMessage();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) IdentityRecord(org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord)

Example 3 with IdentityRecord

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

the class UnverifiedSendDialog method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    final IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(getContext());
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            synchronized (SESSION_LOCK) {
                for (IdentityRecord identityRecord : untrustedRecords) {
                    identityDatabase.setVerified(identityRecord.getAddress(), identityRecord.getIdentityKey(), IdentityDatabase.VerifiedStatus.DEFAULT);
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            resendListener.onResendMessage();
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) IdentityRecord(org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord)

Example 4 with IdentityRecord

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

the class ConversationActivity method handleUnverifiedRecipients.

private void handleUnverifiedRecipients() {
    List<Recipient> unverifiedRecipients = identityRecords.getUnverifiedRecipients(this);
    List<IdentityRecord> unverifiedRecords = identityRecords.getUnverifiedRecords();
    String message = IdentityUtil.getUnverifiedSendDialogDescription(this, unverifiedRecipients);
    if (message == null)
        return;
    // noinspection CodeBlock2Expr
    new UnverifiedSendDialog(this, message, unverifiedRecords, () -> {
        initializeIdentityRecords().addListener(new ListenableFuture.Listener<Boolean>() {

            @Override
            public void onSuccess(Boolean result) {
                sendMessage();
            }

            @Override
            public void onFailure(ExecutionException e) {
                throw new AssertionError(e);
            }
        });
    }).show();
}
Also used : AttachmentDrawerListener(org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener) OnFocusChangeListener(android.view.View.OnFocusChangeListener) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) OnKeyboardShownListener(org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout.OnKeyboardShownListener) OnKeyListener(android.view.View.OnKeyListener) RecipientModifiedListener(org.thoughtcrime.securesms.recipients.RecipientModifiedListener) OnClickListener(android.view.View.OnClickListener) IdentityRecord(org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) UnverifiedSendDialog(org.thoughtcrime.securesms.components.identity.UnverifiedSendDialog)

Example 5 with IdentityRecord

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

the class IdentityUtil method processVerifiedMessage.

public static void processVerifiedMessage(Context context, VerifiedMessage verifiedMessage) {
    synchronized (SESSION_LOCK) {
        IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(context);
        Recipient recipient = Recipient.from(context, Address.fromExternal(context, verifiedMessage.getDestination()), true);
        Optional<IdentityRecord> identityRecord = identityDatabase.getIdentity(recipient.getAddress());
        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) {
            identityDatabase.setVerified(recipient.getAddress(), 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(context, verifiedMessage.getDestination(), verifiedMessage.getIdentityKey());
            identityDatabase.setVerified(recipient.getAddress(), verifiedMessage.getIdentityKey(), IdentityDatabase.VerifiedStatus.VERIFIED);
            markIdentityVerified(context, recipient, true, true);
        }
    }
}
Also used : IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) IdentityRecord(org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient)

Aggregations

IdentityRecord (org.thoughtcrime.securesms.database.IdentityDatabase.IdentityRecord)6 IdentityDatabase (org.thoughtcrime.securesms.database.IdentityDatabase)4 Recipient (org.thoughtcrime.securesms.recipients.Recipient)3 OnClickListener (android.view.View.OnClickListener)2 OnFocusChangeListener (android.view.View.OnFocusChangeListener)2 OnKeyListener (android.view.View.OnKeyListener)2 ByteString (com.google.protobuf.ByteString)2 ExecutionException (java.util.concurrent.ExecutionException)2 OnKeyboardShownListener (org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout.OnKeyboardShownListener)2 AttachmentDrawerListener (org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener)2 RecipientModifiedListener (org.thoughtcrime.securesms.recipients.RecipientModifiedListener)2 AssertedSuccessListener (org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener)2 UntrustedSendDialog (org.thoughtcrime.securesms.components.identity.UntrustedSendDialog)1 UnverifiedSendDialog (org.thoughtcrime.securesms.components.identity.UnverifiedSendDialog)1 Address (org.thoughtcrime.securesms.database.Address)1 VerifiedStatus (org.thoughtcrime.securesms.database.IdentityDatabase.VerifiedStatus)1 SignalProtocolAddress (org.whispersystems.libsignal.SignalProtocolAddress)1