Search in sources :

Example 6 with IdentityKey

use of org.whispersystems.libsignal.IdentityKey in project Signal-Android by WhisperSystems.

the class WebRtcCallActivity method handleUntrustedIdentity.

private void handleUntrustedIdentity(@NonNull WebRtcViewModel event) {
    final IdentityKey theirIdentity = event.getIdentityKey();
    final Recipient recipient = event.getRecipient();
    callScreen.setUntrustedIdentity(recipient, theirIdentity);
    callScreen.setAcceptIdentityListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            IdentityDatabase identityDatabase = DatabaseFactory.getIdentityDatabase(WebRtcCallActivity.this);
            identityDatabase.saveIdentity(recipient.getRecipientId(), theirIdentity);
            Intent intent = new Intent(WebRtcCallActivity.this, WebRtcCallService.class);
            intent.putExtra(WebRtcCallService.EXTRA_REMOTE_NUMBER, recipient.getNumber());
            intent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL);
            startService(intent);
        }
    });
    callScreen.setCancelIdentityButton(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            handleTerminate(recipient);
        }
    });
}
Also used : WebRtcCallService(org.thoughtcrime.securesms.service.WebRtcCallService) IdentityKey(org.whispersystems.libsignal.IdentityKey) IdentityDatabase(org.thoughtcrime.securesms.database.IdentityDatabase) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Intent(android.content.Intent) View(android.view.View)

Example 7 with IdentityKey

use of org.whispersystems.libsignal.IdentityKey in project Signal-Android by WhisperSystems.

the class IdentityDatabase method isValidIdentity.

public boolean isValidIdentity(long recipientId, IdentityKey theirIdentity) {
    SQLiteDatabase database = databaseHelper.getReadableDatabase();
    Cursor cursor = null;
    try {
        cursor = database.query(TABLE_NAME, null, RECIPIENT + " = ?", new String[] { recipientId + "" }, null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            String serializedIdentity = cursor.getString(cursor.getColumnIndexOrThrow(IDENTITY_KEY));
            IdentityKey ourIdentity = new IdentityKey(Base64.decode(serializedIdentity), 0);
            return ourIdentity.equals(theirIdentity);
        } else {
            return true;
        }
    } catch (IOException e) {
        Log.w("IdentityDatabase", e);
        return false;
    } catch (InvalidKeyException e) {
        Log.w("IdentityDatabase", e);
        return false;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
Also used : IdentityKey(org.whispersystems.libsignal.IdentityKey) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) IOException(java.io.IOException) Cursor(android.database.Cursor) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException)

Example 8 with IdentityKey

use of org.whispersystems.libsignal.IdentityKey in project Signal-Android by WhisperSystems.

the class IdentityUtil method getRemoteIdentityKey.

@UiThread
public static ListenableFuture<Optional<IdentityKey>> getRemoteIdentityKey(final Context context, final MasterSecret masterSecret, final Recipient recipient) {
    final SettableFuture<Optional<IdentityKey>> future = new SettableFuture<>();
    new AsyncTask<Recipient, Void, Optional<IdentityKey>>() {

        @Override
        protected Optional<IdentityKey> doInBackground(Recipient... recipient) {
            SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
            SignalProtocolAddress axolotlAddress = new SignalProtocolAddress(recipient[0].getNumber(), SignalServiceAddress.DEFAULT_DEVICE_ID);
            SessionRecord record = sessionStore.loadSession(axolotlAddress);
            if (record == null) {
                return Optional.absent();
            }
            return Optional.fromNullable(record.getSessionState().getRemoteIdentityKey());
        }

        @Override
        protected void onPostExecute(Optional<IdentityKey> result) {
            future.set(result);
        }
    }.execute(recipient);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) IdentityKey(org.whispersystems.libsignal.IdentityKey) Optional(org.whispersystems.libsignal.util.guava.Optional) Recipient(org.thoughtcrime.securesms.recipients.Recipient) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SessionStore(org.whispersystems.libsignal.state.SessionStore) TextSecureSessionStore(org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) SessionRecord(org.whispersystems.libsignal.state.SessionRecord) UiThread(android.support.annotation.UiThread)

Aggregations

IdentityKey (org.whispersystems.libsignal.IdentityKey)8 IOException (java.io.IOException)4 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)2 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 ContentValues (android.content.ContentValues)1 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 UiThread (android.support.annotation.UiThread)1 View (android.view.View)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 DecryptingPartInputStream (org.thoughtcrime.securesms.crypto.DecryptingPartInputStream)1 MasterCipher (org.thoughtcrime.securesms.crypto.MasterCipher)1 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)1