Fix pre key usage

This commit is contained in:
Niels Andriesse 2019-06-26 14:31:38 +10:00
parent e7f7c3cdb2
commit dd67e59807
5 changed files with 23 additions and 11 deletions

View File

@ -156,7 +156,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException
{
try {
// rotateSenderCertificateIfNecessary(); // LOKITODO: Uncomment this?
// rotateSenderCertificateIfNecessary();
SignalServiceAddress address = getPushAddress(message.getIndividualRecipient().getAddress());
Optional<byte[]> profileKey = getProfileKey(message.getIndividualRecipient());

View File

@ -55,9 +55,9 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType {
@Override
public void onRun() throws IOException {
if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
Log.i(TAG, "Already have a signed pre key registered.");
Log.d("Loki", "A signed pre key has already been registered.");
} else {
Log.i(TAG, "Registering new signed pre key...");
Log.d("Loki", "Registering a new signed pre key.");
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
PreKeyUtil.generateSignedPreKey(context, identityKey, true);
TextSecurePreferences.setSignedPreKeyRegistered(context, true);

View File

@ -55,7 +55,7 @@ public class RotateSignedPreKeyJob extends BaseJob implements InjectableType {
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);
accountManager.setSignedPreKey(signedPreKeyRecord);
// accountManager.setSignedPreKey(signedPreKeyRecord);
PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
TextSecurePreferences.setSignedPreKeyRegistered(context, true);

View File

@ -8,11 +8,13 @@ import org.thoughtcrime.securesms.crypto.PreKeyUtil
import org.thoughtcrime.securesms.database.Database
import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
import org.thoughtcrime.securesms.logging.Log
import org.thoughtcrime.securesms.util.Base64
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.libsignal.util.KeyHelper
import org.whispersystems.signalservice.api.push.SignalServiceAddress
import org.whispersystems.signalservice.loki.messaging.LokiPreKeyBundleDatabaseProtocol
@ -35,13 +37,23 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
}
fun generatePreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null
val preKeyRecord = DatabaseFactory.getLokiPreKeyRecordDatabase(context).getOrCreatePreKey(hexEncodedPublicKey)
val registrationID = TextSecurePreferences.getLocalRegistrationId(context)
if (registrationID == 0) return null
var registrationID = TextSecurePreferences.getLocalRegistrationId(context)
if (registrationID == 0) {
registrationID = KeyHelper.generateRegistrationId(false)
TextSecurePreferences.setLocalRegistrationId(context, registrationID)
}
val deviceID = SignalServiceAddress.DEFAULT_DEVICE_ID
return PreKeyBundle(registrationID, deviceID,preKeyRecord.id, preKeyRecord.keyPair.publicKey, signedPreKey.id, signedPreKey.keyPair.publicKey, signedPreKey.signature, identityKeyPair.publicKey)
val preKeyRecord = DatabaseFactory.getLokiPreKeyRecordDatabase(context).getOrCreatePreKey(hexEncodedPublicKey)
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
Log.d("Loki", "A signed pre key has already been registered.")
} else {
Log.d("Loki", "Registering a new signed pre key.")
PreKeyUtil.generateSignedPreKey(context, identityKeyPair, true)
TextSecurePreferences.setSignedPreKeyRegistered(context, true)
}
val activeSignedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null
return PreKeyBundle(registrationID, deviceID, preKeyRecord.id, preKeyRecord.keyPair.publicKey, activeSignedPreKey.id, activeSignedPreKey.keyPair.publicKey, activeSignedPreKey.signature, identityKeyPair.publicKey)
}
override fun getPreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {

View File

@ -21,7 +21,7 @@ public class RotateSignedPreKeyListener extends PersistentAlarmManagerListener {
@Override
protected long onAlarm(Context context, long scheduledTime) {
if (scheduledTime != 0 && TextSecurePreferences.isPushRegistered(context)) {
if (scheduledTime != 0 /*&& TextSecurePreferences.isPushRegistered(context)*/) {
ApplicationContext.getInstance(context)
.getJobManager()
.add(new RotateSignedPreKeyJob());