Search in sources :

Example 1 with MasterSecretUnion

use of org.thoughtcrime.securesms.crypto.MasterSecretUnion in project Signal-Android by WhisperSystems.

the class PushDecryptJob method onRun.

@Override
public void onRun() throws NoSuchMessageException {
    if (!IdentityKeyUtil.hasIdentityKey(context)) {
        Log.w(TAG, "Skipping job, waiting for migration...");
        return;
    }
    MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
    PushDatabase database = DatabaseFactory.getPushDatabase(context);
    SignalServiceEnvelope envelope = database.get(messageId);
    Optional<Long> optionalSmsMessageId = smsMessageId > 0 ? Optional.of(smsMessageId) : Optional.<Long>absent();
    MasterSecretUnion masterSecretUnion;
    if (masterSecret == null)
        masterSecretUnion = new MasterSecretUnion(MasterSecretUtil.getAsymmetricMasterSecret(context, null));
    else
        masterSecretUnion = new MasterSecretUnion(masterSecret);
    handleMessage(masterSecretUnion, envelope, optionalSmsMessageId);
    database.delete(messageId);
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) PushDatabase(org.thoughtcrime.securesms.database.PushDatabase) MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) SignalServiceEnvelope(org.whispersystems.signalservice.api.messages.SignalServiceEnvelope)

Example 2 with MasterSecretUnion

use of org.thoughtcrime.securesms.crypto.MasterSecretUnion 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 3 with MasterSecretUnion

use of org.thoughtcrime.securesms.crypto.MasterSecretUnion 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)

Example 4 with MasterSecretUnion

use of org.thoughtcrime.securesms.crypto.MasterSecretUnion in project Signal-Android by WhisperSystems.

the class MmsDownloadJob method storeRetrievedMms.

private void storeRetrievedMms(MasterSecret masterSecret, String contentLocation, long messageId, long threadId, RetrieveConf retrieved, int subscriptionId) throws MmsException, NoSessionException, DuplicateMessageException, InvalidMessageException, LegacyMessageException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    SingleUseBlobProvider provider = SingleUseBlobProvider.getInstance();
    String from = null;
    List<String> to = new LinkedList<>();
    List<String> cc = new LinkedList<>();
    String body = null;
    List<Attachment> attachments = new LinkedList<>();
    if (retrieved.getFrom() != null) {
        from = Util.toIsoString(retrieved.getFrom().getTextString());
    }
    if (retrieved.getTo() != null) {
        for (EncodedStringValue toValue : retrieved.getTo()) {
            to.add(Util.toIsoString(toValue.getTextString()));
        }
    }
    if (retrieved.getCc() != null) {
        for (EncodedStringValue ccValue : retrieved.getCc()) {
            cc.add(Util.toIsoString(ccValue.getTextString()));
        }
    }
    if (retrieved.getBody() != null) {
        body = PartParser.getMessageText(retrieved.getBody());
        PduBody media = PartParser.getSupportedMediaParts(retrieved.getBody());
        for (int i = 0; i < media.getPartsNum(); i++) {
            PduPart part = media.getPart(i);
            if (part.getData() != null) {
                Uri uri = provider.createUri(part.getData());
                attachments.add(new UriAttachment(uri, Util.toIsoString(part.getContentType()), AttachmentDatabase.TRANSFER_PROGRESS_DONE, part.getData().length));
            }
        }
    }
    IncomingMediaMessage message = new IncomingMediaMessage(from, to, cc, body, retrieved.getDate() * 1000L, attachments, subscriptionId, 0, false);
    Optional<InsertResult> insertResult = database.insertMessageInbox(new MasterSecretUnion(masterSecret), message, contentLocation, threadId);
    if (insertResult.isPresent()) {
        database.delete(messageId);
        MessageNotifier.updateNotification(context, masterSecret, insertResult.get().getThreadId());
    }
}
Also used : InsertResult(org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult) EncodedStringValue(ws.com.google.android.mms.pdu.EncodedStringValue) MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) PduBody(ws.com.google.android.mms.pdu.PduBody) IncomingMediaMessage(org.thoughtcrime.securesms.mms.IncomingMediaMessage) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) Uri(android.net.Uri) LinkedList(java.util.LinkedList) SingleUseBlobProvider(org.thoughtcrime.securesms.providers.SingleUseBlobProvider) PduPart(ws.com.google.android.mms.pdu.PduPart) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Example 5 with MasterSecretUnion

use of org.thoughtcrime.securesms.crypto.MasterSecretUnion in project Signal-Android by WhisperSystems.

the class MessageSender method send.

public static long send(final Context context, final MasterSecret masterSecret, final OutgoingMediaMessage message, final long threadId, final boolean forceSms) {
    try {
        ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(context);
        MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
        long allocatedThreadId;
        if (threadId == -1) {
            allocatedThreadId = threadDatabase.getThreadIdFor(message.getRecipients(), message.getDistributionType());
        } else {
            allocatedThreadId = threadId;
        }
        Recipients recipients = message.getRecipients();
        long messageId = database.insertMessageOutbox(new MasterSecretUnion(masterSecret), message, allocatedThreadId, forceSms);
        sendMediaMessage(context, masterSecret, recipients, forceSms, messageId, message.getExpiresIn());
        return allocatedThreadId;
    } catch (MmsException e) {
        Log.w(TAG, e);
        return threadId;
    }
}
Also used : MasterSecretUnion(org.thoughtcrime.securesms.crypto.MasterSecretUnion) MmsException(ws.com.google.android.mms.MmsException) Recipients(org.thoughtcrime.securesms.recipients.Recipients) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase)

Aggregations

MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)7 MmsDatabase (org.thoughtcrime.securesms.database.MmsDatabase)3 LinkedList (java.util.LinkedList)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)2 EncryptingSmsDatabase (org.thoughtcrime.securesms.database.EncryptingSmsDatabase)2 InsertResult (org.thoughtcrime.securesms.database.MessagingDatabase.InsertResult)2 Recipients (org.thoughtcrime.securesms.recipients.Recipients)2 MmsException (ws.com.google.android.mms.MmsException)2 ContentValues (android.content.ContentValues)1 Uri (android.net.Uri)1 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)1 MmsNotificationAttachment (org.thoughtcrime.securesms.attachments.MmsNotificationAttachment)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 PushDatabase (org.thoughtcrime.securesms.database.PushDatabase)1 SmsDatabase (org.thoughtcrime.securesms.database.SmsDatabase)1 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)1 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)1 SmsMessageRecord (org.thoughtcrime.securesms.database.model.SmsMessageRecord)1 IncomingMediaMessage (org.thoughtcrime.securesms.mms.IncomingMediaMessage)1