Search in sources :

Example 16 with InvalidMessageException

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

the class EncryptingJobSerializer method deserialize.

@Override
public Job deserialize(EncryptionKeys keys, boolean encrypted, String serialized) throws IOException {
    try {
        String plaintext;
        if (encrypted) {
            MasterSecret masterSecret = ParcelUtil.deserialize(keys.getEncoded(), MasterSecret.CREATOR);
            MasterCipher masterCipher = new MasterCipher(masterSecret);
            plaintext = masterCipher.decryptBody(serialized);
        } else {
            plaintext = serialized;
        }
        return delegate.deserialize(keys, encrypted, plaintext);
    } catch (InvalidMessageException e) {
        throw new IOException(e);
    }
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher) IOException(java.io.IOException)

Example 17 with InvalidMessageException

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

the class AvatarDownloadJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) throws IOException {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    GroupDatabase.GroupRecord record = database.getGroup(groupId);
    File attachment = null;
    try {
        if (record != null) {
            long avatarId = record.getAvatarId();
            String contentType = record.getAvatarContentType();
            byte[] key = record.getAvatarKey();
            String relay = record.getRelay();
            Optional<byte[]> digest = Optional.fromNullable(record.getAvatarDigest());
            if (avatarId == -1 || key == null) {
                return;
            }
            if (digest.isPresent()) {
                Log.w(TAG, "Downloading group avatar with digest: " + Hex.toString(digest.get()));
            }
            attachment = File.createTempFile("avatar", "tmp", context.getCacheDir());
            attachment.deleteOnExit();
            SignalServiceAttachmentPointer pointer = new SignalServiceAttachmentPointer(avatarId, contentType, key, relay, digest);
            InputStream inputStream = receiver.retrieveAttachment(pointer, attachment, MAX_AVATAR_SIZE);
            Bitmap avatar = BitmapUtil.createScaledBitmap(context, new AttachmentModel(attachment, key), 500, 500);
            database.updateAvatar(groupId, avatar);
            inputStream.close();
        }
    } catch (BitmapDecodingException | NonSuccessfulResponseCodeException | InvalidMessageException e) {
        Log.w(TAG, e);
    } finally {
        if (attachment != null)
            attachment.delete();
    }
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) InputStream(java.io.InputStream) SignalServiceAttachmentPointer(org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer) NonSuccessfulResponseCodeException(org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException) Bitmap(android.graphics.Bitmap) AttachmentModel(org.thoughtcrime.securesms.mms.AttachmentStreamUriLoader.AttachmentModel) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) File(java.io.File) BitmapDecodingException(org.thoughtcrime.securesms.util.BitmapDecodingException)

Example 18 with InvalidMessageException

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

the class MasterSecretDecryptJob method onRun.

@Override
public void onRun(MasterSecret masterSecret) {
    EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsDatabase.Reader smsReader = smsDatabase.getDecryptInProgressMessages(masterSecret);
    SmsMessageRecord smsRecord;
    while ((smsRecord = smsReader.getNext()) != null) {
        try {
            String body = getAsymmetricDecryptedBody(masterSecret, smsRecord.getBody().getBody());
            smsDatabase.updateMessageBody(new MasterSecretUnion(masterSecret), smsRecord.getId(), body);
        } catch (InvalidMessageException e) {
            Log.w(TAG, e);
        }
    }
    MmsDatabase mmsDatabase = DatabaseFactory.getMmsDatabase(context);
    MmsDatabase.Reader mmsReader = mmsDatabase.getDecryptInProgressMessages(masterSecret);
    MessageRecord mmsRecord;
    while ((mmsRecord = mmsReader.getNext()) != null) {
        try {
            String body = getAsymmetricDecryptedBody(masterSecret, mmsRecord.getBody().getBody());
            mmsDatabase.updateMessageBody(new MasterSecretUnion(masterSecret), mmsRecord.getId(), body);
        } catch (InvalidMessageException e) {
            Log.w(TAG, e);
        }
    }
    smsReader.close();
    mmsReader.close();
    MessageNotifier.updateNotification(context, masterSecret);
}
Also used : MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) SmsDatabase(org.thoughtcrime.securesms.database.SmsDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)18 IOException (java.io.IOException)7 File (java.io.File)4 InputStream (java.io.InputStream)3 MasterCipher (org.thoughtcrime.securesms.crypto.MasterCipher)3 SignalServiceAttachmentPointer (org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer)3 MmsException (ws.com.google.android.mms.MmsException)3 Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 Pair (android.util.Pair)2 FileInputStream (java.io.FileInputStream)2 LinkedList (java.util.LinkedList)2 AsymmetricMasterSecret (org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret)2 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)2 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)2 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 DuplicateMessageException (org.whispersystems.libsignal.DuplicateMessageException)2 IdentityKey (org.whispersystems.libsignal.IdentityKey)2 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)2