Fix narrow race around generation of some ACI keys.
This commit is contained in:
parent
66f93e0d32
commit
80bfa103ab
3 changed files with 22 additions and 3 deletions
|
@ -61,7 +61,7 @@ public class PassphraseCreateActivity extends PassphraseActivity {
|
|||
passphrase);
|
||||
|
||||
MasterSecretUtil.generateAsymmetricMasterSecret(PassphraseCreateActivity.this, masterSecret);
|
||||
SignalStore.account().generateAciIdentityKey();
|
||||
SignalStore.account().generateAciIdentityKeyIfNecessary();
|
||||
SignalStore.account().generatePniIdentityKeyIfNecessary();
|
||||
VersionTracker.updateLastSeenVersion(PassphraseCreateActivity.this);
|
||||
|
||||
|
|
|
@ -296,8 +296,19 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr
|
|||
throw new IllegalStateException("No PNI set!");
|
||||
}
|
||||
|
||||
boolean needsPreKeyJob = false;
|
||||
|
||||
if (!SignalStore.account().hasAciIdentityKey()) {
|
||||
SignalStore.account().generateAciIdentityKeyIfNecessary();
|
||||
needsPreKeyJob = true;
|
||||
}
|
||||
|
||||
if (!SignalStore.account().hasPniIdentityKey()) {
|
||||
SignalStore.account().generatePniIdentityKeyIfNecessary();
|
||||
needsPreKeyJob = true;
|
||||
}
|
||||
|
||||
if (needsPreKeyJob) {
|
||||
CreateSignedPreKeyJob.enqueueIfNeeded();
|
||||
}
|
||||
|
||||
|
|
|
@ -150,11 +150,19 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
|
|||
)
|
||||
}
|
||||
|
||||
fun hasAciIdentityKey(): Boolean {
|
||||
return store.containsKey(KEY_ACI_IDENTITY_PUBLIC_KEY)
|
||||
}
|
||||
|
||||
/** Generates and saves an identity key pair for the ACI identity. Should only be done once. */
|
||||
fun generateAciIdentityKey() {
|
||||
fun generateAciIdentityKeyIfNecessary() {
|
||||
synchronized(this) {
|
||||
if (store.containsKey(KEY_ACI_IDENTITY_PUBLIC_KEY)) {
|
||||
Log.w(TAG, "Tried to generate an ANI identity, but one was already set!", Throwable())
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue