Search in sources :

Example 6 with InvalidKeyException

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

the class AsymmetricMasterCipher method encryptBytes.

public byte[] encryptBytes(byte[] body) {
    try {
        ECPublicKey theirPublic = asymmetricMasterSecret.getDjbPublicKey();
        ECKeyPair ourKeyPair = Curve.generateKeyPair();
        byte[] secret = Curve.calculateAgreement(theirPublic, ourKeyPair.getPrivateKey());
        MasterCipher masterCipher = getMasterCipherForSecret(secret);
        byte[] encryptedBodyBytes = masterCipher.encryptBytes(body);
        PublicKey ourPublicKey = new PublicKey(31337, ourKeyPair.getPublicKey());
        byte[] publicKeyBytes = ourPublicKey.serialize();
        return Util.combine(publicKeyBytes, encryptedBodyBytes);
    } catch (InvalidKeyException e) {
        throw new AssertionError(e);
    }
}
Also used : ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) ECPublicKey(org.whispersystems.libsignal.ecc.ECPublicKey) ECKeyPair(org.whispersystems.libsignal.ecc.ECKeyPair) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException)

Example 7 with InvalidKeyException

use of org.whispersystems.libsignal.InvalidKeyException 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)

Aggregations

InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)7 IOException (java.io.IOException)3 ECPrivateKey (org.whispersystems.libsignal.ecc.ECPrivateKey)3 ECPublicKey (org.whispersystems.libsignal.ecc.ECPublicKey)3 IdentityKey (org.whispersystems.libsignal.IdentityKey)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 ECKeyPair (org.whispersystems.libsignal.ecc.ECKeyPair)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 SignalProtocolStoreImpl (org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl)1 TextSecurePreKeyStore (org.thoughtcrime.securesms.crypto.storage.TextSecurePreKeyStore)1 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)1 DuplicateMessageException (org.whispersystems.libsignal.DuplicateMessageException)1 IdentityKeyPair (org.whispersystems.libsignal.IdentityKeyPair)1 InvalidKeyIdException (org.whispersystems.libsignal.InvalidKeyIdException)1 InvalidVersionException (org.whispersystems.libsignal.InvalidVersionException)1 LegacyMessageException (org.whispersystems.libsignal.LegacyMessageException)1 NoSessionException (org.whispersystems.libsignal.NoSessionException)1 UntrustedIdentityException (org.whispersystems.libsignal.UntrustedIdentityException)1 SignalProtocolStore (org.whispersystems.libsignal.state.SignalProtocolStore)1