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;
}
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);
}
}
}
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;
}
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;
}
}
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);
}
}
Aggregations