From 384a5ba35dc215e556bf800faf1373714c0052b3 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Tue, 4 Jun 2019 15:00:27 +1000 Subject: [PATCH] Update RefreshPreKeysJob. --- .../database/helpers/SQLCipherOpenHelper.java | 4 ++++ .../securesms/jobs/RefreshPreKeysJob.java | 21 +++++++++++++++++++ .../loki/LokiPreKeyBundleDatabase.kt | 2 -- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 3d3bae2bf5..fb66026457 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -36,6 +36,8 @@ import org.thoughtcrime.securesms.database.SmsDatabase; import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob; import org.thoughtcrime.securesms.loki.LokiAPIDatabase; +import org.thoughtcrime.securesms.loki.LokiContactPreKeyDatabase; +import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase; import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.util.TextSecurePreferences; @@ -116,6 +118,8 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { db.execSQL(LokiAPIDatabase.getCreateSwarmCacheTableCommand()); db.execSQL(LokiAPIDatabase.getCreateLastMessageHashValueTableCommand()); db.execSQL(LokiAPIDatabase.getCreateReceivedMessageHashValuesTableCommand()); + db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand()); + db.execSQL(LokiContactPreKeyDatabase.getCreateTableCommand()); executeStatements(db, SmsDatabase.CREATE_INDEXS); executeStatements(db, MmsDatabase.CREATE_INDEXS); diff --git a/src/org/thoughtcrime/securesms/jobs/RefreshPreKeysJob.java b/src/org/thoughtcrime/securesms/jobs/RefreshPreKeysJob.java index 362942107c..b1bf51bab9 100644 --- a/src/org/thoughtcrime/securesms/jobs/RefreshPreKeysJob.java +++ b/src/org/thoughtcrime/securesms/jobs/RefreshPreKeysJob.java @@ -55,6 +55,26 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType { return KEY; } + @Override + public void onRun() throws IOException { + if (!TextSecurePreferences.isPushRegistered(context)) return; + + if (TextSecurePreferences.isSignedPreKeyRegistered(context)) { + Log.i(TAG, "Already have a signed pre key set"); + return; + } + + Log.i(TAG, "Registering new signed pre key..."); + IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context); + PreKeyUtil.generateSignedPreKey(context, identityKey, true); + TextSecurePreferences.setSignedPreKeyRegistered(context, true); + + ApplicationContext.getInstance(context) + .getJobManager() + .add(new CleanPreKeysJob()); + } + + /* Loki - Original Code @Override public void onRun() throws IOException { if (!TextSecurePreferences.isPushRegistered(context)) return; @@ -81,6 +101,7 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType { .getJobManager() .add(new CleanPreKeysJob()); } + */ @Override public boolean onShouldRetry(Exception exception) { diff --git a/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleDatabase.kt b/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleDatabase.kt index d37f886aee..f6de9e0a2f 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiPreKeyBundleDatabase.kt @@ -50,9 +50,7 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) : * @return PreKeyBundle? A pre key bundle or `null` if something went wrong. */ fun generatePreKeyBundle(pubKey: String): PreKeyBundle? { - // TODO: Check if we have pre keys val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context) - val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null val preKeyRecord = DatabaseFactory.getLokiContactPreKeyDatabase(context).getOrCreatePreKey(pubKey)