Search in sources :

Example 1 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleCorruptMessage.

private void handleCorruptMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(envelope);
        if (insertResult.isPresent()) {
            smsDatabase.markAsDecryptFailed(insertResult.get().getMessageId());
            MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsDecryptFailed(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase)

Example 2 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleUntrustedIdentityMessage.

private void handleUntrustedIdentityMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    try {
        EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        byte[] serialized = envelope.hasLegacyMessage() ? envelope.getLegacyMessage() : envelope.getContent();
        PreKeySignalMessage whisperMessage = new PreKeySignalMessage(serialized);
        IdentityKey identityKey = whisperMessage.getIdentityKey();
        String encoded = Base64.encodeBytes(serialized);
        IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), encoded, Optional.<SignalServiceGroup>absent(), 0);
        if (!smsMessageId.isPresent()) {
            IncomingPreKeyBundleMessage bundleMessage = new IncomingPreKeyBundleMessage(textMessage, encoded, envelope.hasLegacyMessage());
            Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, bundleMessage);
            if (insertResult.isPresent()) {
                database.setMismatchedIdentity(insertResult.get().getMessageId(), recipientId, identityKey);
                MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
            }
        } else {
            database.updateMessageBody(masterSecret, smsMessageId.get(), encoded);
            database.markAsPreKeyBundle(smsMessageId.get());
            database.setMismatchedIdentity(smsMessageId.get(), recipientId, identityKey);
        }
    } catch (InvalidMessageException | InvalidVersionException e) {
        throw new AssertionError(e);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IdentityKey(org.whispersystems.libsignal.IdentityKey) Recipients(org.thoughtcrime.securesms.recipients.Recipients) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingPreKeyBundleMessage(org.thoughtcrime.securesms.sms.IncomingPreKeyBundleMessage) PreKeySignalMessage(org.whispersystems.libsignal.protocol.PreKeySignalMessage) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 3 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleNoSessionMessage.

private void handleNoSessionMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull Optional<Long> smsMessageId) {
    EncryptingSmsDatabase smsDatabase = DatabaseFactory.getEncryptingSmsDatabase(context);
    if (!smsMessageId.isPresent()) {
        Optional<InsertResult> insertResult = insertPlaceholder(envelope);
        if (insertResult.isPresent()) {
            smsDatabase.markAsNoSession(insertResult.get().getMessageId());
            MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
        }
    } else {
        smsDatabase.markAsNoSession(smsMessageId.get());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase)

Example 4 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult in project Signal-Android by WhisperSystems.

the class SmsReceiveJob method onRun.

@Override
public void onRun() {
    Log.w(TAG, "onRun()");
    Optional<IncomingTextMessage> message = assembleMessageFragments(pdus, subscriptionId);
    MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
    MasterSecretUnion masterSecretUnion;
    if (masterSecret == null) {
        masterSecretUnion = new MasterSecretUnion(MasterSecretUtil.getAsymmetricMasterSecret(context, null));
    } else {
        masterSecretUnion = new MasterSecretUnion(masterSecret);
    }
    if (message.isPresent() && !isBlocked(message.get())) {
        Optional<InsertResult> insertResult = storeMessage(masterSecretUnion, message.get());
        if (insertResult.isPresent()) {
            MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId());
        }
    } else if (message.isPresent()) {
        Log.w(TAG, "*** Received blocked SMS, ignoring...");
    } else {
        Log.w(TAG, "*** Failed to assemble message fragments!");
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 5 with InsertResult

use of org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult in project Signal-Android by WhisperSystems.

the class PushDecryptJob method handleTextMessage.

private void handleTextMessage(@NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, @NonNull Optional<Long> smsMessageId) throws MmsException {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    String body = message.getBody().isPresent() ? message.getBody().get() : "";
    Recipients recipients = getMessageDestination(envelope, message);
    if (message.getExpiresInSeconds() != recipients.getExpireMessages()) {
        handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
    }
    Long threadId;
    if (smsMessageId.isPresent() && !message.getGroupInfo().isPresent()) {
        threadId = database.updateBundleMessageBody(masterSecret, smsMessageId.get(), body).second;
    } else {
        IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), message.getTimestamp(), body, message.getGroupInfo(), message.getExpiresInSeconds() * 1000);
        textMessage = new IncomingEncryptedMessage(textMessage, body);
        Optional<InsertResult> insertResult = database.insertMessageInbox(masterSecret, textMessage);
        if (insertResult.isPresent())
            threadId = insertResult.get().getThreadId();
        else
            threadId = null;
        if (smsMessageId.isPresent())
            database.deleteMessage(smsMessageId.get());
    }
    if (threadId != null) {
        MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) Recipients(org.thoughtcrime.securesms.recipients.Recipients) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Aggregations

InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)13 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)9 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)6 Recipients (org.thoughtcrime.securesms.recipients.Recipients)4 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)2 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 ByteString (com.google.protobuf.ByteString)1 LinkedList (java.util.LinkedList)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)1 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)1 OutgoingGroupMediaMessage (org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage)1 SingleUseBlobProvider (org.thoughtcrime.securesms.providers.SingleUseBlobProvider)1 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)1