Search in sources :

Example 6 with MasterSecret

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

the class KeyCachingService method getMasterSecret.

@Nullable
public static synchronized MasterSecret getMasterSecret(Context context) {
    if (masterSecret == null && TextSecurePreferences.isPasswordDisabled(context)) {
        try {
            MasterSecret masterSecret = MasterSecretUtil.getMasterSecret(context, MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
            Intent intent = new Intent(context, KeyCachingService.class);
            context.startService(intent);
            return masterSecret;
        } catch (InvalidPassphraseException e) {
            Log.w("KeyCachingService", e);
        }
    }
    return masterSecret;
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) InvalidPassphraseException(org.thoughtcrime.securesms.crypto.InvalidPassphraseException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Nullable(android.support.annotation.Nullable)

Example 7 with MasterSecret

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

the class KeyCachingService method onCreate.

@Override
public void onCreate() {
    Log.w("KeyCachingService", "onCreate()");
    super.onCreate();
    this.pending = PendingIntent.getService(this, 0, new Intent(PASSPHRASE_EXPIRED_EVENT, null, this, KeyCachingService.class), 0);
    if (TextSecurePreferences.isPasswordDisabled(this)) {
        try {
            MasterSecret masterSecret = MasterSecretUtil.getMasterSecret(this, MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
            setMasterSecret(masterSecret);
        } catch (InvalidPassphraseException e) {
            Log.w("KeyCachingService", e);
        }
    }
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) InvalidPassphraseException(org.thoughtcrime.securesms.crypto.InvalidPassphraseException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 8 with MasterSecret

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

the class ConversationActivity method saveDraft.

protected ListenableFuture<Long> saveDraft() {
    final SettableFuture<Long> future = new SettableFuture<>();
    if (this.recipients == null || this.recipients.isEmpty()) {
        future.set(threadId);
        return future;
    }
    final Drafts drafts = getDraftsForCurrentState();
    final long thisThreadId = this.threadId;
    final MasterSecret thisMasterSecret = this.masterSecret.parcelClone();
    final int thisDistributionType = this.distributionType;
    new AsyncTask<Long, Void, Long>() {

        @Override
        protected Long doInBackground(Long... params) {
            ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(ConversationActivity.this);
            DraftDatabase draftDatabase = DatabaseFactory.getDraftDatabase(ConversationActivity.this);
            long threadId = params[0];
            if (drafts.size() > 0) {
                if (threadId == -1)
                    threadId = threadDatabase.getThreadIdFor(getRecipients(), thisDistributionType);
                draftDatabase.insertDrafts(new MasterCipher(thisMasterSecret), threadId, drafts);
                threadDatabase.updateSnippet(threadId, drafts.getSnippet(ConversationActivity.this), drafts.getUriSnippet(ConversationActivity.this), System.currentTimeMillis(), Types.BASE_DRAFT_TYPE, true);
            } else if (threadId > 0) {
                threadDatabase.update(threadId, false);
            }
            return threadId;
        }

        @Override
        protected void onPostExecute(Long result) {
            future.set(result);
        }
    }.execute(thisThreadId);
    return future;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) DraftDatabase(org.thoughtcrime.securesms.database.DraftDatabase) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Drafts(org.thoughtcrime.securesms.database.DraftDatabase.Drafts)

Example 9 with MasterSecret

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

the class EncryptingJobSerializer method serialize.

@Override
public String serialize(Job job) throws IOException {
    String plaintext = delegate.serialize(job);
    if (job.getEncryptionKeys() != null) {
        MasterSecret masterSecret = ParcelUtil.deserialize(job.getEncryptionKeys().getEncoded(), MasterSecret.CREATOR);
        MasterCipher masterCipher = new MasterCipher(masterSecret);
        return masterCipher.encryptBody(plaintext);
    } else {
        return plaintext;
    }
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher)

Example 10 with MasterSecret

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

Aggregations

MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)16 MasterCipher (org.thoughtcrime.securesms.crypto.MasterCipher)4 IOException (java.io.IOException)3 InvalidPassphraseException (org.thoughtcrime.securesms.crypto.InvalidPassphraseException)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Intent (android.content.Intent)2 Bitmap (android.graphics.Bitmap)2 InputStream (java.io.InputStream)2 MasterSecretUnion (org.thoughtcrime.securesms.crypto.MasterSecretUnion)2 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)2 ComponentName (android.content.ComponentName)1 Cursor (android.database.Cursor)1 BitmapFactory (android.graphics.BitmapFactory)1 Point (android.graphics.Point)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 ChooserTarget (android.service.chooser.ChooserTarget)1 Nullable (android.support.annotation.Nullable)1