mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Fix pre key usage
This commit is contained in:
parent
e7f7c3cdb2
commit
dd67e59807
@ -156,7 +156,7 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
|||||||
throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException
|
throws UntrustedIdentityException, InsecureFallbackApprovalException, RetryLaterException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// rotateSenderCertificateIfNecessary(); // LOKITODO: Uncomment this?
|
// rotateSenderCertificateIfNecessary();
|
||||||
|
|
||||||
SignalServiceAddress address = getPushAddress(message.getIndividualRecipient().getAddress());
|
SignalServiceAddress address = getPushAddress(message.getIndividualRecipient().getAddress());
|
||||||
Optional<byte[]> profileKey = getProfileKey(message.getIndividualRecipient());
|
Optional<byte[]> profileKey = getProfileKey(message.getIndividualRecipient());
|
||||||
|
@ -55,9 +55,9 @@ public class RefreshPreKeysJob extends BaseJob implements InjectableType {
|
|||||||
@Override
|
@Override
|
||||||
public void onRun() throws IOException {
|
public void onRun() throws IOException {
|
||||||
if (TextSecurePreferences.isSignedPreKeyRegistered(context)) {
|
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 {
|
} else {
|
||||||
Log.i(TAG, "Registering new signed pre key...");
|
Log.d("Loki", "Registering a new signed pre key.");
|
||||||
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
|
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
|
||||||
PreKeyUtil.generateSignedPreKey(context, identityKey, true);
|
PreKeyUtil.generateSignedPreKey(context, identityKey, true);
|
||||||
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
|
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
|
||||||
|
@ -55,7 +55,7 @@ public class RotateSignedPreKeyJob extends BaseJob implements InjectableType {
|
|||||||
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
|
IdentityKeyPair identityKey = IdentityKeyUtil.getIdentityKeyPair(context);
|
||||||
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);
|
SignedPreKeyRecord signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(context, identityKey, false);
|
||||||
|
|
||||||
accountManager.setSignedPreKey(signedPreKeyRecord);
|
// accountManager.setSignedPreKey(signedPreKeyRecord);
|
||||||
|
|
||||||
PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
|
PreKeyUtil.setActiveSignedPreKeyId(context, signedPreKeyRecord.getId());
|
||||||
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
|
TextSecurePreferences.setSignedPreKeyRegistered(context, true);
|
||||||
|
@ -8,11 +8,13 @@ import org.thoughtcrime.securesms.crypto.PreKeyUtil
|
|||||||
import org.thoughtcrime.securesms.database.Database
|
import org.thoughtcrime.securesms.database.Database
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||||
|
import org.thoughtcrime.securesms.logging.Log
|
||||||
import org.thoughtcrime.securesms.util.Base64
|
import org.thoughtcrime.securesms.util.Base64
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
import org.whispersystems.libsignal.IdentityKey
|
import org.whispersystems.libsignal.IdentityKey
|
||||||
import org.whispersystems.libsignal.ecc.Curve
|
import org.whispersystems.libsignal.ecc.Curve
|
||||||
import org.whispersystems.libsignal.state.PreKeyBundle
|
import org.whispersystems.libsignal.state.PreKeyBundle
|
||||||
|
import org.whispersystems.libsignal.util.KeyHelper
|
||||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||||
import org.whispersystems.signalservice.loki.messaging.LokiPreKeyBundleDatabaseProtocol
|
import org.whispersystems.signalservice.loki.messaging.LokiPreKeyBundleDatabaseProtocol
|
||||||
|
|
||||||
@ -35,13 +37,23 @@ class LokiPreKeyBundleDatabase(context: Context, helper: SQLCipherOpenHelper) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun generatePreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
|
fun generatePreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
|
||||||
val identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context)
|
var registrationID = TextSecurePreferences.getLocalRegistrationId(context)
|
||||||
val signedPreKey = PreKeyUtil.getActiveSignedPreKey(context) ?: return null
|
if (registrationID == 0) {
|
||||||
val preKeyRecord = DatabaseFactory.getLokiPreKeyRecordDatabase(context).getOrCreatePreKey(hexEncodedPublicKey)
|
registrationID = KeyHelper.generateRegistrationId(false)
|
||||||
val registrationID = TextSecurePreferences.getLocalRegistrationId(context)
|
TextSecurePreferences.setLocalRegistrationId(context, registrationID)
|
||||||
if (registrationID == 0) return null
|
}
|
||||||
val deviceID = SignalServiceAddress.DEFAULT_DEVICE_ID
|
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? {
|
override fun getPreKeyBundle(hexEncodedPublicKey: String): PreKeyBundle? {
|
||||||
|
@ -21,7 +21,7 @@ public class RotateSignedPreKeyListener extends PersistentAlarmManagerListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected long onAlarm(Context context, long scheduledTime) {
|
protected long onAlarm(Context context, long scheduledTime) {
|
||||||
if (scheduledTime != 0 && TextSecurePreferences.isPushRegistered(context)) {
|
if (scheduledTime != 0 /*&& TextSecurePreferences.isPushRegistered(context)*/) {
|
||||||
ApplicationContext.getInstance(context)
|
ApplicationContext.getInstance(context)
|
||||||
.getJobManager()
|
.getJobManager()
|
||||||
.add(new RotateSignedPreKeyJob());
|
.add(new RotateSignedPreKeyJob());
|
||||||
|
Loading…
Reference in New Issue
Block a user