Compare commits

..
1 Commits
Author SHA1 Message Date
thuttu 9b0009faef Android security implementation Phase 3.4 2026-11-03 19:41:09 +02:00
8 changed files with 165 additions and 43 deletions
+3 -3
View File
@@ -16,9 +16,9 @@ Tracking legend: `[x]` implemented for the stated item; `[~]` partially implemen
OpenPGP.js 6.3.2 is bundled for Android testing. The test implementation stores passphrase-protected keys and public contacts in the existing Keystore-encrypted vault; supports key generation/import/export, contact trust controls, PGP/MIME encrypt/sign, and on-demand PGP/MIME or inline-encrypted-message decryption. Encrypted sends are converted to ciphertext before native sending or offline queueing; decrypted content is held in renderer memory only. Native prompts cover trust elevation, key replacement, and plaintext sending when keys exist or encryption was requested. Key-server lookup is disabled, and PGP/MIME messages are capped at 25 MiB. This work was implemented to enable testing before the independent review gate was satisfied; it is **not approved for sensitive or production use**. OpenPGP.js 6.3.2 is bundled for Android testing. The test implementation stores passphrase-protected keys and public contacts in the existing Keystore-encrypted vault; supports key generation/import/export, contact trust controls, PGP/MIME encrypt/sign, and on-demand PGP/MIME or inline-encrypted-message decryption. Encrypted sends are converted to ciphertext before native sending or offline queueing; decrypted content is held in renderer memory only. Native prompts cover trust elevation, key replacement, and plaintext sending when keys exist or encryption was requested. Key-server lookup is disabled, and PGP/MIME messages are capped at 25 MiB. This work was implemented to enable testing before the independent review gate was satisfied; it is **not approved for sensitive or production use**.
**Validation evidence:** DAV URL, attachment-name, notification privacy, and Android OpenPGP trust/plaintext policy decisions have Android unit tests. The app lock was exercised on an emulator with a device PIN, including background lock and unlock. OpenPGP key generation/storage and native trust/plaintext confirmation dialogs were exercised on an emulator; trust cancellation left trust unchanged, trust confirmation persisted, and plaintext cancellation returned `PLAINTEXT_CANCELLED`. Phone and landscape layouts were checked for horizontal overflow. Current validation: 152 passing Node tests, 18 Android unit tests, and a successful Android debug build. This does not constitute live-provider mail testing or GnuPG/Thunderbird interoperability testing on Android. **Validation evidence:** DAV URL, attachment-name, notification privacy, Android OpenPGP policy decisions, and the confirmation gate's accept/cancel callback ordering have Android unit tests. The app lock was exercised on an emulator with a device PIN, including background lock and unlock. OpenPGP key generation/storage and native trust/plaintext confirmation dialogs were exercised on an emulator; trust cancellation left trust unchanged, trust confirmation persisted, and plaintext cancellation returned `PLAINTEXT_CANCELLED`. Phone and landscape layouts were checked for horizontal overflow. Current validation: Android debug build and 20 Android unit tests pass; the Node suite has 151 passes and one version-consistency failure because the working tree's `package-lock.json` is locally set to 0.5.9 while `package.json` remains 0.5.8. That lockfile change was preserved. This does not constitute automated testing of the actual Android dialog UI, live-provider mail testing, or GnuPG/Thunderbird interoperability testing on Android.
**Release blockers:** independent human cryptography/security review; automated native confirmation and bypass tests; full signed/inline and hostile-input parity; Android/GnuPG/Thunderbird interoperability; Keystore lifecycle/recovery and biometric design; invalid-certificate integration tests; production-signed APK/manifest review; app-lock recovery polish; and compatibility review/remediation of the three moderate `npm audit --omit=dev` advisories in `ip-address` and the `nodemailer`/`mailparser` dependency chain. **Release blockers:** independent human cryptography/security review; instrumented tests of actual native confirmation dialogs and policy-bypass attempts; full signed/inline and hostile-input parity; Android/GnuPG/Thunderbird interoperability; Keystore lifecycle/recovery and biometric design; invalid-certificate integration tests; production-signed APK/manifest review; app-lock recovery polish; and compatibility review/remediation of the three moderate `npm audit --omit=dev` advisories in `ip-address` and the `nodemailer`/`mailparser` dependency chain.
## Goals and limits ## Goals and limits
@@ -64,7 +64,7 @@ These are implementation observations, not proof that all paths are safe. In par
- [ ] Add optional biometric/device-credential release of PGP key access and test Keystore invalidation/recovery. Background sync does not use PGP private keys. - [ ] Add optional biometric/device-credential release of PGP key access and test Keystore invalidation/recovery. Background sync does not use PGP private keys.
- [~] The Android UI/bridge supports key generation, paste-based import, export, deletion, revocation export, contacts, fingerprints, and trust. Native prompts now guard trust elevation and replacement; automated cancel/confirm regression tests remain open. - [~] The Android UI/bridge supports key generation, paste-based import, export, deletion, revocation export, contacts, fingerprints, and trust. Native prompts now guard trust elevation and replacement; automated cancel/confirm regression tests remain open.
- [~] PGP/MIME encryption/signing, PGP/MIME and inline-encrypted-message decryption, attachments, encrypted Sent copies, and ciphertext-before-queueing are implemented. Signed-only/clear-signed/inline signature parity, full hostile-input/tampering suite, and Android interoperability remain open. - [~] PGP/MIME encryption/signing, PGP/MIME and inline-encrypted-message decryption, attachments, encrypted Sent copies, and ciphertext-before-queueing are implemented. Signed-only/clear-signed/inline signature parity, full hostile-input/tampering suite, and Android interoperability remain open.
- [~] Native prompts guard trust elevation, key replacement, and plaintext sending when a key is available or encryption was requested; the native send path checks PGP/MIME structure. Emulator smoke tests cover trust accept/cancel and plaintext cancel; policy-level unit tests cover prompt/no-prompt decisions. Automated dialog-interaction, bypass, stale-key, and queue-policy tests remain open. - [~] Native prompts guard trust elevation, key replacement, and plaintext sending when a key is available or encryption was requested; the native send path checks PGP/MIME structure. Emulator smoke tests cover trust accept/cancel and plaintext cancel; policy and confirmation-gate unit tests cover prompt decisions and one-shot accept/cancel handling. Instrumented tests of the actual dialog UI, bypass attempts, stale-key cases, and queue policy remain open.
- [x] Key-server lookup and publication are disabled in the initial Android test implementation. - [x] Key-server lookup and publication are disabled in the initial Android test implementation.
**Exit criteria:** parity tests for desktop message formats and trust rules; Android-specific tests for cancel/confirm paths, tampering, malformed/oversized messages, key replacement, offline queueing, process death, and passphrase expiry; independent human review before release. **Exit criteria:** parity tests for desktop message formats and trust rules; Android-specific tests for cancel/confirm paths, tampering, malformed/oversized messages, key replacement, offline queueing, process death, and passphrase expiry; independent human review before release.
+1 -1
View File
@@ -34,7 +34,7 @@
- [x] Experimental Android test path: Keystore-encrypted vault key storage, key/contact management, PGP/MIME encryption/signing, and on-demand decryption. - [x] Experimental Android test path: Keystore-encrypted vault key storage, key/contact management, PGP/MIME encryption/signing, and on-demand decryption.
- [x] Exercise native trust-change and plaintext-send confirmations on an emulator, including cancellation. - [x] Exercise native trust-change and plaintext-send confirmations on an emulator, including cancellation.
- [x] Add Android unit tests for trust-elevation, key-replacement, and plaintext-send confirmation decisions. - [x] Add Android unit tests for trust-elevation, key-replacement, and plaintext-send confirmation decisions.
- [ ] Android release gate: automated native-dialog interaction and bypass tests, full parity/interoperability tests, independent human cryptography/security review, and signed release review. - [ ] Android release gate: instrumented native-dialog UI and bypass tests, full parity/interoperability tests, independent human cryptography/security review, and signed release review.
- [ ] Android follow-up: biometric unlock, full vault lifecycle/recovery, signed/inline verification parity, and dependency advisory remediation. - [ ] Android follow-up: biometric unlock, full vault lifecycle/recovery, signed/inline verification parity, and dependency advisory remediation.
- [x] Phase 5 (automated): large attachments, multiple recipients, corrupted/tampered payloads, inline PGP and PGP/MIME tests. - [x] Phase 5 (automated): large attachments, multiple recipients, corrupted/tampered payloads, inline PGP and PGP/MIME tests.
- [x] Phase 5 (GnuPG): automated interoperability tests with GnuPG 2.5 (both directions: PGP/MIME, inline, clear-signed, detached signatures). - [x] Phase 5 (GnuPG): automated interoperability tests with GnuPG 2.5 (both directions: PGP/MIME, inline, clear-signed, detached signatures).
@@ -0,0 +1,39 @@
package studio.daybreak.mail
import java.util.concurrent.atomic.AtomicBoolean
/** Makes native confirmations fail closed and guarantees each plugin call gets one decision. */
internal class AndroidPgpConfirmationGate(
private val showPrompt: (Prompt) -> Unit,
private val dispatch: ((() -> Unit) -> Unit)
) {
data class Prompt(
val title: String,
val message: String,
val confirmLabel: String,
val cancelLabel: String,
val confirm: () -> Unit,
val cancel: () -> Unit
)
fun request(
title: String,
message: String,
confirmLabel: String,
cancelLabel: String = "Cancel",
onConfirmed: () -> Unit,
onCancelled: () -> Unit
) {
val decided = AtomicBoolean(false)
showPrompt(
Prompt(
title = title,
message = message,
confirmLabel = confirmLabel,
cancelLabel = cancelLabel,
confirm = { if (decided.compareAndSet(false, true)) dispatch(onConfirmed) },
cancel = { if (decided.compareAndSet(false, true)) dispatch(onCancelled) }
)
)
}
}
@@ -126,25 +126,20 @@ class EpMailPlugin : Plugin() {
AndroidAccountVault.savePgpStore(next) AndroidAccountVault.savePgpStore(next)
call.resolve(JSObject().put("ok", true)) call.resolve(JSObject().put("ok", true))
} else { } else {
val host = activity showPgpConfirmation(
host.runOnUiThread { title = "Confirm OpenPGP key changes",
AlertDialog.Builder(host) message = warning,
.setTitle("Confirm OpenPGP key changes") confirmLabel = "Confirm changes",
.setMessage(warning) onConfirmed = {
.setNegativeButton("Cancel") { _, _ -> call.reject("OpenPGP key change cancelled.") }
.setPositiveButton("Confirm changes") { _, _ ->
bridge.execute {
try { try {
AndroidAccountVault.savePgpStore(next) AndroidAccountVault.savePgpStore(next)
call.resolve(JSObject().put("ok", true)) call.resolve(JSObject().put("ok", true))
} catch (error: Exception) { } catch (error: Exception) {
call.reject(error.message ?: "Could not save the Android OpenPGP key store.") call.reject(error.message ?: "Could not save the Android OpenPGP key store.")
} }
} },
} onCancelled = { call.reject("OpenPGP key change cancelled.") }
.setOnCancelListener { call.reject("OpenPGP key change cancelled.") } )
.show()
}
} }
} catch (error: Exception) { } catch (error: Exception) {
call.reject(error.message ?: "Could not save the Android OpenPGP key store.") call.reject(error.message ?: "Could not save the Android OpenPGP key store.")
@@ -169,6 +164,31 @@ class EpMailPlugin : Plugin() {
private fun jsonStrings(values: JSONArray?): List<String> = private fun jsonStrings(values: JSONArray?): List<String> =
values?.let { array -> (0 until array.length()).mapNotNull { array.optString(it).takeIf(String::isNotBlank) } }.orEmpty() values?.let { array -> (0 until array.length()).mapNotNull { array.optString(it).takeIf(String::isNotBlank) } }.orEmpty()
private fun showPgpConfirmation(
title: String,
message: String,
confirmLabel: String,
onConfirmed: () -> Unit,
onCancelled: () -> Unit
) {
val gate = AndroidPgpConfirmationGate(
showPrompt = { prompt ->
val host = activity
host.runOnUiThread {
AlertDialog.Builder(host)
.setTitle(prompt.title)
.setMessage(prompt.message)
.setNegativeButton(prompt.cancelLabel) { _, _ -> prompt.cancel() }
.setPositiveButton(prompt.confirmLabel) { _, _ -> prompt.confirm() }
.setOnCancelListener { prompt.cancel() }
.show()
}
},
dispatch = { action -> bridge.execute(action) }
)
gate.request(title, message, confirmLabel, onConfirmed = onConfirmed, onCancelled = onCancelled)
}
@PluginMethod @PluginMethod
fun pgpGetMessageSource(call: PluginCall) { fun pgpGetMessageSource(call: PluginCall) {
try { try {
@@ -435,20 +455,15 @@ class EpMailPlugin : Plugin() {
sendPrepared(call, input) sendPrepared(call, input)
return return
} }
val host = activity showPgpConfirmation(
host.runOnUiThread { title = "Send without OpenPGP encryption?",
AlertDialog.Builder(host) message = warning,
.setTitle("Send without OpenPGP encryption?") confirmLabel = "Send plaintext",
.setMessage(warning) onConfirmed = { sendPrepared(call, input) },
.setNegativeButton("Cancel") { _, _ -> onCancelled = {
call.resolve(JSObject().put("failed", true).put("code", "PLAINTEXT_CANCELLED").put("message", "Plaintext send cancelled.")) call.resolve(JSObject().put("failed", true).put("code", "PLAINTEXT_CANCELLED").put("message", "Plaintext send cancelled."))
} }
.setPositiveButton("Send plaintext") { _, _ -> bridge.execute { sendPrepared(call, input) } } )
.setOnCancelListener {
call.resolve(JSObject().put("failed", true).put("code", "PLAINTEXT_CANCELLED").put("message", "Plaintext send cancelled."))
}
.show()
}
} }
private fun sendPrepared(call: PluginCall, input: JSONObject) { private fun sendPrepared(call: PluginCall, input: JSONObject) {
@@ -0,0 +1,66 @@
package studio.daybreak.mail
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test
class AndroidPgpConfirmationGateTest {
@Test
fun cancelDoesNotRunProtectedActionAndCannotBeOverriddenLater() {
var prompt: AndroidPgpConfirmationGate.Prompt? = null
var protectedActionCount = 0
var cancelCount = 0
val gate = AndroidPgpConfirmationGate(
showPrompt = { prompt = it },
dispatch = { action -> action() }
)
gate.request(
title = "Confirm key change",
message = "Check the fingerprint",
confirmLabel = "Confirm",
onConfirmed = { protectedActionCount += 1 },
onCancelled = { cancelCount += 1 }
)
assertEquals(0, protectedActionCount)
assertEquals(0, cancelCount)
assertNotNull(prompt)
prompt!!.cancel()
prompt!!.confirm()
prompt!!.cancel()
assertEquals(0, protectedActionCount)
assertEquals(1, cancelCount)
}
@Test
fun confirmRunsProtectedActionExactlyOnce() {
var prompt: AndroidPgpConfirmationGate.Prompt? = null
var protectedActionCount = 0
var cancelCount = 0
val gate = AndroidPgpConfirmationGate(
showPrompt = { prompt = it },
dispatch = { action -> action() }
)
gate.request(
title = "Send plaintext?",
message = "The message will not be encrypted",
confirmLabel = "Send plaintext",
onConfirmed = { protectedActionCount += 1 },
onCancelled = { cancelCount += 1 }
)
assertNotNull(prompt)
assertEquals("Send plaintext", prompt!!.confirmLabel)
prompt!!.confirm()
prompt!!.confirm()
prompt!!.cancel()
assertEquals(1, protectedActionCount)
assertEquals(0, cancelCount)
assertTrue(prompt!!.message.contains("not be encrypted"))
}
}
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "ep-mail", "name": "ep-mail",
"version": "0.5.8", "version": "0.5.9",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "ep-mail", "name": "ep-mail",
"version": "0.5.8", "version": "0.5.9",
"dependencies": { "dependencies": {
"@capacitor/android": "^8.5.2", "@capacitor/android": "^8.5.2",
"@capacitor/core": "^8.5.2", "@capacitor/core": "^8.5.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ep-mail", "name": "ep-mail",
"version": "0.5.8", "version": "0.5.9",
"private": true, "private": true,
"description": "Eternity Project mail client", "description": "Eternity Project mail client",
"homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client", "homepage": "https://git.eternityproject.fi/thuttu/ep-mail-client",
+6 -4
View File
@@ -12,6 +12,7 @@ const mainActivity = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'm
const plugin = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'EpMailPlugin.kt'), 'utf8'); const plugin = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'EpMailPlugin.kt'), 'utf8');
const androidMailService = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidMailService.kt'), 'utf8'); const androidMailService = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidMailService.kt'), 'utf8');
const androidPgpPolicy = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidPgpPolicy.kt'), 'utf8'); const androidPgpPolicy = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidPgpPolicy.kt'), 'utf8');
const androidPgpConfirmationGate = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidPgpConfirmationGate.kt'), 'utf8');
const productivity = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8'); const productivity = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8');
const androidBridge = fs.readFileSync(path.join(root, 'scripts', 'android-bridge.js'), 'utf8'); const androidBridge = fs.readFileSync(path.join(root, 'scripts', 'android-bridge.js'), 'utf8');
const androidPgp = fs.readFileSync(path.join(root, 'scripts', 'android-pgp.js'), 'utf8'); const androidPgp = fs.readFileSync(path.join(root, 'scripts', 'android-pgp.js'), 'utf8');
@@ -77,10 +78,11 @@ test('Android OpenPGP uses the encrypted vault and queues only built MIME data',
assert.match(plugin, /pgpStoreChangeWarning/); assert.match(plugin, /pgpStoreChangeWarning/);
assert.match(plugin, /plaintextSendWarning/); assert.match(plugin, /plaintextSendWarning/);
assert.match(plugin, /Send plaintext/); assert.match(plugin, /Send plaintext/);
assert.match(plugin, /\.setNegativeButton\("Cancel"\) \{ _, _ -> call\.reject\("OpenPGP key change cancelled\."\) \}/); assert.match(plugin, /showPgpConfirmation\(/);
assert.match(plugin, /\.setPositiveButton\("Confirm changes"\)[\s\S]*bridge\.execute \{[\s\S]*AndroidAccountVault\.savePgpStore\(next\)/); assert.match(plugin, /onCancelled = \{ call\.reject\("OpenPGP key change cancelled\."\) \}/);
assert.match(plugin, /\.setNegativeButton\("Cancel"\)[\s\S]*PLAINTEXT_CANCELLED/); assert.match(plugin, /onConfirmed = \{ sendPrepared\(call, input\) \}/);
assert.match(plugin, /\.setPositiveButton\("Send plaintext"\)[\s\S]*sendPrepared\(call, input\)/); assert.match(plugin, /PLAINTEXT_CANCELLED/);
assert.match(androidPgpConfirmationGate, /compareAndSet\(false, true\)/);
assert.match(androidPgpPolicy, /fun storeChangeWarning/); assert.match(androidPgpPolicy, /fun storeChangeWarning/);
assert.match(androidPgpPolicy, /fun plaintextSendWarning/); assert.match(androidPgpPolicy, /fun plaintextSendWarning/);
assert.match(androidPgp, /curve25519Legacy/); assert.match(androidPgp, /curve25519Legacy/);