Fix narrow race around generation of some ACI keys.

fork-5.53.8
Greyson Parrelli 2022-03-10 11:11:14 -05:00
rodzic 66f93e0d32
commit 80bfa103ab
3 zmienionych plików z 22 dodań i 3 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

@ -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();
}

Wyświetl plik

@ -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