use of org.thoughtcrime.securesms.jobs.RefreshPreKeysJob in project Signal-Android by signalapp.
the class SQLCipherOpenHelper method onCreate.
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SmsDatabase.CREATE_TABLE);
db.execSQL(MmsDatabase.CREATE_TABLE);
db.execSQL(AttachmentDatabase.CREATE_TABLE);
db.execSQL(ThreadDatabase.CREATE_TABLE);
db.execSQL(IdentityDatabase.CREATE_TABLE);
db.execSQL(DraftDatabase.CREATE_TABLE);
db.execSQL(PushDatabase.CREATE_TABLE);
db.execSQL(GroupDatabase.CREATE_TABLE);
db.execSQL(RecipientDatabase.CREATE_TABLE);
db.execSQL(GroupReceiptDatabase.CREATE_TABLE);
db.execSQL(OneTimePreKeyDatabase.CREATE_TABLE);
db.execSQL(SignedPreKeyDatabase.CREATE_TABLE);
db.execSQL(SessionDatabase.CREATE_TABLE);
executeStatements(db, SmsDatabase.CREATE_INDEXS);
executeStatements(db, MmsDatabase.CREATE_INDEXS);
executeStatements(db, AttachmentDatabase.CREATE_INDEXS);
executeStatements(db, ThreadDatabase.CREATE_INDEXS);
executeStatements(db, DraftDatabase.CREATE_INDEXS);
executeStatements(db, GroupDatabase.CREATE_INDEXS);
executeStatements(db, GroupReceiptDatabase.CREATE_INDEXES);
if (context.getDatabasePath(ClassicOpenHelper.NAME).exists()) {
ClassicOpenHelper legacyHelper = new ClassicOpenHelper(context);
android.database.sqlite.SQLiteDatabase legacyDb = legacyHelper.getWritableDatabase();
SQLCipherMigrationHelper.migratePlaintext(context, legacyDb, db);
MasterSecret masterSecret = KeyCachingService.getMasterSecret(context);
if (masterSecret != null)
SQLCipherMigrationHelper.migrateCiphertext(context, masterSecret, legacyDb, db, null);
else
TextSecurePreferences.setNeedsSqlCipherMigration(context, true);
if (!PreKeyMigrationHelper.migratePreKeys(context, db)) {
ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
}
SessionStoreMigrationHelper.migrateSessions(context, db);
PreKeyMigrationHelper.cleanUpPreKeys(context);
}
}
use of org.thoughtcrime.securesms.jobs.RefreshPreKeysJob in project Signal-Android by WhisperSystems.
the class ApplicationContext method onCreate.
@Override
public void onCreate() {
Tracer.getInstance().start("Application#onCreate()");
AppStartup.getInstance().onApplicationCreate();
SignalLocalMetrics.ColdStart.start();
long startTime = System.currentTimeMillis();
if (FeatureFlags.internalUser()) {
Tracer.getInstance().setMaxBufferSize(35_000);
}
super.onCreate();
AppStartup.getInstance().addBlocking("security-provider", this::initializeSecurityProvider).addBlocking("sqlcipher-init", () -> {
SqlCipherLibraryLoader.load();
SignalDatabase.init(this, DatabaseSecretProvider.getOrCreateDatabaseSecret(this), AttachmentSecretProvider.getInstance(this).getOrCreateAttachmentSecret());
}).addBlocking("logging", () -> {
initializeLogging();
Log.i(TAG, "onCreate()");
}).addBlocking("crash-handling", this::initializeCrashHandling).addBlocking("rx-init", this::initializeRx).addBlocking("event-bus", () -> EventBus.builder().logNoSubscriberMessages(false).installDefaultEventBus()).addBlocking("app-dependencies", this::initializeAppDependencies).addBlocking("notification-channels", () -> NotificationChannels.create(this)).addBlocking("first-launch", this::initializeFirstEverAppLaunch).addBlocking("app-migrations", this::initializeApplicationMigrations).addBlocking("ring-rtc", this::initializeRingRtc).addBlocking("mark-registration", () -> RegistrationUtil.maybeMarkRegistrationComplete(this)).addBlocking("lifecycle-observer", () -> ApplicationDependencies.getAppForegroundObserver().addListener(this)).addBlocking("message-retriever", this::initializeMessageRetrieval).addBlocking("dynamic-theme", () -> DynamicTheme.setDefaultDayNightMode(this)).addBlocking("vector-compat", () -> {
if (Build.VERSION.SDK_INT < 21) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}).addBlocking("proxy-init", () -> {
if (SignalStore.proxy().isProxyEnabled()) {
Log.w(TAG, "Proxy detected. Enabling Conscrypt.setUseEngineSocketByDefault()");
Conscrypt.setUseEngineSocketByDefault(true);
}
}).addBlocking("blob-provider", this::initializeBlobProvider).addBlocking("feature-flags", FeatureFlags::init).addBlocking("glide", () -> SignalGlideModule.setRegisterGlideComponents(new SignalGlideComponents())).addNonBlocking(this::cleanAvatarStorage).addNonBlocking(this::initializeRevealableMessageManager).addNonBlocking(this::initializePendingRetryReceiptManager).addNonBlocking(this::initializeFcmCheck).addNonBlocking(CreateSignedPreKeyJob::enqueueIfNeeded).addNonBlocking(this::initializePeriodicTasks).addNonBlocking(this::initializeCircumvention).addNonBlocking(this::initializePendingMessages).addNonBlocking(this::initializeCleanup).addNonBlocking(this::initializeGlideCodecs).addNonBlocking(RefreshPreKeysJob::scheduleIfNecessary).addNonBlocking(StorageSyncHelper::scheduleRoutineSync).addNonBlocking(() -> ApplicationDependencies.getJobManager().beginJobLoop()).addNonBlocking(EmojiSource::refresh).addNonBlocking(() -> ApplicationDependencies.getGiphyMp4Cache().onAppStart(this)).addNonBlocking(this::ensureProfileUploaded).addPostRender(() -> RateLimitUtil.retryAllRateLimitedMessages(this)).addPostRender(this::initializeExpiringMessageManager).addPostRender(() -> SignalStore.settings().setDefaultSms(Util.isDefaultSmsProvider(this))).addPostRender(() -> DownloadLatestEmojiDataJob.scheduleIfNecessary(this)).addPostRender(EmojiSearchIndexDownloadJob::scheduleIfNecessary).addPostRender(() -> SignalDatabase.messageLog().trimOldMessages(System.currentTimeMillis(), FeatureFlags.retryRespondMaxAge())).addPostRender(() -> JumboEmoji.updateCurrentVersion(this)).addPostRender(RetrieveReleaseChannelJob::enqueue).execute();
Log.d(TAG, "onCreate() took " + (System.currentTimeMillis() - startTime) + " ms");
SignalLocalMetrics.ColdStart.onApplicationCreateFinished();
Tracer.getInstance().end("Application#onCreate()");
}
use of org.thoughtcrime.securesms.jobs.RefreshPreKeysJob in project Signal-Android by WhisperSystems.
the class MessageDecryptionUtil method decrypt.
/**
* Takes a {@link SignalServiceEnvelope} and returns a {@link DecryptionResult}, which has either
* a plaintext {@link SignalServiceContent} or information about an error that happened.
*
* Excluding the data updated in our protocol stores that results from decrypting a message, this
* method is side-effect free, preferring to return the decryption results to be handled by the
* caller.
*/
@NonNull
public static DecryptionResult decrypt(@NonNull Context context, @NonNull SignalServiceEnvelope envelope) {
SignalServiceAccountDataStore protocolStore = ApplicationDependencies.getProtocolStore().aci();
SignalServiceAddress localAddress = new SignalServiceAddress(Recipient.self().requireServiceId(), Recipient.self().requireE164());
SignalServiceCipher cipher = new SignalServiceCipher(localAddress, SignalStore.account().getDeviceId(), protocolStore, ReentrantSessionLock.INSTANCE, UnidentifiedAccessUtil.getCertificateValidator());
List<Job> jobs = new LinkedList<>();
if (envelope.isPreKeySignalMessage()) {
jobs.add(new RefreshPreKeysJob());
}
try {
try {
return DecryptionResult.forSuccess(cipher.decrypt(envelope), jobs);
} catch (ProtocolInvalidVersionException e) {
Log.w(TAG, String.valueOf(envelope.getTimestamp()), e);
return DecryptionResult.forError(MessageState.INVALID_VERSION, toExceptionMetadata(e), jobs);
} catch (ProtocolInvalidKeyIdException | ProtocolInvalidKeyException | ProtocolUntrustedIdentityException | ProtocolNoSessionException | ProtocolInvalidMessageException e) {
Log.w(TAG, String.valueOf(envelope.getTimestamp()), e);
Recipient sender = Recipient.external(context, e.getSender());
if (sender.supportsMessageRetries() && Recipient.self().supportsMessageRetries() && FeatureFlags.retryReceipts()) {
jobs.add(handleRetry(context, sender, envelope, e));
postInternalErrorNotification(context);
} else {
jobs.add(new AutomaticSessionResetJob(sender.getId(), e.getSenderDevice(), envelope.getTimestamp()));
}
return DecryptionResult.forNoop(jobs);
} catch (ProtocolLegacyMessageException e) {
Log.w(TAG, "[" + envelope.getTimestamp() + "] " + envelope.getSourceIdentifier() + ":" + envelope.getSourceDevice(), e);
return DecryptionResult.forError(MessageState.LEGACY_MESSAGE, toExceptionMetadata(e), jobs);
} catch (ProtocolDuplicateMessageException e) {
Log.w(TAG, "[" + envelope.getTimestamp() + "] " + envelope.getSourceIdentifier() + ":" + envelope.getSourceDevice(), e);
return DecryptionResult.forError(MessageState.DUPLICATE_MESSAGE, toExceptionMetadata(e), jobs);
} catch (InvalidMetadataVersionException | InvalidMetadataMessageException | InvalidMessageStructureException e) {
Log.w(TAG, "[" + envelope.getTimestamp() + "] " + envelope.getSourceIdentifier() + ":" + envelope.getSourceDevice(), e);
return DecryptionResult.forNoop(jobs);
} catch (SelfSendException e) {
Log.i(TAG, "Dropping UD message from self.");
return DecryptionResult.forNoop(jobs);
} catch (UnsupportedDataMessageException e) {
Log.w(TAG, "[" + envelope.getTimestamp() + "] " + envelope.getSourceIdentifier() + ":" + envelope.getSourceDevice(), e);
return DecryptionResult.forError(MessageState.UNSUPPORTED_DATA_MESSAGE, toExceptionMetadata(e), jobs);
}
} catch (NoSenderException e) {
Log.w(TAG, "Invalid message, but no sender info!");
return DecryptionResult.forNoop(jobs);
}
}
use of org.thoughtcrime.securesms.jobs.RefreshPreKeysJob in project Signal-Android by signalapp.
the class ApplicationContext method onCreate.
@Override
public void onCreate() {
Tracer.getInstance().start("Application#onCreate()");
AppStartup.getInstance().onApplicationCreate();
SignalLocalMetrics.ColdStart.start();
long startTime = System.currentTimeMillis();
if (FeatureFlags.internalUser()) {
Tracer.getInstance().setMaxBufferSize(35_000);
}
super.onCreate();
AppStartup.getInstance().addBlocking("security-provider", this::initializeSecurityProvider).addBlocking("sqlcipher-init", () -> {
SqlCipherLibraryLoader.load();
SignalDatabase.init(this, DatabaseSecretProvider.getOrCreateDatabaseSecret(this), AttachmentSecretProvider.getInstance(this).getOrCreateAttachmentSecret());
}).addBlocking("logging", () -> {
initializeLogging();
Log.i(TAG, "onCreate()");
}).addBlocking("crash-handling", this::initializeCrashHandling).addBlocking("rx-init", this::initializeRx).addBlocking("event-bus", () -> EventBus.builder().logNoSubscriberMessages(false).installDefaultEventBus()).addBlocking("app-dependencies", this::initializeAppDependencies).addBlocking("notification-channels", () -> NotificationChannels.create(this)).addBlocking("first-launch", this::initializeFirstEverAppLaunch).addBlocking("app-migrations", this::initializeApplicationMigrations).addBlocking("ring-rtc", this::initializeRingRtc).addBlocking("mark-registration", () -> RegistrationUtil.maybeMarkRegistrationComplete(this)).addBlocking("lifecycle-observer", () -> ApplicationDependencies.getAppForegroundObserver().addListener(this)).addBlocking("message-retriever", this::initializeMessageRetrieval).addBlocking("dynamic-theme", () -> DynamicTheme.setDefaultDayNightMode(this)).addBlocking("vector-compat", () -> {
if (Build.VERSION.SDK_INT < 21) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
}).addBlocking("proxy-init", () -> {
if (SignalStore.proxy().isProxyEnabled()) {
Log.w(TAG, "Proxy detected. Enabling Conscrypt.setUseEngineSocketByDefault()");
Conscrypt.setUseEngineSocketByDefault(true);
}
}).addBlocking("blob-provider", this::initializeBlobProvider).addBlocking("feature-flags", FeatureFlags::init).addBlocking("glide", () -> SignalGlideModule.setRegisterGlideComponents(new SignalGlideComponents())).addNonBlocking(this::cleanAvatarStorage).addNonBlocking(this::initializeRevealableMessageManager).addNonBlocking(this::initializePendingRetryReceiptManager).addNonBlocking(this::initializeFcmCheck).addNonBlocking(CreateSignedPreKeyJob::enqueueIfNeeded).addNonBlocking(this::initializePeriodicTasks).addNonBlocking(this::initializeCircumvention).addNonBlocking(this::initializePendingMessages).addNonBlocking(this::initializeCleanup).addNonBlocking(this::initializeGlideCodecs).addNonBlocking(RefreshPreKeysJob::scheduleIfNecessary).addNonBlocking(StorageSyncHelper::scheduleRoutineSync).addNonBlocking(() -> ApplicationDependencies.getJobManager().beginJobLoop()).addNonBlocking(EmojiSource::refresh).addNonBlocking(() -> ApplicationDependencies.getGiphyMp4Cache().onAppStart(this)).addNonBlocking(this::ensureProfileUploaded).addPostRender(() -> RateLimitUtil.retryAllRateLimitedMessages(this)).addPostRender(this::initializeExpiringMessageManager).addPostRender(() -> SignalStore.settings().setDefaultSms(Util.isDefaultSmsProvider(this))).addPostRender(() -> DownloadLatestEmojiDataJob.scheduleIfNecessary(this)).addPostRender(EmojiSearchIndexDownloadJob::scheduleIfNecessary).addPostRender(() -> SignalDatabase.messageLog().trimOldMessages(System.currentTimeMillis(), FeatureFlags.retryRespondMaxAge())).addPostRender(() -> JumboEmoji.updateCurrentVersion(this)).addPostRender(RetrieveReleaseChannelJob::enqueue).execute();
Log.d(TAG, "onCreate() took " + (System.currentTimeMillis() - startTime) + " ms");
SignalLocalMetrics.ColdStart.onApplicationCreateFinished();
Tracer.getInstance().end("Application#onCreate()");
}
use of org.thoughtcrime.securesms.jobs.RefreshPreKeysJob in project Signal-Android by signalapp.
the class SQLCipherOpenHelper method onUpgrade.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database: " + oldVersion + ", " + newVersion);
db.beginTransaction();
try {
if (oldVersion < RECIPIENT_CALL_RINGTONE_VERSION) {
db.execSQL("ALTER TABLE recipient_preferences ADD COLUMN call_ringtone TEXT DEFAULT NULL");
db.execSQL("ALTER TABLE recipient_preferences ADD COLUMN call_vibrate INTEGER DEFAULT " + RecipientDatabase.VibrateState.DEFAULT.getId());
}
if (oldVersion < MIGRATE_PREKEYS_VERSION) {
db.execSQL("CREATE TABLE signed_prekeys (_id INTEGER PRIMARY KEY, key_id INTEGER UNIQUE, public_key TEXT NOT NULL, private_key TEXT NOT NULL, signature TEXT NOT NULL, timestamp INTEGER DEFAULT 0)");
db.execSQL("CREATE TABLE one_time_prekeys (_id INTEGER PRIMARY KEY, key_id INTEGER UNIQUE, public_key TEXT NOT NULL, private_key TEXT NOT NULL)");
if (!PreKeyMigrationHelper.migratePreKeys(context, db)) {
ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
}
}
if (oldVersion < MIGRATE_SESSIONS_VERSION) {
db.execSQL("CREATE TABLE sessions (_id INTEGER PRIMARY KEY, address TEXT NOT NULL, device INTEGER NOT NULL, record BLOB NOT NULL, UNIQUE(address, device) ON CONFLICT REPLACE)");
SessionStoreMigrationHelper.migrateSessions(context, db);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
if (oldVersion < MIGRATE_PREKEYS_VERSION) {
PreKeyMigrationHelper.cleanUpPreKeys(context);
}
}
Aggregations