Search in sources :

Example 1 with EncryptingSmsDatabase

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

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

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

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

the class PushDecryptJob method insertPlaceholder.

private Optional<InsertResult> insertPlaceholder(@NonNull SignalServiceEnvelope envelope) {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    IncomingTextMessage textMessage = new IncomingTextMessage(envelope.getSource(), envelope.getSourceDevice(), envelope.getTimestamp(), "", Optional.<SignalServiceGroup>absent(), 0);
    textMessage = new IncomingEncryptedMessage(textMessage, "");
    return database.insertMessageInbox(textMessage);
}
Also used : IncomingEncryptedMessage(org.thoughtcrime.securesms.sms.IncomingEncryptedMessage) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) IncomingTextMessage(org.thoughtcrime.securesms.sms.IncomingTextMessage)

Example 5 with EncryptingSmsDatabase

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

the class PushTextSendJob method onPushSend.

@Override
public void onPushSend(MasterSecret masterSecret) throws NoSuchMessageException, RetryLaterException {
    ExpiringMessageManager expirationManager = ApplicationContext.getInstance(context).getExpiringMessageManager();
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord record = database.getMessage(masterSecret, messageId);
    try {
        Log.w(TAG, "Sending message: " + messageId);
        deliver(record);
        database.markAsSent(messageId, true);
        if (record.getExpiresIn() > 0) {
            database.markExpireStarted(messageId);
            expirationManager.scheduleDeletion(record.getId(), record.isMms(), record.getExpiresIn());
        }
    } catch (InsecureFallbackApprovalException e) {
        Log.w(TAG, e);
        database.markAsPendingInsecureSmsFallback(record.getId());
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
        ApplicationContext.getInstance(context).getJobManager().add(new DirectoryRefreshJob(context));
    } catch (UntrustedIdentityException e) {
        Log.w(TAG, e);
        Recipients recipients = RecipientFactory.getRecipientsFromString(context, e.getE164Number(), false);
        long recipientId = recipients.getPrimaryRecipient().getRecipientId();
        database.addMismatchedIdentity(record.getId(), recipientId, e.getIdentityKey());
        database.markAsSentFailed(record.getId());
        database.markAsPush(record.getId());
    }
}
Also used : UntrustedIdentityException(org.whispersystems.signalservice.api.crypto.UntrustedIdentityException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) SmsMessageRecord(org.thoughtcrime.securesms.database.model.SmsMessageRecord) EncryptingSmsDatabase(org.thoughtcrime.securesms.database.EncryptingSmsDatabase) ExpiringMessageManager(org.thoughtcrime.securesms.service.ExpiringMessageManager) InsecureFallbackApprovalException(org.thoughtcrime.securesms.transport.InsecureFallbackApprovalException)

Aggregations

EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)19 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)9 Recipients (org.thoughtcrime.securesms.recipients.Recipients)7 IncomingTextMessage (org.thoughtcrime.securesms.sms.IncomingTextMessage)6 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)4 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 Nullable (android.support.annotation.Nullable)2 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 TextSecureSessionStore (org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore)2 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)2 ExpiringMessageManager (org.thoughtcrime.securesms.service.ExpiringMessageManager)2 IncomingEncryptedMessage (org.thoughtcrime.securesms.sms.IncomingEncryptedMessage)2 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SessionStore (org.whispersystems.libsignal.state.SessionStore)2 ByteString (com.google.protobuf.ByteString)1 MmsSmsDatabase (org.thoughtcrime.securesms.database.MmsSmsDatabase)1 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)1 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)1 AvatarDownloadJob (org.thoughtcrime.securesms.jobs.AvatarDownloadJob)1