securemail: keystore-held S2K passphrase, decrypt on arrival
- Commit
9ca626ec3af2e732449001cc685ff4926e86f606- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-24 04:14 UTC (1 month ago)
- Parents
465093d
Diff
securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt b/securemail/src/main/java/com/vayunmathur/securemail/Navigation.ktindex a3863fbcbc..edf935400b 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/Navigation.kt@@ -64,7 +64,6 @@ fun Navigation(viewModel: MailViewModel, initialRoute: Route? = null) { (context as? FragmentActivity)?.let { viewModel.unlock(it) } }, onDismissMessages = viewModel::dismissMessages,- onPassphrase = viewModel::providePassphrase, ) } entry<Route.Inbox> {@@ -114,8 +113,6 @@ fun Navigation(viewModel: MailViewModel, initialRoute: Route? = null) { }, onBack = { backStack.pop() }, message = msg,- onProvidePassphrase = viewModel::providePassphrase,- onRetryDecrypt = { viewModel.decryptStored(route.messageId) }, ) } entry<Route.Outbox> {
securemail/src/main/java/com/vayunmathur/securemail/domain/mail/MimeCodec.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/domain/mail/MimeCodec.kt b/securemail/src/main/java/com/vayunmathur/securemail/domain/mail/MimeCodec.ktnew file mode 100644index 0000000000..79df56af3f--- /dev/null+++ b/securemail/src/main/java/com/vayunmathur/securemail/domain/mail/MimeCodec.kt@@ -0,0 +1,78 @@+package com.vayunmathur.securemail.domain.mail++/**+ * Pure MIME helpers shared by the receive path (service-side decrypt on+ * arrival) and the UI-side decrypt fallback. No Android imports — base64+ * stays at the call sites.+ */+object MimeCodec {++ /**+ * Extracts the raw PGP bytes from an RFC 3156 multipart/encrypted envelope+ * (second part, base64 `application/octet-stream`). Returns the base64+ * payload string, or null when the input is not such an envelope (legacy+ * bare blobs pass through undecrypted at a higher layer).+ */+ fun extractPgpPayloadB64(envelope: ByteArray): String? {+ return try {+ val text = envelope.toString(Charsets.UTF_8)+ if (!text.contains("application/pgp-encrypted")) return null+ // Split on boundary markers; the data part follows the octet-stream header.+ val octetIdx = text.indexOf("application/octet-stream")+ if (octetIdx < 0) return null+ val bodyStart = text.indexOf("\r\n\r\n", octetIdx).takeIf { it >= 0 }+ ?: text.indexOf("\n\n", octetIdx).takeIf { it >= 0 }+ ?: return null+ val afterHeaders = if (text.startsWith("\r\n\r\n", bodyStart)) {+ text.substring(bodyStart + 4)+ } else {+ text.substring(bodyStart + 2)+ }+ // Cut at the closing boundary; de-whitespace the base64.+ val end = afterHeaders.indexOf("--maemail-").takeIf { it >= 0 } ?: afterHeaders.length+ val b64 = afterHeaders.substring(0, end).filterNot { it.isWhitespace() }+ if (b64.isEmpty()) null else b64+ } catch (_: Exception) {+ null+ }+ }++ /**+ * Minimal parser for the MIME skeleton the composer emits (headers ++ * trailing `--boundary--`). Returns (subject, body, from). The payload is+ * already authenticated PGP plaintext at this point; this only splits it.+ */+ fun parseMime(mime: String): Triple<String, String, String> {+ val lines = mime.lines()+ var from = ""+ var subject = ""+ var i = 0+ while (i < lines.size && lines[i].isNotBlank()) {+ val line = lines[i]+ when {+ line.startsWith("From:", ignoreCase = true) ->+ from = line.substringAfter(':').trim()+ line.startsWith("Subject:", ignoreCase = true) ->+ subject = line.substringAfter(':').trim()+ }+ i+++ }+ // Skip the blank line plus the multipart preamble (boundary markers and+ // the Version part); the body is the last text block before --boundary--.+ val body = StringBuilder()+ var inBody = false+ for (line in lines.drop(i)) {+ if (line.startsWith("--maemail-")) {+ inBody = false+ continue+ }+ if (line.startsWith("Content-Type: text/plain", ignoreCase = true)) {+ inBody = false // headers of the part follow; blank line starts text+ continue+ }+ if (inBody) body.appendLine(line)+ if (line.isBlank()) inBody = true+ }+ return Triple(subject, body.toString().trimEnd(), from)+ }+}
securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.ktindex 386008a75e..a7ffdac028 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/MailViewModel.kt@@ -43,8 +43,6 @@ data class MailUiState( val busy: Boolean = false, /** Exported public key awaiting user copy/share (Settings). */ val exportArmor: String? = null,- /** True when the in-memory key passphrase was lost (process restart). */- val needsPassphrase: Boolean = false, ) private const val TAG = "MailViewModel"@@ -72,12 +70,21 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { val outboxMessages = repo.outboxDao().observeAll() /**- * In-memory S2K passphrase for the PGP secret ring. Set at claim time and- * re-entered on the Lock screen after process death; never persisted — the- * Keystore holds only the S2K-wrapped blob, so a DB dump alone is useless.+ * In-memory S2K passphrase for the PGP secret ring. Sealed in+ * Keystore-wrapped storage at claim time ([KeyManager.storeKeyPassphrase])+ * and loaded here on first need — the user enters it once at setup (and+ * keeps it for account recovery) and is never asked again. */ private var passphraseCache: String? = null + /**+ * Returns the S2K passphrase, loading it from Keystore-wrapped storage+ * on first use. Must be called on Dispatchers.IO (Keystore I/O).+ */+ private fun requirePassphrase(): String =+ passphraseCache ?: keyManager.getKeyPassphrase()?.also { passphraseCache = it }+ ?: error("No key passphrase stored — restore from your recovery passphrase.")+ init { config.settings .onEach { s ->@@ -120,6 +127,10 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { passphrase, ) keyManager.storeSecretArmor(identity.armoredSecret)+ // Seal the S2K passphrase in Keystore-wrapped storage now:+ // S2K runs transparently after this and is never asked for+ // again (the passphrase is still the recovery secret).+ keyManager.storeKeyPassphrase(passphrase) keyManager.storeOwnAddress(address) config.setIdentity(address, identity.armoredPublic, identity.fingerprintHex) passphraseCache = passphrase@@ -234,12 +245,9 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { runCatching { val stored = repo.messageDao().get(id) ?: return@runCatching if (stored.decryptedBody != null || stored.unencrypted) return@runCatching- val passphrase = passphraseCache- if (passphrase == null) {- state = state.copy(needsPassphrase = true)- Log.status(TAG, "decrypt deferred: passphrase cache empty")- return@runCatching- }+ // S2K passphrase loads transparently from Keystore-wrapped+ // storage (sealed at claim time) — never asked for again.+ val passphrase = requirePassphrase() val raw = Base64.decode(stored.blobBase64, Base64.NO_WRAP) val pgpBytes = extractPgpPayload(raw) ?: raw val mime = PgpCrypto.decrypt(pgpBytes, keyManager.getSecretArmor(), passphrase)@@ -250,12 +258,7 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { repo.messageDao().upsert(stored.copy(from = from)) } }.onFailure {- // Wrong passphrase (or corrupt blob) fails closed here with- // a visible error — not a silent "decrypting…" stall.- state = state.copy(- needsPassphrase = true,- error = "Could not decrypt — wrong passphrase?",- )+ state = state.copy(error = "Could not decrypt this message.") Log.status(TAG, "decryptStored failed", it) } }@@ -263,45 +266,19 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { } /**- * Extracts the raw PGP bytes from an RFC 3156 multipart/encrypted envelope- * (second part, base64 `application/octet-stream`). Returns null when the- * input is not such an envelope (legacy bare blobs pass through).+ * Extracts the raw PGP bytes from an RFC 3156 multipart/encrypted envelope.+ * Delegates to [com.vayunmathur.securemail.domain.mail.MimeCodec]. */ private fun extractPgpPayload(envelope: ByteArray): ByteArray? {+ val b64 = com.vayunmathur.securemail.domain.mail.MimeCodec+ .extractPgpPayloadB64(envelope) ?: return null return try {- val text = envelope.toString(Charsets.UTF_8)- if (!text.contains("application/pgp-encrypted")) return null- // Split on boundary markers; the data part follows the octet-stream header.- val octetIdx = text.indexOf("application/octet-stream")- if (octetIdx < 0) return null- val bodyStart = text.indexOf("\r\n\r\n", octetIdx).takeIf { it >= 0 }- ?: text.indexOf("\n\n", octetIdx).takeIf { it >= 0 }- ?: return null- val afterHeaders = if (text.startsWith("\r\n\r\n", bodyStart)) {- text.substring(bodyStart + 4)- } else {- text.substring(bodyStart + 2)- }- // Cut at the closing boundary; de-whitespace the base64.- val end = afterHeaders.indexOf("--maemail-").takeIf { it >= 0 } ?: afterHeaders.length- val b64 = afterHeaders.substring(0, end).filterNot { it.isWhitespace() }- if (b64.isEmpty()) return null android.util.Base64.decode(b64, android.util.Base64.DEFAULT) } catch (_: Exception) { null } } - /**- * Re-enters the S2K passphrase after process death (Lock screen). Verified- * by a trial decrypt of nothing — it is checked lazily on next decrypt,- * which fails closed and re-asks.- */- fun providePassphrase(passphrase: String) {- passphraseCache = passphrase- state = state.copy(needsPassphrase = false, error = null)- }- /** Plaintext fallback path: stores the body with the unencrypted flag set. */ suspend fun onInboundPlaintext(id: String, from: String, subject: String, body: String) { repo.messageDao().upsert(@@ -562,39 +539,8 @@ class MailViewModel(app: Application) : AndroidViewModel(app) { * trailing `--boundary--`). Returns (subject, body, from). The payload is * already authenticated PGP plaintext at this point; this only splits it. */- private fun parseMime(mime: String): Triple<String, String, String> {- val lines = mime.lines()- var from = ""- var subject = ""- var i = 0- while (i < lines.size && lines[i].isNotBlank()) {- val line = lines[i]- when {- line.startsWith("From:", ignoreCase = true) ->- from = line.substringAfter(':').trim()- line.startsWith("Subject:", ignoreCase = true) ->- subject = line.substringAfter(':').trim()- }- i++- }- // Skip the blank line plus the multipart preamble (boundary markers and- // the Version part); the body is the last text block before --boundary--.- val body = StringBuilder()- var inBody = false- for (line in lines.drop(i)) {- if (line.startsWith("--maemail-")) {- inBody = false- continue- }- if (line.startsWith("Content-Type: text/plain", ignoreCase = true)) {- inBody = false // headers of the part follow; blank line starts text- continue- }- if (inBody) body.appendLine(line)- if (line.isBlank()) inBody = true- }- return Triple(subject, body.toString().trimEnd(), from)- }+ private fun parseMime(mime: String): Triple<String, String, String> =+ com.vayunmathur.securemail.domain.mail.MimeCodec.parseMime(mime) private fun newMessageId(): String = "${UUID.randomUUID()}@maemail.org"
securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt b/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.ktindex bd577a3030..eda200a7cd 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/platform/crypto/KeyManager.kt@@ -6,13 +6,16 @@ import com.vayunmathur.library.util.DatabaseHelper /** * Custody for the SecureMail identity: the passphrase-wrapped PGP secret ring- * plus the relay address token, both wrapped by an AndroidKeyStore key reusing- * the repo's [DatabaseHelper] pattern (see backup's KeyManager).+ * plus the S2K passphrase itself and the relay address token, all wrapped by+ * an AndroidKeyStore key reusing the repo's [DatabaseHelper] pattern (see+ * backup's KeyManager). *- * The PGP private key itself is S2K-wrapped by the passphrase before it ever- * reaches this class, so two layers guard it: the S2K passphrase and the- * Keystore-wrapped storage. Decrypt/sign operations additionally gate on the- * biometric prompt (see MailViewModel.unlock) before [getSecretArmor] is read.+ * Layers: the PGP private key is S2K-wrapped by the user's passphrase (needed+ * once at setup, and for account recovery); the passphrase itself is then+ * sealed in Keystore-wrapped storage, so S2K runs transparently after first+ * unlock and is never asked for again. Decrypt/sign operations additionally+ * gate on the biometric prompt (see MailViewModel.unlock) before either+ * secret is read. */ class KeyManager(context: Context) : DatabaseHelper(context) { override val keyStoreAlias = "securemail_master_key"@@ -20,6 +23,12 @@ class KeyManager(context: Context) : DatabaseHelper(context) { override val passphraseKey = "encrypted_pgp_secret" override val ivKey = "pgp_secret_iv" + // S2K passphrase custody: same Keystore wrap, distinct prefs slot.+ // Stored raw (not base64) via storePassphrase-equivalent below — the+ // DatabaseHelper encrypts at rest either way.+ private val s2kPassphraseKey = "encrypted_s2k_passphrase"+ private val s2kIvKey = "s2k_passphrase_iv"+ private val tokenKey = "relay_address_token" private val addressKey = "own_address" @@ -34,6 +43,39 @@ class KeyManager(context: Context) : DatabaseHelper(context) { fun getSecretArmor(): String = String(Base64.decode(getPassphrase(), Base64.NO_WRAP), Charsets.UTF_8) + /**+ * Seals the S2K passphrase in Keystore-wrapped storage (separate slot+ * from the secret ring so either can be rotated independently).+ */+ fun storeKeyPassphrase(passphrase: String) {+ if (!isKeyGenerated()) generateKey()+ val cipher = getCipherForEncryption()+ val encrypted = cipher.doFinal(passphrase.toByteArray(Charsets.UTF_8))+ val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE)+ prefs.edit()+ .putString(s2kPassphraseKey, Base64.encodeToString(encrypted, Base64.NO_WRAP))+ .putString(s2kIvKey, Base64.encodeToString(cipher.iv, Base64.NO_WRAP))+ .apply()+ }++ /** Returns the sealed S2K passphrase, or null when never stored. */+ fun getKeyPassphrase(): String? {+ val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE)+ val enc = prefs.getString(s2kPassphraseKey, null) ?: return null+ val iv = prefs.getString(s2kIvKey, null) ?: return null+ return try {+ val cipher = javax.crypto.Cipher.getInstance("AES/GCM/NoPadding")+ cipher.init(+ javax.crypto.Cipher.DECRYPT_MODE,+ getSecretKey(),+ javax.crypto.spec.GCMParameterSpec(128, Base64.decode(iv, Base64.NO_WRAP)),+ )+ String(cipher.doFinal(Base64.decode(enc, Base64.NO_WRAP)), Charsets.UTF_8)+ } catch (_: Exception) {+ null+ }+ }+ fun storeRelayToken(token: String) { val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE) prefs.edit().putString(tokenKey, token).apply()@@ -55,6 +97,11 @@ class KeyManager(context: Context) : DatabaseHelper(context) { fun clear() { deleteKey() val prefs = context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE)- prefs.edit().remove(tokenKey).remove(addressKey).apply()+ prefs.edit()+ .remove(tokenKey)+ .remove(addressKey)+ .remove(s2kPassphraseKey)+ .remove(s2kIvKey)+ .apply() } }
securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt b/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.ktindex 87fc6c0f29..308813e13b 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/service/MailSocketService.kt@@ -9,7 +9,10 @@ import com.vayunmathur.library.util.ensureNotificationChannel import com.vayunmathur.securemail.data.MailConfig import com.vayunmathur.securemail.data.MailRepository import com.vayunmathur.securemail.data.StoredMessage+import com.vayunmathur.securemail.domain.mail.MimeCodec+import com.vayunmathur.securemail.domain.pgp.PgpCrypto import com.vayunmathur.securemail.network.MailSocket+import com.vayunmathur.securemail.platform.crypto.KeyManager import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob@@ -51,26 +54,82 @@ class MailSocketService : Service() { else MailSocket.IdentitySnapshot(current.address, current.publicArmor) }, onMessage = { id, unencrypted, raw ->- // Write straight to the Room vault: the UI observes it as a- // Flow, so mail appears live whether the UI is open or not,- // and survives process death (unlike the old in-memory hop).- // Decryption still happens in the ViewModel on open.+ // Write straight to the Room vault, decrypting immediately:+ // the S2K passphrase loads transparently from+ // Keystore-wrapped storage, so arrival-time decrypt needs+ // no user interaction. The UI observes the vault as a Flow+ // and shows decrypted content as soon as it lands. val repo = MailRepository.get(this@MailSocketService)- val settings =- MailConfig(this@MailSocketService).settings.first()- repo.messageDao().upsert(- StoredMessage(- id = id,- from = "",- toJson = settings.address,- dateMillis = System.currentTimeMillis(),- messageId = id,- blobBase64 = android.util.Base64.encodeToString(- raw, android.util.Base64.NO_WRAP,+ val config = MailConfig(this@MailSocketService)+ val settings = config.settings.first()+ val keyManager = KeyManager(this@MailSocketService)+ if (unencrypted) {+ // Plaintext frames carry the MIME body directly.+ val text = raw.toString(Charsets.UTF_8)+ val (subject, body, from) =+ MimeCodec.parseMime(text)+ repo.messageDao().upsert(+ StoredMessage(+ id = id,+ from = from,+ toJson = settings.address,+ dateMillis = System.currentTimeMillis(),+ messageId = id,+ blobBase64 = "",+ decryptedBody = body,+ decryptedSubject = subject,+ unencrypted = true, ),- unencrypted = unencrypted,- ),- )+ )+ } else {+ val passphrase = keyManager.getKeyPassphrase()+ val stored = if (passphrase != null) {+ runCatching {+ val pgpB64 = MimeCodec.extractPgpPayloadB64(raw)+ val pgpBytes = if (pgpB64 != null) {+ android.util.Base64.decode(+ pgpB64, android.util.Base64.DEFAULT,+ )+ } else {+ raw+ }+ val mime = PgpCrypto.decrypt(+ pgpBytes,+ keyManager.getSecretArmor(),+ passphrase,+ ).toString(Charsets.UTF_8)+ val (subject, body, from) = MimeCodec.parseMime(mime)+ StoredMessage(+ id = id,+ from = from,+ toJson = settings.address,+ dateMillis = System.currentTimeMillis(),+ messageId = id,+ blobBase64 = android.util.Base64.encodeToString(+ raw, android.util.Base64.NO_WRAP,+ ),+ decryptedBody = body,+ decryptedSubject = subject,+ unencrypted = false,+ )+ }.getOrNull()+ } else {+ null+ }+ repo.messageDao().upsert(+ stored ?: StoredMessage(+ id = id,+ from = "",+ toJson = settings.address,+ dateMillis = System.currentTimeMillis(),+ messageId = id,+ blobBase64 = android.util.Base64.encodeToString(+ raw, android.util.Base64.NO_WRAP,+ ),+ unencrypted = false,+ ),+ )+ } }, ) { // onBump: socket liveness tick — no-op here; UI polls [MailSocket.connected].
securemail/src/main/java/com/vayunmathur/securemail/ui/LockScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/LockScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/LockScreen.ktindex 9cfa355e37..6c3746e723 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/LockScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/LockScreen.kt@@ -5,10 +5,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.AppScaffold@@ -16,7 +12,6 @@ import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.library.ui.rememberMessenger@@ -28,11 +23,9 @@ fun LockScreen( state: MailUiState, onUnlock: () -> Unit, onDismissMessages: () -> Unit,- onPassphrase: (String) -> Unit = {}, ) { val messenger = rememberMessenger() ConsumeMessage(state.message, messenger, onDismissMessages)- var passphrase by remember { mutableStateOf("") } AppScaffold(title = "SecureMail locked", scrollBehavior = appBarScrollBehavior()) { padding -> DesktopMaxWidthContainer(Modifier.padding(padding)) { Column(@@ -55,36 +48,6 @@ fun LockScreen( } } }- if (state.needsPassphrase) {- Card(modifier = Modifier.fillMaxWidth()) {- Column(- modifier = Modifier.padding(16.dp).fillMaxWidth(),- verticalArrangement = Arrangement.spacedBy(12.dp),- ) {- Text(- "Key passphrase needed",- style = MaterialTheme.typography.titleMedium,- )- Text(- "The app restarted and forgot your key passphrase " +- "(it is never stored). Enter it once to decrypt pending mail.",- style = MaterialTheme.typography.bodyMedium,- )- OutlinedTextField(- value = passphrase,- onValueChange = { passphrase = it },- label = { Text("Key passphrase") },- modifier = Modifier.fillMaxWidth(),- singleLine = true,- )- Button(- onClick = { onPassphrase(passphrase); passphrase = "" },- enabled = passphrase.isNotBlank(),- modifier = Modifier.fillMaxWidth(),- ) { Text("Remember for this session") }- }- }- } } } }
securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.ktindex 76f5ad0261..9b58076fb3 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/ReaderScreen.kt@@ -7,10 +7,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.vayunmathur.library.ui.AppScaffold@@ -18,7 +14,6 @@ import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.securemail.data.StoredMessage@@ -32,11 +27,8 @@ fun ReaderScreen( onReply: (StoredMessage) -> Unit, onBack: () -> Unit, message: StoredMessage? = null,- onProvidePassphrase: (String) -> Unit = {},- onRetryDecrypt: () -> Unit = {}, ) { val msg = message- var passphrase by remember { mutableStateOf("") } AppScaffold(title = "Message", scrollBehavior = appBarScrollBehavior()) { padding -> DesktopMaxWidthContainer(Modifier.padding(padding)) { Column(@@ -50,40 +42,6 @@ fun ReaderScreen( Text("Message not found.", style = MaterialTheme.typography.bodyMedium) } else { TrustBadge(msg)- if (state.needsPassphrase && msg.decryptedBody == null && !msg.unencrypted) {- Card(modifier = Modifier.fillMaxWidth()) {- Column(- modifier = Modifier.padding(16.dp).fillMaxWidth(),- verticalArrangement = Arrangement.spacedBy(8.dp),- ) {- Text(- "Key passphrase needed",- style = MaterialTheme.typography.titleMedium,- )- Text(- "The app restarted and forgot your key passphrase " +- "(it is never stored). Enter it once to decrypt.",- style = MaterialTheme.typography.bodyMedium,- )- OutlinedTextField(- value = passphrase,- onValueChange = { passphrase = it },- label = { Text("Key passphrase") },- modifier = Modifier.fillMaxWidth(),- singleLine = true,- )- Button(- onClick = {- onProvidePassphrase(passphrase)- passphrase = ""- onRetryDecrypt()- },- enabled = passphrase.isNotBlank(),- modifier = Modifier.fillMaxWidth(),- ) { Text("Decrypt") }- }- }- } Card(modifier = Modifier.fillMaxWidth()) { Column( modifier = Modifier.padding(16.dp).fillMaxWidth(),