mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: Ensure valid private key generation (#2160)
This commit is contained in:
parent
1556019803
commit
1928fb64fa
1 changed files with 13 additions and 6 deletions
|
|
@ -118,6 +118,7 @@ fun SecurityConfigItemList(
|
|||
onConfirm = { newConfig ->
|
||||
securityInput = newConfig
|
||||
showKeyGenerationDialog = false
|
||||
onConfirm(securityInput)
|
||||
},
|
||||
onDismiss = { showKeyGenerationDialog = false }
|
||||
)
|
||||
|
|
@ -294,6 +295,7 @@ fun SecurityConfigItemList(
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
@Composable
|
||||
fun PrivateKeyRegenerateDialog(
|
||||
showKeyGenerationDialog: Boolean,
|
||||
|
|
@ -312,12 +314,17 @@ fun PrivateKeyRegenerateDialog(
|
|||
onClick = {
|
||||
securityInput = securityInput.copy {
|
||||
clearPrivateKey()
|
||||
@Suppress("MagicNumber")
|
||||
privateKey = ByteString.copyFrom(
|
||||
ByteArray(32).apply {
|
||||
SecureRandom().nextBytes(this)
|
||||
}
|
||||
)
|
||||
// Generate a random "f" value
|
||||
val f = ByteArray(32).apply {
|
||||
SecureRandom().nextBytes(this)
|
||||
}
|
||||
// Adjust the value to make it valid as an "s" value for eval().
|
||||
// According to the specification we need to mask off the 3
|
||||
// right-most bits of f[0], mask off the left-most bit of f[31],
|
||||
// and set the second to left-most bit of f[31].
|
||||
f[0] = (f[0].toInt() and 0xF8).toByte()
|
||||
f[31] = ((f[31].toInt() and 0x7F) or 0x40).toByte()
|
||||
privateKey = ByteString.copyFrom(f)
|
||||
}
|
||||
onConfirm(securityInput)
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue