Search in sources :

Example 1 with SignalServiceEnvelope

use of org.whispersystems.signalservice.api.messages.SignalServiceEnvelope 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 SignalServiceEnvelope

use of org.whispersystems.signalservice.api.messages.SignalServiceEnvelope in project Signal-Android by WhisperSystems.

the class PushContentReceiveJob method onRun.

@Override
public void onRun() {
    try {
        String sessionKey = TextSecurePreferences.getSignalingKey(context);
        SignalServiceEnvelope envelope = new SignalServiceEnvelope(data, sessionKey);
        handle(envelope, true);
    } catch (IOException | InvalidVersionException e) {
        Log.w(TAG, e);
    }
}
Also used : SignalServiceEnvelope(org.whispersystems.signalservice.api.messages.SignalServiceEnvelope) InvalidVersionException(org.whispersystems.libsignal.InvalidVersionException) IOException(java.io.IOException)

Example 3 with SignalServiceEnvelope

use of org.whispersystems.signalservice.api.messages.SignalServiceEnvelope in project Signal-Android by WhisperSystems.

the class PushDatabase method get.

public SignalServiceEnvelope get(long id) throws NoSuchMessageException {
    Cursor cursor = null;
    try {
        cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, null, ID_WHERE, new String[] { String.valueOf(id) }, null, null, null);
        if (cursor != null && cursor.moveToNext()) {
            String legacyMessage = cursor.getString(cursor.getColumnIndexOrThrow(LEGACY_MSG));
            String content = cursor.getString(cursor.getColumnIndexOrThrow(CONTENT));
            return new SignalServiceEnvelope(cursor.getInt(cursor.getColumnIndexOrThrow(TYPE)), cursor.getString(cursor.getColumnIndexOrThrow(SOURCE)), cursor.getInt(cursor.getColumnIndexOrThrow(DEVICE_ID)), "", cursor.getLong(cursor.getColumnIndexOrThrow(TIMESTAMP)), Util.isEmpty(legacyMessage) ? null : Base64.decode(legacyMessage), Util.isEmpty(content) ? null : Base64.decode(content));
        }
    } catch (IOException e) {
        Log.w(TAG, e);
        throw new NoSuchMessageException(e);
    } finally {
        if (cursor != null)
            cursor.close();
    }
    throw new NoSuchMessageException("Not found");
}
Also used : SignalServiceEnvelope(org.whispersystems.signalservice.api.messages.SignalServiceEnvelope) IOException(java.io.IOException) Cursor(android.database.Cursor)

Aggregations

SignalServiceEnvelope (org.whispersystems.signalservice.api.messages.SignalServiceEnvelope)3 IOException (java.io.IOException)2 Cursor (android.database.Cursor)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)1 PushDatabase (org.thoughtcrime.securesms.database.PushDatabase)1 InvalidVersionException (org.whispersystems.libsignal.InvalidVersionException)1