Guard against invalid seeds

This commit is contained in:
Niels Andriesse 2019-08-21 09:50:03 +10:00
parent 80be7e37d0
commit 313acacedf

View File

@ -76,7 +76,13 @@ class SeedActivity : BaseActionBarActivity() {
// region Updating // region Updating
private fun updateSeed() { private fun updateSeed() {
seed = Curve25519.getInstance("best").generateSeed(16) val seed = Curve25519.getInstance(Curve25519.BEST).generateSeed(16)
try {
IdentityKeyUtil.generateIdentityKeyPair(this, seed + seed)
} catch (exception: Exception) {
return updateSeed()
}
this.seed = seed
} }
private fun updateUI() { private fun updateUI() {
@ -138,9 +144,12 @@ class SeedActivity : BaseActionBarActivity() {
} }
} }
} }
IdentityKeyUtil.save(this, IdentityKeyUtil.lokiSeedKey, Hex.toStringCondensed(seed)) val hexEncodedSeed = Hex.toStringCondensed(seed)
IdentityKeyUtil.save(this, IdentityKeyUtil.lokiSeedKey, hexEncodedSeed)
if (seed.count() == 16) seed = seed + seed if (seed.count() == 16) seed = seed + seed
if (mode == Mode.Restore) {
IdentityKeyUtil.generateIdentityKeyPair(this, seed) IdentityKeyUtil.generateIdentityKeyPair(this, seed)
}
val keyPair = IdentityKeyUtil.getIdentityKeyPair(this) val keyPair = IdentityKeyUtil.getIdentityKeyPair(this)
val publicKey = keyPair.publicKey val publicKey = keyPair.publicKey
val hexEncodedPublicKey = keyPair.hexEncodedPublicKey val hexEncodedPublicKey = keyPair.hexEncodedPublicKey