Pass PreKeyBundleStore into message sender.

This commit is contained in:
Mikunj 2019-06-05 09:29:18 +10:00
parent 4148d598f9
commit a0f95c033a
4 changed files with 40 additions and 4 deletions

View File

@ -41,6 +41,7 @@ import org.thoughtcrime.securesms.jobs.RotateCertificateJob;
import org.thoughtcrime.securesms.jobs.RotateSignedPreKeyJob;
import org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob;
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleStoreImpl;
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
import org.thoughtcrime.securesms.push.SecurityEventListener;
import org.thoughtcrime.securesms.push.SignalServiceNetworkAccess;
@ -134,6 +135,10 @@ public class SignalCommunicationModule {
Optional.fromNullable(IncomingMessageObserver.getPipe()),
Optional.fromNullable(IncomingMessageObserver.getUnidentifiedPipe()),
Optional.of(new SecurityEventListener(context)));
// LOKI - Set the prekey bundle store
// This is something that we MUST have otherwise our loki logic will fail
this.messageSender.setPreKeyBundleStore(new LokiPreKeyBundleStoreImpl(context));
} else {
this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe());
this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context));

View File

@ -61,6 +61,7 @@ import org.thoughtcrime.securesms.linkpreview.Link;
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
import org.thoughtcrime.securesms.linkpreview.LinkPreviewUtil;
import org.thoughtcrime.securesms.logging.Log;
import org.thoughtcrime.securesms.loki.LokiPreKeyBundleDatabase;
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
import org.thoughtcrime.securesms.mms.MmsException;
import org.thoughtcrime.securesms.mms.OutgoingExpirationUpdateMessage;
@ -81,6 +82,7 @@ import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.util.GroupUtil;
import org.thoughtcrime.securesms.util.IdentityUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.libsignal.state.PreKeyBundle;
import org.whispersystems.libsignal.state.SessionStore;
import org.whispersystems.libsignal.state.SignalProtocolStore;
import org.whispersystems.libsignal.util.guava.Optional;
@ -243,7 +245,13 @@ public class PushDecryptJob extends BaseJob {
if (content.lokiMessage.isPresent()) {
LokiServiceMessage lokiMessage = content.lokiMessage.get();
if (lokiMessage.getPreKeyBundleMessage() != null) {
// TODO: Loki - Handle pre key bundle
Log.i(TAG, "[Loki] Received a prekey bundle from: " + envelope.getSource());
int registrationId = TextSecurePreferences.getLocalRegistrationId(context);
if (registrationId > 0) {
LokiPreKeyBundleDatabase preKeyBundleDatabase = DatabaseFactory.getLokiPreKeyBundleDatabase(context);
PreKeyBundle preKeyBundle = lokiMessage.getPreKeyBundleMessage().getPreKeyBundle(registrationId);
preKeyBundleDatabase.setPreKeyBundle(envelope.getSource(), preKeyBundle);
}
}
if (lokiMessage.getAddressMessage() != null) {

View File

@ -13,6 +13,7 @@ import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.libsignal.IdentityKey
import org.whispersystems.libsignal.ecc.Curve
import org.whispersystems.libsignal.state.PreKeyBundle
import org.whispersystems.signalservice.api.push.SignalServiceAddress
class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) {
@ -57,9 +58,7 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
val registrationId = TextSecurePreferences.getLocalRegistrationId(context)
if (registrationId == 0) return null
// TODO: This is the primary device id, we may want to change it to support multiple devices?
val deviceId = 1
val deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID
return PreKeyBundle(registrationId, deviceId,preKeyRecord.id, preKeyRecord.keyPair.publicKey, signedPreKey.id, signedPreKey.keyPair.publicKey, signedPreKey.signature, identityKeyPair.publicKey)
}

View File

@ -0,0 +1,24 @@
package org.thoughtcrime.securesms.loki
import android.content.Context
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.whispersystems.libsignal.state.PreKeyBundle
import org.whispersystems.signalservice.loki.utilities.LokiPreKeyBundleStore
class LokiPreKeyBundleStoreImpl(val context: Context): LokiPreKeyBundleStore {
companion object {
val FILE_LOCK = Object()
}
override fun getPreKeyBundle(pubKey: String): PreKeyBundle? {
synchronized (FILE_LOCK) {
return DatabaseFactory.getLokiPreKeyBundleDatabase(context).getPreKeyBundle(pubKey)
}
}
override fun removePreKeyBundle(pubKey: String) {
synchronized (FILE_LOCK) {
DatabaseFactory.getLokiPreKeyBundleDatabase(context).removePreKeyBundle(pubKey)
}
}
}