fix: clear public key when private key edited (#2190)

This commit is contained in:
James Rich 2025-06-20 18:47:52 +00:00 committed by GitHub
parent 7acc5ef8e8
commit b5a503c0cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View file

@ -34,6 +34,7 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
@ -59,6 +60,7 @@ import com.geeksville.mesh.ui.common.components.SwitchPreference
import com.geeksville.mesh.ui.node.NodeActionButton
import com.geeksville.mesh.ui.radioconfig.RadioConfigViewModel
import com.geeksville.mesh.util.encodeToString
import com.geeksville.mesh.util.toByteString
import com.google.protobuf.ByteString
import java.security.SecureRandom
@ -103,6 +105,15 @@ fun SecurityConfigItemList(
val focusManager = LocalFocusManager.current
var securityInput by rememberSaveable { mutableStateOf(securityConfig) }
var publicKey by rememberSaveable { mutableStateOf(securityInput.publicKey) }
LaunchedEffect(securityInput.privateKey) {
if (securityInput.privateKey != securityConfig.privateKey) {
publicKey = "".toByteString()
} else if (securityInput.privateKey == securityConfig.privateKey) {
publicKey = securityConfig.publicKey
}
}
val exportConfigLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
@ -157,7 +168,7 @@ fun SecurityConfigItemList(
item {
EditBase64Preference(
title = stringResource(R.string.public_key),
value = securityInput.publicKey,
value = publicKey,
enabled = enabled,
readOnly = true,
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
@ -314,6 +325,7 @@ fun PrivateKeyRegenerateDialog(
onClick = {
securityInput = securityInput.copy {
clearPrivateKey()
clearPublicKey()
// Generate a random "f" value
val f = ByteArray(32).apply {
SecureRandom().nextBytes(this)

View file

@ -689,7 +689,7 @@
<string name="client_notification">Client Notification</string>
<string name="compromised_keys">Compromised keys detected, select OK to regenerate.</string>
<string name="regenerate_private_key">Regenerate Private Key</string>
<string name="regenerate_keys_confirmation">Are you sure you want to regenerate your Private Key?</string>
<string name="regenerate_keys_confirmation">Are you sure you want to regenerate your Private Key?\n\nNodes that may have previously exchanged keys with this node will need to Remove that node and re-exchange keys in order to resume secure communication.</string>
<string name="export_keys">Export Keys</string>
<string name="export_keys_confirmation">Exports public and private keys to a file. Please store somewhere securely.</string>
</resources>