mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 18:26:57 +00:00
Allow late initialization of some PNI keys.
This commit is contained in:
@@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.jobmanager.JobManager;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigrator;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.FactoryJobPredicate;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer;
|
||||
import org.thoughtcrime.securesms.jobs.CreateSignedPreKeyJob;
|
||||
import org.thoughtcrime.securesms.jobs.FastJobStorage;
|
||||
import org.thoughtcrime.securesms.jobs.GroupCallUpdateSendJob;
|
||||
import org.thoughtcrime.securesms.jobs.JobManagerFactories;
|
||||
@@ -289,6 +290,11 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
|
||||
throw new IllegalStateException("No PNI set!");
|
||||
}
|
||||
|
||||
if (!SignalStore.account().hasPniIdentityKey()) {
|
||||
SignalStore.account().generatePniIdentityKey();
|
||||
CreateSignedPreKeyJob.enqueueIfNeeded();
|
||||
}
|
||||
|
||||
SignalBaseIdentityKeyStore baseIdentityStore = new SignalBaseIdentityKeyStore(context);
|
||||
|
||||
SignalServiceAccountDataStoreImpl aciStore = new SignalServiceAccountDataStoreImpl(context,
|
||||
|
||||
@@ -151,15 +151,17 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
|
||||
|
||||
/** Generates and saves an identity key pair for the ACI identity. Should only be done once. */
|
||||
fun generateAciIdentityKey() {
|
||||
Log.i(TAG, "Generating a new ACI identity key pair.")
|
||||
require(!store.containsKey(KEY_ACI_IDENTITY_PUBLIC_KEY)) { "Already generated!" }
|
||||
synchronized(this) {
|
||||
Log.i(TAG, "Generating a new ACI identity key pair.")
|
||||
require(!store.containsKey(KEY_ACI_IDENTITY_PUBLIC_KEY)) { "Already generated!" }
|
||||
|
||||
val key: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_ACI_IDENTITY_PUBLIC_KEY, key.publicKey.serialize())
|
||||
.putBlob(KEY_ACI_IDENTITY_PRIVATE_KEY, key.privateKey.serialize())
|
||||
.commit()
|
||||
val key: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_ACI_IDENTITY_PUBLIC_KEY, key.publicKey.serialize())
|
||||
.putBlob(KEY_ACI_IDENTITY_PRIVATE_KEY, key.privateKey.serialize())
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
fun hasPniIdentityKey(): Boolean {
|
||||
@@ -168,25 +170,29 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
|
||||
|
||||
/** Generates and saves an identity key pair for the PNI identity. Should only be done once. */
|
||||
fun generatePniIdentityKey() {
|
||||
Log.i(TAG, "Generating a new PNI identity key pair.")
|
||||
require(!store.containsKey(KEY_PNI_IDENTITY_PUBLIC_KEY)) { "Already generated!" }
|
||||
synchronized(this) {
|
||||
Log.i(TAG, "Generating a new PNI identity key pair.")
|
||||
require(!store.containsKey(KEY_PNI_IDENTITY_PUBLIC_KEY)) { "Already generated!" }
|
||||
|
||||
val key: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_PNI_IDENTITY_PUBLIC_KEY, key.publicKey.serialize())
|
||||
.putBlob(KEY_PNI_IDENTITY_PRIVATE_KEY, key.privateKey.serialize())
|
||||
.commit()
|
||||
val key: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_PNI_IDENTITY_PUBLIC_KEY, key.publicKey.serialize())
|
||||
.putBlob(KEY_PNI_IDENTITY_PRIVATE_KEY, key.privateKey.serialize())
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
/** When acting as a linked device, this method lets you store the identity keys sent from the primary device */
|
||||
fun setIdentityKeysFromPrimaryDevice(aciKeys: IdentityKeyPair) {
|
||||
require(isLinkedDevice) { "Must be a linked device!" }
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_ACI_IDENTITY_PUBLIC_KEY, aciKeys.publicKey.serialize())
|
||||
.putBlob(KEY_ACI_IDENTITY_PRIVATE_KEY, aciKeys.privateKey.serialize())
|
||||
.commit()
|
||||
synchronized(this) {
|
||||
require(isLinkedDevice) { "Must be a linked device!" }
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_ACI_IDENTITY_PUBLIC_KEY, aciKeys.publicKey.serialize())
|
||||
.putBlob(KEY_ACI_IDENTITY_PRIVATE_KEY, aciKeys.privateKey.serialize())
|
||||
.commit()
|
||||
}
|
||||
}
|
||||
|
||||
/** Only to be used when restoring an identity public key from an old backup */
|
||||
|
||||
Reference in New Issue
Block a user