diff --git a/app/src/androidTest/kotlin/io/privkey/keep/CertificatePinHoldsCardTest.kt b/app/src/androidTest/kotlin/io/privkey/keep/CertificatePinHoldsCardTest.kt new file mode 100644 index 00000000..e83fe209 --- /dev/null +++ b/app/src/androidTest/kotlin/io/privkey/keep/CertificatePinHoldsCardTest.kt @@ -0,0 +1,106 @@ +package io.privkey.keep + +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onAllNodesWithText +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performTextInput +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import io.privkey.keep.ui.theme.KeepAndroidTheme +import io.privkey.keep.uniffi.CertificatePinHolds +import org.junit.Assert.assertEquals +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +/** + * A relay whose pin was removed stays disconnected until the user acts, so the card has to + * show it and offer the way back for each one, including the case where the core could not + * read which hosts it holds. + */ +@RunWith(AndroidJUnit4::class) +class CertificatePinHoldsCardTest { + + // createComposeRule() is deprecated in favor of the v2 API; the classic rule + // is intentional here, and the project builds with -Werror. + @Suppress("DEPRECATION") + @get:Rule + val compose = createComposeRule() + + private val context = InstrumentationRegistry.getInstrumentation().targetContext + private val trustNext get() = context.getString(R.string.settings_cert_pins_trust_next) + private val trustHost get() = context.getString(R.string.settings_cert_pins_trust_host) + private val heldTitle get() = context.getString(R.string.settings_cert_pins_held_title) + + private fun show(holds: CertificatePinHolds?, trusted: MutableList) = compose.setContent { + KeepAndroidTheme { + CertificatePinsCard( + pins = emptyList(), + holds = holds, + onStagePin = { _, _ -> }, + onRetirePin = { _, _ -> }, + onTrustNextKey = { trusted += it }, + onClearAllPins = {}, + ) + } + } + + @Test + fun eachHeldHostOffersToTrustItsNextKey() { + val trusted = mutableListOf() + show(CertificatePinHolds(listOf("relay.one.com", "relay.two.com"), false, emptyList()), trusted) + + compose.onNodeWithText(heldTitle).assertIsDisplayed() + compose.onNodeWithText("relay.two.com").assertIsDisplayed() + compose.onAllNodesWithText(trustNext)[1].performClick() + assertEquals("nothing is trusted before the warning is confirmed", emptyList(), trusted) + compose.onNodeWithText(context.getString(R.string.settings_cert_pins_trust_dialog_text, "relay.two.com")).assertIsDisplayed() + compose.onAllNodesWithText(trustNext).let { it[it.fetchSemanticsNodes().size - 1] }.performClick() + assertEquals(listOf("relay.two.com"), trusted) + assertEquals(0, compose.onAllNodesWithText(trustHost).fetchSemanticsNodes().size) + } + + @Test + fun unreadableHoldsOfferToTrustAHostByName() { + val trusted = mutableListOf() + show(CertificatePinHolds(emptyList(), true, emptyList()), trusted) + + compose.onNodeWithText(context.getString(R.string.settings_cert_pins_held_all_text)).assertIsDisplayed() + compose.onNodeWithText(trustHost).performClick() + compose.onNodeWithText(context.getString(R.string.settings_cert_pins_stage_host_label)).performTextInput(" relay.example.com ") + compose.onNodeWithText(trustNext).performClick() + assertEquals(emptyList(), trusted) + compose.onNodeWithText(context.getString(R.string.settings_cert_pins_trust_dialog_text, "relay.example.com")).assertIsDisplayed() + compose.onNodeWithText(trustNext).performClick() + assertEquals(listOf("relay.example.com"), trusted) + } + + @Test + fun cancellingTheWarningTrustsNothing() { + val trusted = mutableListOf() + show(CertificatePinHolds(listOf("relay.one.com"), false, emptyList()), trusted) + compose.onNodeWithText(trustNext).performClick() + compose.onNodeWithText(context.getString(R.string.settings_cancel)).performClick() + assertEquals(emptyList(), trusted) + } + + @Test + fun theMismatchDialogWarnsBeforeClearingAndTrusting() { + var cleared = 0 + compose.setContent { + KeepAndroidTheme { PinMismatchDialog("relay.example.com", onClearAndRetry = { cleared++ }, onDismiss = {}) } + } + compose.onNodeWithText(context.getString(R.string.main_clear_pin_and_retry_text, "relay.example.com")).assertIsDisplayed() + assertEquals(0, cleared) + compose.onNodeWithText(context.getString(R.string.main_clear_pin_and_retry)).performClick() + assertEquals(1, cleared) + } + + @Test + fun nothingHeldShowsNoSection() { + show(CertificatePinHolds(emptyList(), false, emptyList()), mutableListOf()) + assertEquals(0, compose.onAllNodesWithText(heldTitle).fetchSemanticsNodes().size) + } +} diff --git a/app/src/androidTest/kotlin/io/privkey/keep/approver/ApproverPinChangeE2ETest.kt b/app/src/androidTest/kotlin/io/privkey/keep/approver/ApproverPinChangeE2ETest.kt index ed0061ec..0c424ae4 100644 --- a/app/src/androidTest/kotlin/io/privkey/keep/approver/ApproverPinChangeE2ETest.kt +++ b/app/src/androidTest/kotlin/io/privkey/keep/approver/ApproverPinChangeE2ETest.kt @@ -18,6 +18,7 @@ import org.junit.runner.RunWith import java.security.KeyPairGenerator import java.security.KeyStore import java.security.PrivateKey +import java.net.URI import java.security.SecureRandom import java.security.Signature import java.security.interfaces.ECPublicKey @@ -26,9 +27,8 @@ import java.security.spec.ECGenParameterSpec /** * End-to-end: the app's own approver, paired with a gateway that never answers over a * public relay, is started again by the core after a certificate pin change. Once a - * change leaves its relay without a pin the restart is refused, and nothing in this - * process starts it either, since a start would trust whatever key the relay shows; only - * a start by hand does. Manual-only, since it needs the relay: run it with `-e approverManual 1`. + * change leaves its relay without a pin the relay is held: the restart is refused, and so + * is any start, until the user trusts the relay's next key. Manual-only, since it needs the relay: run it with `-e approverManual 1`. * The test key needs no biometric, unlike the app's approver key, and is deleted after. */ @RunWith(AndroidJUnit4::class) @@ -51,6 +51,8 @@ class ApproverPinChangeE2ETest { // The run clears every pin, so the device's own are put back after it. val mobile = checkNotNull(app.getKeepMobile()) { "Keep not initialized" } val devicePins = mobile.getCertificatePins() + val heldBefore = mobile.certificatePinHolds().hosts.toSet() + val relayHost = checkNotNull(URI(relay).host) val secret = ByteArray(32).also(SecureRandom()::nextBytes).joinToString("") { "%02x".format(it) } val uri = "keep-approver:v1?gateway=$GATEWAY&secret=$secret&relay=$relay" @@ -80,18 +82,25 @@ class ApproverPinChangeE2ETest { Thread.sleep(SETTLE_MS) assertFalse("nothing started the approver on an unpinned relay", handler.status().running) + assertTrue("clearing the pin holds the relay", relayHost in mobile.certificatePinHolds().hosts) controller.startIfPaired() - assertTrue("a start by hand serves again", awaitStatus(handler) { it.running && it.pairing }) + assertFalse("a start does not learn a key for a held relay", handler.status().running) + + assertTrue(app.releaseCertificatePinHold(relayHost)) + controller.startIfPaired() + assertTrue("a start after the user trusts the next key serves again", awaitStatus(handler) { it.running && it.pairing }) assertFalse(handler.status().paired) } finally { runCatching { handler.forget() } mobile.clearCertificatePins() devicePins.forEach { mobile.stageCertificatePin(it.hostname, it.spkiHash) } + (mobile.certificatePinHolds().hosts - heldBefore).forEach { mobile.releaseCertificatePinHold(it) } runCatching { controller.startIfPaired() } runCatching { keyStore().deleteEntry(ALIAS) } } assertFalse(handler.status().running) assertEquals(devicePins, mobile.getCertificatePins()) + assertEquals(heldBefore, mobile.certificatePinHolds().hosts.toSet()) } // The stop lands before the pin call returns, and the restart probes the relay before it diff --git a/app/src/main/kotlin/io/privkey/keep/KeepMobileApp.kt b/app/src/main/kotlin/io/privkey/keep/KeepMobileApp.kt index 3bf9e3e2..5c743082 100644 --- a/app/src/main/kotlin/io/privkey/keep/KeepMobileApp.kt +++ b/app/src/main/kotlin/io/privkey/keep/KeepMobileApp.kt @@ -52,6 +52,7 @@ import io.privkey.keep.uniffi.ProxyConfigInfo import io.privkey.keep.uniffi.RelayConfigInfo import io.privkey.keep.uniffi.SignPolicyStore import io.privkey.keep.uniffi.SigningAuditLog +import io.privkey.keep.uniffi.CertificatePinHolds import io.privkey.keep.uniffi.SigningRateLimiter import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope @@ -833,10 +834,37 @@ class KeepMobileApp : Application() { onLiveNodeDropped() } - fun clearCertificatePin(hostname: String) { - runCatching { keepMobile?.clearCertificatePin(hostname) } - .onSuccess { if (it != null) onLiveNodeDropped() } + fun clearCertificatePin(hostname: String): Boolean = + runCatching { checkNotNull(keepMobile).clearCertificatePin(hostname) } + .onSuccess { onLiveNodeDropped() } .onFailure { if (BuildConfig.DEBUG) Log.e(TAG, "Failed to clearCertificatePin: ${it::class.simpleName}") } + .isSuccess + + fun certificatePinHolds(): CertificatePinHolds? = + runCatching { keepMobile?.certificatePinHolds() } + .onFailure { if (BuildConfig.DEBUG) Log.e(TAG, "Failed to read certificatePinHolds: ${it::class.simpleName}") } + .getOrNull() + + /** + * Lets the next connection to [hostname] trust whatever key it shows, so callers gate it + * on the user. That choice is also the start the hold waited for: a bunker serving without + * the relay and a paired approver the hold stopped start again, and the caller reconnects + * the node. + */ + fun releaseCertificatePinHold(hostname: String): Boolean { + val released = runCatching { checkNotNull(keepMobile).releaseCertificatePinHold(hostname) } + .onFailure { if (BuildConfig.DEBUG) Log.e(TAG, "Failed to releaseCertificatePinHold: ${it::class.simpleName}") } + .isSuccess + if (!released) return false + io.privkey.keep.nip46.BunkerService.restartAfterNodeDrop() + approverController?.let { controller -> + applicationScope.launch(Dispatchers.IO) { + runCatching { controller.startIfPaired() }.onFailure { + if (BuildConfig.DEBUG) Log.e(TAG, "Failed to start approver: ${it::class.simpleName}") + } + } + } + return true } fun clearAllCertificatePins() { diff --git a/app/src/main/kotlin/io/privkey/keep/MainActivity.kt b/app/src/main/kotlin/io/privkey/keep/MainActivity.kt index 5c323a3b..4578b166 100644 --- a/app/src/main/kotlin/io/privkey/keep/MainActivity.kt +++ b/app/src/main/kotlin/io/privkey/keep/MainActivity.kt @@ -319,6 +319,8 @@ class MainActivity : FragmentActivity() { onReconnectRelays = { app.reconnectRelays() }, onSaveProxyConfig = app::saveProxyConfig, onClearCertificatePin = app::clearCertificatePin, + onCertificatePinHolds = app::certificatePinHolds, + onReleaseCertificatePinHold = app::releaseCertificatePinHold, onClearAllCertificatePins = app::clearAllCertificatePins, onStageCertificatePin = app::stageCertificatePin, onRemoveCertificatePin = { hostname, spkiHash -> @@ -467,7 +469,9 @@ fun MainScreen( onBunkerServiceChanged: (Boolean) -> Unit = {}, onReconnectRelays: () -> Unit = {}, onSaveProxyConfig: (ProxyConfigInfo) -> Unit, - onClearCertificatePin: (String) -> Unit = {}, + onClearCertificatePin: (String) -> Boolean = { false }, + onCertificatePinHolds: () -> CertificatePinHolds? = { null }, + onReleaseCertificatePinHold: (String) -> Boolean = { false }, onClearAllCertificatePins: () -> Unit = {}, onStageCertificatePin: (String, String) -> Boolean = { _, _ -> false }, onRemoveCertificatePin: (String, String) -> CertPinRemoval? = { _, _ -> null }, @@ -598,6 +602,7 @@ fun MainScreen( val bunkerUrl by BunkerService.bunkerUrl.collectAsState() val bunkerStatus by BunkerService.status.collectAsState() var certificatePins by remember { mutableStateOf(emptyList()) } + var certificatePinHolds by remember { mutableStateOf(null) } var profileRelays by remember { mutableStateOf(emptyList()) } var showSecuritySettings by remember { mutableStateOf(false) } var showExportLogs by remember { mutableStateOf(false) } @@ -711,10 +716,24 @@ fun MainScreen( suspend fun refreshCertificatePins() { certificatePins = withContext(Dispatchers.IO) { keepMobile.getCertificatePinsCompat() } + certificatePinHolds = withContext(Dispatchers.IO) { onCertificatePinHolds() } } LaunchedEffect(Unit) { refreshCertificatePins() } + suspend fun afterRelease(hostname: String, released: Boolean) { + refreshCertificatePins() + if (released) { + onReconnectRelays() + } else { + Toast.makeText( + appContext, + appContext.getString(R.string.settings_cert_pins_trust_failed, hostname), + Toast.LENGTH_LONG + ).show() + } + } + fun loadProfileRelays(accountKey: String?): List { if (accountKey == null) return emptyList() return runCatching { keepMobile.getRelayConfig(accountKey).profileRelays }.getOrDefault(emptyList()) @@ -1612,16 +1631,19 @@ fun MainScreen( PinMismatchDialog( hostname = pinMismatchInfo.hostname, onClearAndRetry = { - // Clearing a pin re-opens trust-on-first-use for this host (here, right after - // a possible-MITM mismatch), so require a fresh auth factor first. + // Clearing holds the host, so the retry needs the hold released too: trusting + // the key it now shows, right after a possible MITM, is what this asks for, + // so both steps sit behind one fresh auth factor. requireAuthThen( appContext.getString(R.string.settings_cert_pins_clear_dialog_title), - appContext.getString(R.string.settings_cert_pins_clear_dialog_text, pinMismatchInfo.hostname), + appContext.getString(R.string.main_clear_pin_and_retry_text, pinMismatchInfo.hostname), appContext.getString(R.string.settings_cert_pins_clear), ) { - withContext(Dispatchers.IO) { onClearCertificatePin(pinMismatchInfo.hostname) } - refreshCertificatePins() - onReconnectRelays() + val trusted = withContext(Dispatchers.IO) { + onClearCertificatePin(pinMismatchInfo.hostname) && + onReleaseCertificatePinHold(pinMismatchInfo.hostname) + } + afterRelease(pinMismatchInfo.hostname, trusted) } }, onDismiss = onDismissPinMismatch @@ -1906,6 +1928,7 @@ fun MainScreen( // Null (not running) also covers a stale state left by a stop or error. relayHealth = appLiveState?.relays?.takeIf { isConnected || isConnecting }, certificatePins = certificatePins, + certificatePinHolds = certificatePinHolds, proxyEnabled = proxyEnabled, proxyPort = proxyPort, autoStartEnabled = autoStartEnabled, @@ -1999,7 +2022,14 @@ fun MainScreen( // retiring pins one at a time. requireAuthThen( appContext.getString(R.string.settings_cert_pins_clear_dialog_title), - appContext.getString(R.string.settings_cert_pins_clear_dialog_text, hostname), + appContext.getString( + if (isLastPinForHost(certificatePins, hostname)) { + R.string.settings_cert_pins_retire_last_dialog_text + } else { + R.string.settings_cert_pins_retire_keep_others + }, + hostname + ), appContext.getString(R.string.settings_cert_pins_clear), ) { val removal = withContext(Dispatchers.IO) { @@ -2015,6 +2045,15 @@ fun MainScreen( } } }, + onTrustNextKey = { hostname -> + requireAuthThen( + appContext.getString(R.string.settings_cert_pins_trust_dialog_title), + appContext.getString(R.string.settings_cert_pins_trust_dialog_text, hostname), + appContext.getString(R.string.settings_cert_pins_trust_next), + ) { + afterRelease(hostname, withContext(Dispatchers.IO) { onReleaseCertificatePinHold(hostname) }) + } + }, onClearAllPins = { requireAuthThen( appContext.getString(R.string.settings_cert_pins_clear_all_dialog_title), @@ -2376,6 +2415,7 @@ private fun SettingsTab( relayConfigUnreadable: Boolean, relayHealth: List?, certificatePins: List, + certificatePinHolds: CertificatePinHolds?, proxyEnabled: Boolean, proxyPort: Int, autoStartEnabled: Boolean, @@ -2388,6 +2428,7 @@ private fun SettingsTab( onResetRelayConfig: () -> Unit, onStagePin: (String, String) -> Unit, onRetirePin: (String, String) -> Unit, + onTrustNextKey: (String) -> Unit, onClearAllPins: () -> Unit, onProxyActivate: (Int) -> Unit, onProxyDeactivate: () -> Unit, @@ -2431,6 +2472,7 @@ private fun SettingsTab( relayConfigUnreadable = relayConfigUnreadable, relayHealth = relayHealth, certificatePins = certificatePins, + certificatePinHolds = certificatePinHolds, proxyEnabled = proxyEnabled, proxyPort = proxyPort, onAddRelay = onAddRelay, @@ -2440,6 +2482,7 @@ private fun SettingsTab( onResetRelayConfig = onResetRelayConfig, onStagePin = onStagePin, onRetirePin = onRetirePin, + onTrustNextKey = onTrustNextKey, onClearAllPins = onClearAllPins, onProxyActivate = onProxyActivate, onProxyDeactivate = onProxyDeactivate @@ -2798,7 +2841,7 @@ private fun DiscardPendingDkgDialog( } @Composable -private fun PinMismatchDialog( +internal fun PinMismatchDialog( hostname: String, onClearAndRetry: () -> Unit, onDismiss: () -> Unit @@ -2807,7 +2850,11 @@ private fun PinMismatchDialog( onDismissRequest = onDismiss, title = { Text(stringResource(R.string.main_pin_mismatch_title)) }, text = { - Text(stringResource(R.string.main_pin_mismatch_text, hostname)) + // Shown here, not only in the auth prompt, which a device with no lock skips. + Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { + Text(stringResource(R.string.main_pin_mismatch_text, hostname)) + Text(stringResource(R.string.main_clear_pin_and_retry_text, hostname)) + } }, confirmButton = { TextButton(onClick = onClearAndRetry) { Text(stringResource(R.string.main_clear_pin_and_retry)) } @@ -2825,6 +2872,7 @@ private fun ShareSettingsSection( relayConfigUnreadable: Boolean, relayHealth: List?, certificatePins: List, + certificatePinHolds: CertificatePinHolds?, proxyEnabled: Boolean, proxyPort: Int, onAddRelay: (String) -> Unit, @@ -2834,6 +2882,7 @@ private fun ShareSettingsSection( onResetRelayConfig: () -> Unit, onStagePin: (String, String) -> Unit, onRetirePin: (String, String) -> Unit, + onTrustNextKey: (String) -> Unit, onClearAllPins: () -> Unit, onProxyActivate: (Int) -> Unit, onProxyDeactivate: () -> Unit @@ -2853,8 +2902,10 @@ private fun ShareSettingsSection( CertificatePinsCard( pins = certificatePins, + holds = certificatePinHolds, onStagePin = onStagePin, onRetirePin = onRetirePin, + onTrustNextKey = onTrustNextKey, onClearAllPins = onClearAllPins ) Spacer(modifier = Modifier.height(16.dp)) diff --git a/app/src/main/kotlin/io/privkey/keep/SecurityCards.kt b/app/src/main/kotlin/io/privkey/keep/SecurityCards.kt index f18096ab..9a9b09bc 100644 --- a/app/src/main/kotlin/io/privkey/keep/SecurityCards.kt +++ b/app/src/main/kotlin/io/privkey/keep/SecurityCards.kt @@ -1,6 +1,7 @@ package io.privkey.keep import io.privkey.keep.ui.components.KeepCard +import io.privkey.keep.uniffi.CertificatePinHolds import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons @@ -229,12 +230,16 @@ internal fun isValidSpkiHash(hash: String): Boolean = @Composable fun CertificatePinsCard( pins: List, + holds: CertificatePinHolds?, onStagePin: (String, String) -> Unit, onRetirePin: (String, String) -> Unit, + onTrustNextKey: (String) -> Unit, onClearAllPins: () -> Unit ) { var showClearAllDialog by remember { mutableStateOf(false) } var showStageDialog by remember { mutableStateOf(false) } + var showTrustHostDialog by remember { mutableStateOf(false) } + var hostToTrust by remember { mutableStateOf(null) } var pinToRetire by remember { mutableStateOf(null) } KeepCard(contentPadding = PaddingValues(0.dp)) { @@ -251,13 +256,14 @@ fun CertificatePinsCard( } } } - if (pins.isEmpty()) { + val held = holds?.takeIf { it.hosts.isNotEmpty() || it.everyUnpinnedHost } + if (pins.isEmpty() && held == null) { Text( stringResource(R.string.settings_cert_pins_empty), color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodySmall ) - } else { + } else if (pins.isNotEmpty()) { pins.forEach { pin -> Row( modifier = Modifier @@ -293,9 +299,45 @@ fun CertificatePinsCard( TextButton(onClick = { showStageDialog = true }) { Text(stringResource(R.string.settings_cert_pins_stage)) } + if (held != null) { + HeldHostsSection(held, onTrustNextKey = { hostToTrust = it }, onTrustOtherHost = { showTrustHostDialog = true }) + } } } + if (showTrustHostDialog) { + TrustHostDialog( + onDismiss = { showTrustHostDialog = false }, + onTrust = { host -> + hostToTrust = host + showTrustHostDialog = false + } + ) + } + + // The one action here that trusts a key on first use, so the warning is shown in the app + // whatever the lock: the gate after it may be a biometric prompt or no prompt at all. + hostToTrust?.let { host -> + AlertDialog( + onDismissRequest = { hostToTrust = null }, + title = { Text(stringResource(R.string.settings_cert_pins_trust_dialog_title)) }, + text = { Text(stringResource(R.string.settings_cert_pins_trust_dialog_text, host)) }, + confirmButton = { + TextButton(onClick = { + onTrustNextKey(host) + hostToTrust = null + }) { + Text(stringResource(R.string.settings_cert_pins_trust_next), color = MaterialTheme.colorScheme.error) + } + }, + dismissButton = { + TextButton(onClick = { hostToTrust = null }) { + Text(stringResource(R.string.settings_cancel)) + } + } + ) + } + pinToRetire?.let { pin -> val lastPin = isLastPinForHost(pins, pin.hostname) AlertDialog( @@ -358,6 +400,73 @@ fun CertificatePinsCard( } } +@Composable +private fun HeldHostsSection( + holds: CertificatePinHolds, + onTrustNextKey: (String) -> Unit, + onTrustOtherHost: () -> Unit +) { + Spacer(modifier = Modifier.height(8.dp)) + Text(stringResource(R.string.settings_cert_pins_held_title), style = MaterialTheme.typography.titleSmall) + Text( + stringResource( + if (holds.everyUnpinnedHost) R.string.settings_cert_pins_held_all_text else R.string.settings_cert_pins_held_text + ), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + holds.hosts.forEach { host -> + Row( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 4.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically + ) { + Text(host, style = MaterialTheme.typography.bodyMedium, modifier = Modifier.weight(1f)) + TextButton(onClick = { onTrustNextKey(host) }) { + Text(stringResource(R.string.settings_cert_pins_trust_next)) + } + } + } + if (holds.everyUnpinnedHost) { + TextButton(onClick = onTrustOtherHost) { + Text(stringResource(R.string.settings_cert_pins_trust_host)) + } + } +} + +@Composable +private fun TrustHostDialog( + onDismiss: () -> Unit, + onTrust: (String) -> Unit +) { + var host by remember { mutableStateOf("") } + val hostTrimmed = host.trim() + AlertDialog( + onDismissRequest = onDismiss, + title = { Text(stringResource(R.string.settings_cert_pins_trust_host)) }, + text = { + OutlinedTextField( + value = host, + onValueChange = { host = it }, + label = { Text(stringResource(R.string.settings_cert_pins_stage_host_label)) }, + singleLine = true + ) + }, + confirmButton = { + TextButton(onClick = { onTrust(hostTrimmed) }, enabled = hostTrimmed.isNotEmpty()) { + Text(stringResource(R.string.settings_cert_pins_trust_next)) + } + }, + dismissButton = { + TextButton(onClick = onDismiss) { + Text(stringResource(R.string.settings_cancel)) + } + } + ) +} + @Composable private fun StageBackupPinDialog( onDismiss: () -> Unit, diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index 09b52a39..66620d29 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -125,6 +125,7 @@ Certificate Pin Mismatch The certificate for %1$s has changed. This could indicate a security issue or a legitimate certificate rotation. Clear Pin & Retry + Remove the certificate pin for %1$s and trust the certificate it shows on the next connection? If you do not know why it changed, someone may be intercepting the connection. Dismiss Database: %1$s MB Clean up expired data diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index c35c3f46..01045c52 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -93,14 +93,22 @@ Pins are set on first connection to each relay Clear pin Clear Pin? - Remove the certificate pin for %1$s? A new pin will be set on next connection. + Remove the certificate pin for %1$s? The relay stays disconnected until you stage a new pin or choose to trust its next key. Clear Clear All Pins? - This will remove all stored certificate pins. New pins will be set on next connection. + This will remove all stored certificate pins. Each relay that had one stays disconnected until you stage a new pin or choose to trust its next key. Remove this pin for %1$s? The host\'s other pins stay active. - This is the only pin for %1$s. Removing it leaves the relay unpinned, so the next connection trusts whatever certificate is presented (including an attacker\'s). Only continue if you intend to reset this relay\'s pin. - %1$s is now unpinned; the next connection sets a new pin. + This is the only pin for %1$s. Removing it leaves the relay disconnected until you stage a new pin or choose to trust its next key. + %1$s has no pin now and stays disconnected until you stage one or trust its next key. Stage backup pin + Waiting for a new key + These relays had their pin removed. They stay disconnected until you stage a new pin or trust the key they show next. + Your pin records could not be read, so every relay without a pin stays disconnected until you stage a pin for it or trust its next key. + Trust next key + Trust a relay\'s next key + Trust Next Key? + The next connection to %1$s will trust whatever certificate it shows, including an attacker\'s, and pin it. Only continue if you know why its pin was removed. + Could not trust the next key for %1$s Stage Backup Pin Add a backup certificate pin so a relay key rotation verifies against the current or the next certificate during the overlap. Any certificate matching a pin is fully trusted: only enter a hash you obtained from the relay operator over a trusted channel. Relay host diff --git a/keep.version b/keep.version index 4409ca72..93567bbe 100644 --- a/keep.version +++ b/keep.version @@ -1 +1 @@ -b8499dca0936adf69f418ccbace9464bde979072 +44a0b3aa0949cb8fc7c6e2b836707f88130d19f4