Fix narrow race around generation of some ACI keys.

This commit is contained in:
Greyson Parrelli
2022-03-10 11:11:14 -05:00
parent 66f93e0d32
commit 80bfa103ab
3 changed files with 22 additions and 3 deletions

View File

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