Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ada3c2ce8 | ||
|
|
9b0009faef | ||
|
|
57e194562b |
+12
-11
@@ -6,8 +6,8 @@ Related: [ENCRYPTION_PLAN.md](./ENCRYPTION_PLAN.md), [SECURITY_REVIEW.md](./SECU
|
|||||||
|
|
||||||
## Implementation progress (2026-11-03)
|
## Implementation progress (2026-11-03)
|
||||||
|
|
||||||
- **Phase 0 — Baseline:** Mostly implemented; release verification remains open.
|
- **Phase 0 — Baseline:** The merged release manifest and core WebView/network settings have now been reviewed and hardened. TLS certificate integration tests, the complete plugin audit, and a production-signed APK review remain open, so the Phase 0 release gate is not closed.
|
||||||
- **Phase 1 — Local data/privacy:** Notification privacy and the basic native app lock are implemented; vault lifecycle, deletion, and lock-recovery assurance remain open.
|
- **Phase 1 — Local data/privacy:** Notification privacy, immediate background app locking, `FLAG_SECURE` while locked, account-removal disclosure, and a fail-closed missing-key recovery screen are implemented. Vault lifecycle, complete deletion semantics, and app-lock lifecycle/biometric follow-up remain open.
|
||||||
- **Phase 2 — Android OpenPGP:** Experimental test implementation is present. It is not security-reviewed or release-complete.
|
- **Phase 2 — Android OpenPGP:** Experimental test implementation is present. It is not security-reviewed or release-complete.
|
||||||
- **Phase 3 — WebView/bridge:** Important protections are implemented; complete bridge review and device/content testing remain open.
|
- **Phase 3 — WebView/bridge:** Important protections are implemented; complete bridge review and device/content testing remain open.
|
||||||
- **Phase 4 — Assurance:** Open; independent review, release assurance, and vulnerability/maintenance work remain.
|
- **Phase 4 — Assurance:** Open; independent review, release assurance, and vulnerability/maintenance work remain.
|
||||||
@@ -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, and notification privacy policies 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. The latest validation was 152 passing Node tests and a successful Android debug build with 12 Android unit tests. 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, one-shot confirmation callbacks, and the missing-vault-key policy have Android unit tests. The app lock was exercised on an emulator with a device PIN, including background lock/unlock; with the lock active, emulator screenshots were fully obscured, and unlocking/turning the setting off restored the app. 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`. The V0.5.11 worktree release-variant merged manifest was inspected; the hardened debug app loaded `https://localhost` and the Capacitor bridge in an emulator at a 411 px viewport. Current validation: 153 Node tests and 21 Android unit tests pass; the Android debug build and release-manifest task succeed. Device testing of vault-corruption/key-loss recovery, invalid-certificate integration tests, production-signed APK review, and automated instrumentation of the actual confirmation dialogs remain open. This does not constitute 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
|
||||||
|
|
||||||
@@ -39,20 +39,21 @@ These are implementation observations, not proof that all paths are safe. In par
|
|||||||
|
|
||||||
### Phase 0 — Android security baseline and release gate (P0)
|
### Phase 0 — Android security baseline and release gate (P0)
|
||||||
|
|
||||||
- [ ] Complete and record a checklist for the merged manifest and production APK (permissions, exported components, backup rules, cleartext policy, WebView debugging, file access, and plugin exposure). Backup/data-extraction exclusions, cleartext denial, removal of the wildcard origin, and removal of the unused broad `FileProvider` are implemented; the production-artifact review is not.
|
- [x] Generate and review the V0.5.11 worktree release-variant merged manifest. It uses package `studio.daybreak.mail`, versionCode 511/versionName 0.5.11, minSdk 24/targetSdk 36; `allowBackup=false`, `usesCleartextTraffic=false`, and data-extraction exclusions for root/files/databases/shared preferences/external storage. The release manifest has no `debuggable=true` attribute. `MainActivity` is exported only for the launcher; WorkManager's exported job service is protected by `BIND_JOB_SERVICE`; diagnostics/profile receivers require `DUMP`; other merged components are non-exported. The only declared permissions are network, foreground data sync, notifications, wake lock, network-state/boot support, and a signature-protected dynamic-receiver permission. The unused broad `FileProvider` and wildcard origin are absent. The V0.5.10 published APK itself remains debug-signed; no production-signed artifact has been reviewed.
|
||||||
- [~] Require TLS and hostname validation on IMAP/SMTP and DAV. DAV is restricted to HTTPS and the configured origin; transport TLS modes are implemented and covered by unit tests. Invalid, expired, and mismatched certificate integration tests and a full native-client review remain open.
|
- [~] Review release WebView settings. Web contents debugging now follows `BuildConfig.DEBUG`; file/content access, file-URL cross-access, automatic JavaScript windows, and geolocation are disabled; mixed content is explicitly `NEVER_ALLOW`. The packaged app uses the HTTPS localhost origin. The hardened build compiles and loads the app/Capacitor bridge in the emulator; a full supported-device review remains open.
|
||||||
|
- [~] Require TLS and hostname validation on IMAP/SMTP and DAV. DAV is restricted to HTTPS and the configured origin; transport requires STARTTLS or implicit TLS and verifies host identity. Unit tests check those settings and absence of permissive trust/socket-factory overrides. Invalid, expired, and mismatched certificate integration tests and a full native-client review remain open.
|
||||||
- [~] Review `EpMailPlugin` as an untrusted-input boundary. DAV URLs and attachment names have specific native validation; PGP MIME structure and send confirmations have added native checks. A complete method-by-method bridge review and comprehensive size/state tests remain open.
|
- [~] Review `EpMailPlugin` as an untrusted-input boundary. DAV URLs and attachment names have specific native validation; PGP MIME structure and send confirmations have added native checks. A complete method-by-method bridge review and comprehensive size/state tests remain open.
|
||||||
- [~] Keep signing keys outside the repository, label debug APKs, and require environment-provided credentials for signed builds. No production-signed APK or merged release review has been completed.
|
- [~] Keep signing keys outside the repository, label debug APKs, and require environment-provided credentials for signed builds. No Android release-signing variables are configured here; published Android APKs are clearly labeled debug/test-only, and no production-signed APK has been reviewed.
|
||||||
- [x] Remove/sanitize sensitive native logging; the current mail sync log omits mailbox content and credentials.
|
- [x] Remove/sanitize sensitive native logging; the current mail sync log omits mailbox content and credentials.
|
||||||
|
|
||||||
**Exit criteria:** documented release manifest/config review; TLS validation and downgrade regression tests pass; no sensitive data in logs; release APK is signed and distinguishable from debug output.
|
**Exit criteria:** documented release manifest/config review; TLS validation and downgrade regression tests pass; no sensitive data in logs; release APK is signed and distinguishable from debug output.
|
||||||
|
|
||||||
### Phase 1 — Local data and privacy controls (P0)
|
### Phase 1 — Local data and privacy controls (P0)
|
||||||
|
|
||||||
- [~] The combined account/cache/draft/outbox store uses AES-GCM with an Android Keystore key. Document and test the key's security/fallback behavior, corruption and reinstall handling, and lock-screen/key invalidation; verify no plaintext fallback across all stored data.
|
- [~] The combined account/cache/draft/outbox store uses AES-GCM with an Android Keystore key. If the key alias is missing while encrypted data remains, the app now refuses to generate a replacement key and shows a recovery screen; it does not reset or expose the data. Add device tests for missing/invalidated keys, corrupted ciphertext, reinstall/migration handling, and the recovery instructions; verify no plaintext fallback for all stored data.
|
||||||
- [~] Account removal exists, but prove deletion covers account caches, queued sends, downloaded files, and related encryption-key lifecycle; document exported files and recovery limits.
|
- [~] Removing an account removes its encrypted account record, including that account's cache, drafts, outbox, snoozes, and rules. The confirmation now says downloaded attachment files and global OpenPGP keys are retained. Decide/test whether a separate app-data wipe should remove app-created Downloads and PGP keys; account removal intentionally leaves those user data intact.
|
||||||
- [x] Notification details are opt-in, persisted in the encrypted vault, and redacted from lock-screen previews; snooze notifications follow the privacy setting.
|
- [x] Notification details are opt-in, persisted in the encrypted vault, and redacted from lock-screen previews; snooze notifications follow the privacy setting.
|
||||||
- [~] A native app lock covers the WebView on background/resume and uses the device credential; background sync continues. Delayed lock, task-switcher obscuring, process-recreation/timeout tests, biometric UX, and recovery polish remain open.
|
- [~] A native app lock covers the WebView on background/resume, uses the device credential, and sets `FLAG_SECURE` while locked to hide task-switcher content and block screenshots; emulator smoke testing confirmed screenshots are obscured. Background sync continues and the setting is off unless enabled. Delayed lock, automated lifecycle/process-recreation tests, biometric UX, and recovery polish remain open.
|
||||||
- [x] Background sync is separate from the UI lock. Further verification of which credentials/key material are available to background workers remains part of the vault lifecycle review.
|
- [x] Background sync is separate from the UI lock. Further verification of which credentials/key material are available to background workers remains part of the vault lifecycle review.
|
||||||
|
|
||||||
**Exit criteria:** storage migration and failure tests; no plaintext fallback; app-lock/session tests across lifecycle events; notification privacy tests on supported Android versions; data removal tests.
|
**Exit criteria:** storage migration and failure tests; no plaintext fallback; app-lock/session tests across lifecycle events; notification privacy tests on supported Android versions; data removal tests.
|
||||||
@@ -64,7 +65,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. Automated 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.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ See the project architecture overview in [ARCHITECTURE.md](./ARCHITECTURE.md).
|
|||||||
|
|
||||||
## Android app
|
## Android app
|
||||||
|
|
||||||
The Android app reuses the web interface in a Capacitor shell and implements mail, DAV, encrypted account storage, and background sync with native Android services. Per-account signatures, notification preferences, and incoming-mail rules are respected; configured sync intervals apply to IDLE fallback polling, while Android's periodic background worker has a 15-minute platform minimum. Recent message content, drafts, and queued actions/sends are stored in the encrypted Android account vault for offline access and retry. Search filters use the same criteria and online scan limit as desktop. Android Settings can enable an app lock that covers the WebView and disables its JavaScript bridge when the app leaves the foreground; unlock requires the device PIN, pattern, or password, while background mail sync continues. Configure a secure Android screen lock before enabling it. This is a local privacy control, not protection against a compromised or rooted device. Android OpenPGP is now present as an **experimental test-only feature** for key and message testing. It has not had an independent cryptography/security review and is not approved for sensitive or production mail; do not rely on it to protect important messages. Install Node.js, Android Studio with the Android SDK, and JDK 21. Set `JAVA_HOME` and `ANDROID_HOME` if they are not configured by Android Studio, then run:
|
The Android app reuses the web interface in a Capacitor shell and implements mail, DAV, encrypted account storage, and background sync with native Android services. Per-account signatures, notification preferences, and incoming-mail rules are respected; configured sync intervals apply to IDLE fallback polling, while Android's periodic background worker has a 15-minute platform minimum. Recent message content, drafts, and queued actions/sends are stored in the encrypted Android account vault for offline access and retry. Search filters use the same criteria and online scan limit as desktop. Android Settings can enable an app lock that covers the WebView and disables its JavaScript bridge when the app leaves the foreground; it also hides the locked screen from screenshots and recent-app previews. Unlock requires the device PIN, pattern, or password, while background mail sync continues. Configure a secure Android screen lock before enabling it. This is a local privacy control, not protection against a compromised or rooted device. Android OpenPGP is now present as an **experimental test-only feature** for key and message testing. It has not had an independent cryptography/security review and is not approved for sensitive or production mail; do not rely on it to protect important messages. Install Node.js, Android Studio with the Android SDK, and JDK 21. Set `JAVA_HOME` and `ANDROID_HOME` if they are not configured by Android Studio, then run:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
npm install
|
npm install
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
- [x] Phase 4 (desktop): trust levels and fingerprint verification, key-change warnings, passphrase cache timeout.
|
- [x] Phase 4 (desktop): trust levels and fingerprint verification, key-change warnings, passphrase cache timeout.
|
||||||
- [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.
|
||||||
- [ ] Android release gate: native confirmation accept/cancel and bypass tests, full parity/interoperability tests, independent human cryptography/security review, and signed release review.
|
- [x] Add Android unit tests for trust-elevation, key-replacement, and plaintext-send confirmation decisions.
|
||||||
|
- [ ] 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).
|
||||||
@@ -47,6 +48,13 @@
|
|||||||
- [ ] Complete the Android security work in [ANDROID_SECURITY_PLAN.md](./ANDROID_SECURITY_PLAN.md), including Android OpenPGP and release security checks.
|
- [ ] Complete the Android security work in [ANDROID_SECURITY_PLAN.md](./ANDROID_SECURITY_PLAN.md), including Android OpenPGP and release security checks.
|
||||||
- [x] Make Android notification details opt-in, persist the preference in the encrypted vault, and redact lock-screen previews.
|
- [x] Make Android notification details opt-in, persist the preference in the encrypted vault, and redact lock-screen previews.
|
||||||
- [x] Add an optional native Android app lock using the device credential while leaving background mail sync available.
|
- [x] Add an optional native Android app lock using the device credential while leaving background mail sync available.
|
||||||
|
- [x] Set `FLAG_SECURE` while the optional app lock is engaged to hide the screen from screenshots and recents previews.
|
||||||
|
- [x] Exercise background lock, credential unlock, and screenshot obscuring on an Android emulator.
|
||||||
|
- [x] Disclose in account-removal confirmation that downloaded files and global OpenPGP keys are retained.
|
||||||
|
- [x] Refuse to generate a replacement Keystore key when encrypted vault data already exists; show a fail-closed recovery screen with clear-data guidance.
|
||||||
|
- [ ] Device-test missing/invalidated Keystore keys, corrupted vault data, migration/reinstall behavior, and recovery instructions.
|
||||||
|
- [ ] Define/test full app-data deletion and downloaded-file/OpenPGP-key retention or removal behavior.
|
||||||
|
- [ ] Add app-lock timeout/delay options and decide whether to add biometric unlock; test process recreation and lifecycle transitions.
|
||||||
|
|
||||||
## Appearance and settings
|
## Appearance and settings
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ async function openAccountManager(){
|
|||||||
const editButton=event.target.closest('[data-edit-account]');
|
const editButton=event.target.closest('[data-edit-account]');
|
||||||
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)accountMailUi.openMailAccount(account);return}
|
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)accountMailUi.openMailAccount(account);return}
|
||||||
const removeButton=event.target.closest('[data-remove-account]');
|
const removeButton=event.target.closest('[data-remove-account]');
|
||||||
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;accountMailUi.connectedAccount=active;if(active){accountMailUi.updateAccountCard(active);close();accountMailUi.state.activeFolder='Inbox';accountMailUi.setPageOffset(0);await accountMailUi.syncMailbox(false,{offset:0})}else{accountMailUi.updateAccountCard({email:'Connect a mailbox',imapHost:''});accountMailUi.state.messages.splice(0,accountMailUi.state.messages.length);accountMailUi.renderList();accountMailUi.select('#reader-pane').innerHTML=accountMailUi.emptyReader();accountMailUi.toast('Mail account removed');openAccountManager()}}catch(error){accountMailUi.toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?\n\nIts cached mail, drafts and pending sends will be removed. Downloaded attachment files and OpenPGP keys are kept; delete those separately if you want to remove them too.`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;accountMailUi.connectedAccount=active;if(active){accountMailUi.updateAccountCard(active);close();accountMailUi.state.activeFolder='Inbox';accountMailUi.setPageOffset(0);await accountMailUi.syncMailbox(false,{offset:0})}else{accountMailUi.updateAccountCard({email:'Connect a mailbox',imapHost:''});accountMailUi.state.messages.splice(0,accountMailUi.state.messages.length);accountMailUi.renderList();accountMailUi.select('#reader-pane').innerHTML=accountMailUi.emptyReader();accountMailUi.toast('Mail account removed');openAccountManager()}}catch(error){accountMailUi.toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
||||||
};
|
};
|
||||||
}catch(error){accountMailUi.toast(error.message||'Could not load mail accounts')}
|
}catch(error){accountMailUi.toast(error.message||'Could not load mail accounts')}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ internal object AndroidAccountVault {
|
|||||||
private const val ENCRYPTED_VALUE = "encrypted-data"
|
private const val ENCRYPTED_VALUE = "encrypted-data"
|
||||||
private const val GCM_TAG_BITS = 128
|
private const val GCM_TAG_BITS = 128
|
||||||
|
|
||||||
@Volatile private var appContext: Context? = null
|
@Volatile private var appContext: Context? = null
|
||||||
|
|
||||||
fun initialize(context: Context) {
|
fun initialize(context: Context) {
|
||||||
appContext = context.applicationContext
|
appContext = context.applicationContext
|
||||||
secretKey()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun read(): JSONObject {
|
fun read(): JSONObject {
|
||||||
@@ -598,10 +597,15 @@ internal object AndroidAccountVault {
|
|||||||
appContext ?: throw IllegalStateException("Encrypted account storage is not initialized.")
|
appContext ?: throw IllegalStateException("Encrypted account storage is not initialized.")
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun secretKey(): SecretKey {
|
private fun secretKey(): SecretKey {
|
||||||
val keyStore = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }
|
val keyStore = KeyStore.getInstance("AndroidKeyStore").apply { load(null) }
|
||||||
(keyStore.getKey(KEY_ALIAS, null) as? SecretKey)?.let { return it }
|
(keyStore.getKey(KEY_ALIAS, null) as? SecretKey)?.let { return it }
|
||||||
val generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore")
|
val hasEncryptedData = requireContext().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||||
|
.contains(ENCRYPTED_VALUE)
|
||||||
|
check(AndroidVaultKeyPolicy.shouldCreateKey(hasEncryptedData)) {
|
||||||
|
AndroidVaultKeyPolicy.MISSING_KEY_MESSAGE
|
||||||
|
}
|
||||||
|
val generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore")
|
||||||
generator.init(
|
generator.init(
|
||||||
KeyGenParameterSpec.Builder(
|
KeyGenParameterSpec.Builder(
|
||||||
KEY_ALIAS,
|
KEY_ALIAS,
|
||||||
|
|||||||
@@ -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) }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package studio.daybreak.mail
|
||||||
|
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
internal object AndroidPgpPolicy {
|
||||||
|
data class ContactKey(
|
||||||
|
val fingerprint: String,
|
||||||
|
val emails: List<String>,
|
||||||
|
val trust: String
|
||||||
|
)
|
||||||
|
|
||||||
|
data class RecipientKey(
|
||||||
|
val email: String,
|
||||||
|
val fingerprint: String
|
||||||
|
)
|
||||||
|
|
||||||
|
private val trustOrder = mapOf("unknown" to 0, "trusted" to 1, "verified" to 2)
|
||||||
|
|
||||||
|
fun storeChangeWarning(previous: List<ContactKey>, candidate: List<ContactKey>): String? {
|
||||||
|
val oldByFingerprint = previous.associateBy { it.fingerprint.uppercase(Locale.ROOT) }
|
||||||
|
val warnings = ArrayList<String>()
|
||||||
|
|
||||||
|
for (current in candidate) {
|
||||||
|
val fingerprint = current.fingerprint.uppercase(Locale.ROOT)
|
||||||
|
val old = oldByFingerprint[fingerprint]
|
||||||
|
if (old != null && (trustOrder[current.trust] ?: 0) > (trustOrder[old.trust] ?: 0)) {
|
||||||
|
warnings.add(
|
||||||
|
"Trust change for ${safeLabel(current.emails)}\n" +
|
||||||
|
"Fingerprint: ${formatFingerprint(fingerprint)}\n" +
|
||||||
|
"New trust: ${current.trust}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (old == null) {
|
||||||
|
val newEmails = current.emails.map { it.lowercase(Locale.ROOT) }.toSet()
|
||||||
|
for (previousKey in previous) {
|
||||||
|
val oldFingerprint = previousKey.fingerprint.uppercase(Locale.ROOT)
|
||||||
|
val overlaps = previousKey.emails.any { it.lowercase(Locale.ROOT) in newEmails }
|
||||||
|
if (overlaps && oldFingerprint != fingerprint) {
|
||||||
|
warnings.add(
|
||||||
|
"A different key is already stored for ${safeLabel(current.emails)}.\n" +
|
||||||
|
"New fingerprint: ${formatFingerprint(fingerprint)}\n" +
|
||||||
|
"Existing fingerprint: ${formatFingerprint(oldFingerprint)}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return warnings.take(MAX_WARNINGS).takeIf { it.isNotEmpty() }?.joinToString("\n\n")?.let {
|
||||||
|
"$it\n\nOnly confirm trust or a replacement after comparing fingerprints with the key owner through another channel."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun plaintextSendWarning(
|
||||||
|
recipients: List<String>,
|
||||||
|
availableKeys: List<RecipientKey>,
|
||||||
|
encryptionWasRequested: Boolean
|
||||||
|
): String? {
|
||||||
|
val uniqueRecipients = recipients.map { it.trim().lowercase(Locale.ROOT) }.filter(String::isNotBlank).distinct()
|
||||||
|
if (uniqueRecipients.isEmpty()) return null
|
||||||
|
val matchedKeys = availableKeys.filter { key -> key.email.trim().lowercase(Locale.ROOT) in uniqueRecipients }
|
||||||
|
if (!encryptionWasRequested && matchedKeys.isEmpty()) return null
|
||||||
|
|
||||||
|
val recipientLines = uniqueRecipients.take(MAX_RECIPIENTS).map { email ->
|
||||||
|
val fingerprints = matchedKeys.filter { it.email.trim().equals(email, ignoreCase = true) }
|
||||||
|
.map { formatFingerprint(it.fingerprint.uppercase()) }.distinct()
|
||||||
|
if (fingerprints.isEmpty()) "$email — no key stored" else "$email\n${fingerprints.joinToString("\n")}"
|
||||||
|
}.joinToString("\n\n")
|
||||||
|
val prefix = if (encryptionWasRequested) {
|
||||||
|
"OpenPGP was requested, but this message will be sent in plaintext."
|
||||||
|
} else {
|
||||||
|
"A stored OpenPGP key is available for at least one recipient."
|
||||||
|
}
|
||||||
|
return "$prefix\n\nRecipients and stored key fingerprints:\n$recipientLines\n\n" +
|
||||||
|
"The message body and attachments will be readable by the mail provider and anyone who receives it. Send plaintext anyway?"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun safeLabel(values: List<String>): String =
|
||||||
|
values.joinToString(", ").replace(Regex("[\\r\\n\\u0000]"), " ").take(300).ifBlank { "this contact" }
|
||||||
|
|
||||||
|
private fun formatFingerprint(value: String): String = value.chunked(4).joinToString(" ").take(200)
|
||||||
|
|
||||||
|
private const val MAX_WARNINGS = 6
|
||||||
|
private const val MAX_RECIPIENTS = 10
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package studio.daybreak.mail
|
||||||
|
|
||||||
|
internal object AndroidVaultKeyPolicy {
|
||||||
|
fun shouldCreateKey(hasEncryptedData: Boolean): Boolean = !hasEncryptedData
|
||||||
|
|
||||||
|
const val MISSING_KEY_MESSAGE =
|
||||||
|
"The Android Keystore key for saved app data is missing. Existing encrypted data was not reset or replaced."
|
||||||
|
}
|
||||||
@@ -22,8 +22,8 @@ import javax.mail.internet.InternetAddress
|
|||||||
class EpMailPlugin : Plugin() {
|
class EpMailPlugin : Plugin() {
|
||||||
private var syncReceiver: BroadcastReceiver? = null
|
private var syncReceiver: BroadcastReceiver? = null
|
||||||
|
|
||||||
override fun load() {
|
override fun load() {
|
||||||
AndroidAccountVault.initialize(context)
|
AndroidAccountVault.initialize(context)
|
||||||
val filter = IntentFilter(MailIdleService.ACTION_MAIL_SYNC)
|
val filter = IntentFilter(MailIdleService.ACTION_MAIL_SYNC)
|
||||||
val receiver = object : BroadcastReceiver() {
|
val receiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
@@ -38,12 +38,21 @@ class EpMailPlugin : Plugin() {
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
context.registerReceiver(receiver, filter)
|
context.registerReceiver(receiver, filter)
|
||||||
}
|
}
|
||||||
MailIdleService.start(context)
|
ensureVaultAvailableAndStartSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleOnResume() {
|
override fun handleOnResume() {
|
||||||
MailIdleService.start(context)
|
ensureVaultAvailableAndStartSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ensureVaultAvailableAndStartSync() {
|
||||||
|
try {
|
||||||
|
AndroidAccountVault.read()
|
||||||
|
MailIdleService.start(context)
|
||||||
|
} catch (error: Exception) {
|
||||||
|
android.util.Log.e("EpMailStorage", "Secure local storage is unavailable (${error.javaClass.simpleName})")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun handleOnDestroy() {
|
override fun handleOnDestroy() {
|
||||||
syncReceiver?.let {
|
syncReceiver?.let {
|
||||||
@@ -126,25 +135,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.") }
|
try {
|
||||||
.setPositiveButton("Confirm changes") { _, _ ->
|
AndroidAccountVault.savePgpStore(next)
|
||||||
bridge.execute {
|
call.resolve(JSObject().put("ok", true))
|
||||||
try {
|
} catch (error: Exception) {
|
||||||
AndroidAccountVault.savePgpStore(next)
|
call.reject(error.message ?: "Could not save the Android OpenPGP key store.")
|
||||||
call.resolve(JSObject().put("ok", true))
|
|
||||||
} catch (error: Exception) {
|
|
||||||
call.reject(error.message ?: "Could not save the Android OpenPGP key store.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.setOnCancelListener { call.reject("OpenPGP key change cancelled.") }
|
},
|
||||||
.show()
|
onCancelled = { call.reject("OpenPGP key change cancelled.") }
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
} 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.")
|
||||||
@@ -154,42 +158,45 @@ class EpMailPlugin : Plugin() {
|
|||||||
private fun pgpStoreChangeWarning(previous: JSONObject, candidate: JSONObject): String? {
|
private fun pgpStoreChangeWarning(previous: JSONObject, candidate: JSONObject): String? {
|
||||||
val oldContacts = previous.optJSONArray("contacts") ?: JSONArray()
|
val oldContacts = previous.optJSONArray("contacts") ?: JSONArray()
|
||||||
val newContacts = candidate.optJSONArray("contacts") ?: JSONArray()
|
val newContacts = candidate.optJSONArray("contacts") ?: JSONArray()
|
||||||
val oldByFingerprint = (0 until oldContacts.length()).mapNotNull { oldContacts.optJSONObject(it) }
|
return AndroidPgpPolicy.storeChangeWarning(pgpContacts(oldContacts), pgpContacts(newContacts))
|
||||||
.associateBy { it.optString("fingerprint").uppercase(Locale.ROOT) }
|
|
||||||
val warnings = ArrayList<String>()
|
|
||||||
for (index in 0 until newContacts.length()) {
|
|
||||||
val current = newContacts.optJSONObject(index) ?: continue
|
|
||||||
val fingerprint = current.optString("fingerprint").uppercase(Locale.ROOT)
|
|
||||||
val previousContact = oldByFingerprint[fingerprint]
|
|
||||||
val trustOrder = mapOf("unknown" to 0, "trusted" to 1, "verified" to 2)
|
|
||||||
if (previousContact != null &&
|
|
||||||
(trustOrder[current.optString("trust")] ?: 0) > (trustOrder[previousContact.optString("trust")] ?: 0)) {
|
|
||||||
warnings.add("Trust change for ${safePgpLabel(current.optJSONArray("emails"))}\nFingerprint: ${formatPgpFingerprint(fingerprint)}\nNew trust: ${current.optString("trust")}")
|
|
||||||
}
|
|
||||||
if (previousContact == null) {
|
|
||||||
val newEmails = jsonStrings(current.optJSONArray("emails")).map { it.lowercase(Locale.ROOT) }.toSet()
|
|
||||||
for (oldIndex in 0 until oldContacts.length()) {
|
|
||||||
val old = oldContacts.optJSONObject(oldIndex) ?: continue
|
|
||||||
val oldFingerprint = old.optString("fingerprint").uppercase(Locale.ROOT)
|
|
||||||
val overlap = jsonStrings(old.optJSONArray("emails")).map { it.lowercase(Locale.ROOT) }.any(newEmails::contains)
|
|
||||||
if (overlap && oldFingerprint != fingerprint) {
|
|
||||||
warnings.add("A different key is already stored for ${safePgpLabel(current.optJSONArray("emails"))}.\nNew fingerprint: ${formatPgpFingerprint(fingerprint)}\nExisting fingerprint: ${formatPgpFingerprint(oldFingerprint)}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return warnings.take(6).takeIf { it.isNotEmpty() }?.joinToString("\n\n")?.let {
|
|
||||||
"$it\n\nOnly confirm trust or a replacement after comparing fingerprints with the key owner through another channel."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun pgpContacts(values: JSONArray): List<AndroidPgpPolicy.ContactKey> =
|
||||||
|
(0 until values.length()).mapNotNull { values.optJSONObject(it) }.map { contact ->
|
||||||
|
AndroidPgpPolicy.ContactKey(
|
||||||
|
fingerprint = contact.optString("fingerprint"),
|
||||||
|
emails = jsonStrings(contact.optJSONArray("emails")),
|
||||||
|
trust = contact.optString("trust")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
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 safePgpLabel(values: JSONArray?): String =
|
private fun showPgpConfirmation(
|
||||||
jsonStrings(values).joinToString(", ").replace(Regex("[\\r\\n\\u0000]"), " ").take(300).ifBlank { "this contact" }
|
title: String,
|
||||||
|
message: String,
|
||||||
private fun formatPgpFingerprint(value: String): String = value.chunked(4).joinToString(" ").take(200)
|
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) {
|
||||||
@@ -457,20 +464,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) {
|
||||||
@@ -496,31 +498,25 @@ class EpMailPlugin : Plugin() {
|
|||||||
.filter(String::isNotBlank)
|
.filter(String::isNotBlank)
|
||||||
.flatMap { InternetAddress.parse(it, true).mapNotNull { address -> (address as? InternetAddress)?.address?.lowercase(Locale.ROOT) } })
|
.flatMap { InternetAddress.parse(it, true).mapNotNull { address -> (address as? InternetAddress)?.address?.lowercase(Locale.ROOT) } })
|
||||||
.distinct()
|
.distinct()
|
||||||
if (recipients.isEmpty()) return null
|
|
||||||
val data = AndroidAccountVault.pgpStore()
|
val data = AndroidAccountVault.pgpStore()
|
||||||
val contacts = data.optJSONArray("contacts") ?: JSONArray()
|
val contacts = data.optJSONArray("contacts") ?: JSONArray()
|
||||||
val keys = data.optJSONArray("keys") ?: JSONArray()
|
val keys = data.optJSONArray("keys") ?: JSONArray()
|
||||||
val available = ArrayList<Pair<String, String>>()
|
val available = ArrayList<AndroidPgpPolicy.RecipientKey>()
|
||||||
for (address in recipients) {
|
for (address in recipients) {
|
||||||
for (index in 0 until contacts.length()) {
|
for (index in 0 until contacts.length()) {
|
||||||
val contact = contacts.optJSONObject(index) ?: continue
|
val contact = contacts.optJSONObject(index) ?: continue
|
||||||
if (jsonStrings(contact.optJSONArray("emails")).any { it.equals(address, true) }) {
|
if (jsonStrings(contact.optJSONArray("emails")).any { it.equals(address, true) }) {
|
||||||
available.add(address to contact.optString("fingerprint"))
|
available.add(AndroidPgpPolicy.RecipientKey(address, contact.optString("fingerprint")))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (index in 0 until keys.length()) {
|
for (index in 0 until keys.length()) {
|
||||||
val key = keys.optJSONObject(index) ?: continue
|
val key = keys.optJSONObject(index) ?: continue
|
||||||
if (key.optString("email").equals(address, true)) available.add(address to key.optString("fingerprint"))
|
if (key.optString("email").equals(address, true)) {
|
||||||
|
available.add(AndroidPgpPolicy.RecipientKey(address, key.optString("fingerprint")))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val explicitRequest = input.optBoolean("pgpRequested")
|
return AndroidPgpPolicy.plaintextSendWarning(recipients, available, input.optBoolean("pgpRequested"))
|
||||||
if (!explicitRequest && available.isEmpty()) return null
|
|
||||||
val recipientLines = recipients.take(10).map { address ->
|
|
||||||
val fingerprints = available.filter { it.first == address }.map { formatPgpFingerprint(it.second) }.distinct()
|
|
||||||
if (fingerprints.isEmpty()) "$address — no key stored" else "$address\n${fingerprints.joinToString("\n")}"
|
|
||||||
}.joinToString("\n\n")
|
|
||||||
val prefix = if (explicitRequest) "OpenPGP was requested, but this message will be sent in plaintext." else "A stored OpenPGP key is available for at least one recipient."
|
|
||||||
return "$prefix\n\nRecipients and stored key fingerprints:\n$recipientLines\n\nThe message body and attachments will be readable by the mail provider and anyone who receives it. Send plaintext anyway?"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PluginMethod
|
@PluginMethod
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
@@ -27,12 +29,21 @@ public class MainActivity extends BridgeActivity {
|
|||||||
private boolean appLocked;
|
private boolean appLocked;
|
||||||
private boolean awaitingUnlockResult;
|
private boolean awaitingUnlockResult;
|
||||||
private boolean activityResumed;
|
private boolean activityResumed;
|
||||||
|
private boolean vaultRecoveryRequired;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
registerPlugin(EpMailPlugin.class);
|
registerPlugin(EpMailPlugin.class);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
hardenWebView();
|
||||||
AndroidAccountVault.INSTANCE.initialize(getApplicationContext());
|
AndroidAccountVault.INSTANCE.initialize(getApplicationContext());
|
||||||
|
try {
|
||||||
|
AndroidAccountVault.INSTANCE.read();
|
||||||
|
} catch (Exception storageError) {
|
||||||
|
vaultRecoveryRequired = true;
|
||||||
|
createVaultRecoveryOverlay();
|
||||||
|
return;
|
||||||
|
}
|
||||||
createAppLockOverlay();
|
createAppLockOverlay();
|
||||||
if (isAppLockEnabled()) lockWebView();
|
if (isAppLockEnabled()) lockWebView();
|
||||||
if (Build.VERSION.SDK_INT >= 33 && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
if (Build.VERSION.SDK_INT >= 33 && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||||
@@ -43,6 +54,7 @@ public class MainActivity extends BridgeActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
if (vaultRecoveryRequired) return;
|
||||||
activityResumed = true;
|
activityResumed = true;
|
||||||
if (isAppLockEnabled() && appLocked) {
|
if (isAppLockEnabled() && appLocked) {
|
||||||
lockWebView();
|
lockWebView();
|
||||||
@@ -53,7 +65,7 @@ public class MainActivity extends BridgeActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
activityResumed = false;
|
activityResumed = false;
|
||||||
if (isAppLockEnabled()) lockWebView();
|
if (!vaultRecoveryRequired && isAppLockEnabled()) lockWebView();
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +100,77 @@ public class MainActivity extends BridgeActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void hardenWebView() {
|
||||||
|
if (getBridge() == null || getBridge().getWebView() == null) return;
|
||||||
|
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
|
||||||
|
WebView webView = getBridge().getWebView();
|
||||||
|
android.webkit.WebSettings settings = webView.getSettings();
|
||||||
|
settings.setAllowFileAccess(false);
|
||||||
|
settings.setAllowContentAccess(false);
|
||||||
|
settings.setAllowFileAccessFromFileURLs(false);
|
||||||
|
settings.setAllowUniversalAccessFromFileURLs(false);
|
||||||
|
settings.setGeolocationEnabled(false);
|
||||||
|
settings.setJavaScriptCanOpenWindowsAutomatically(false);
|
||||||
|
settings.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_NEVER_ALLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createVaultRecoveryOverlay() {
|
||||||
|
View content = findViewById(android.R.id.content);
|
||||||
|
if (!(content instanceof FrameLayout)) return;
|
||||||
|
FrameLayout overlay = new FrameLayout(this);
|
||||||
|
overlay.setBackgroundColor(Color.rgb(25, 21, 18));
|
||||||
|
overlay.setClickable(true);
|
||||||
|
overlay.setFocusable(true);
|
||||||
|
|
||||||
|
LinearLayout panel = new LinearLayout(this);
|
||||||
|
panel.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
panel.setGravity(Gravity.CENTER);
|
||||||
|
panel.setPadding(dp(28), dp(28), dp(28), dp(28));
|
||||||
|
|
||||||
|
TextView title = new TextView(this);
|
||||||
|
title.setText("Saved data could not be opened");
|
||||||
|
title.setTextColor(Color.rgb(238, 230, 215));
|
||||||
|
title.setTextSize(21);
|
||||||
|
title.setGravity(Gravity.CENTER);
|
||||||
|
panel.addView(title, new LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
|
|
||||||
|
TextView details = new TextView(this);
|
||||||
|
details.setText("ep-mail could not decrypt its saved local data. It has not been reset or replaced. Try restoring the same device/app state if available. If you cannot recover it, open Android App info and clear ep-mail data to start fresh; this permanently removes saved accounts, cached mail, drafts, queued sends, DAV settings, and OpenPGP keys. Attachments already saved to Downloads remain there.");
|
||||||
|
details.setTextColor(Color.rgb(210, 199, 181));
|
||||||
|
details.setTextSize(14);
|
||||||
|
details.setGravity(Gravity.CENTER);
|
||||||
|
LinearLayout.LayoutParams detailsParams = new LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
detailsParams.topMargin = dp(16);
|
||||||
|
panel.addView(details, detailsParams);
|
||||||
|
|
||||||
|
Button settingsButton = new Button(this);
|
||||||
|
settingsButton.setText("Open Android App info");
|
||||||
|
settingsButton.setOnClickListener(view -> {
|
||||||
|
try {
|
||||||
|
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
||||||
|
Uri.parse("package:" + getPackageName())));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
// Keep the recovery instructions visible if Settings cannot be launched.
|
||||||
|
}
|
||||||
|
});
|
||||||
|
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
buttonParams.gravity = Gravity.CENTER_HORIZONTAL;
|
||||||
|
buttonParams.topMargin = dp(24);
|
||||||
|
panel.addView(settingsButton, buttonParams);
|
||||||
|
|
||||||
|
overlay.addView(panel, new FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
|
||||||
|
((FrameLayout) content).addView(overlay, new FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
||||||
|
if (getBridge() != null && getBridge().getWebView() != null) {
|
||||||
|
getBridge().getWebView().getSettings().setJavaScriptEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void createAppLockOverlay() {
|
private void createAppLockOverlay() {
|
||||||
View content = findViewById(android.R.id.content);
|
View content = findViewById(android.R.id.content);
|
||||||
if (!(content instanceof FrameLayout)) return;
|
if (!(content instanceof FrameLayout)) return;
|
||||||
@@ -178,6 +261,7 @@ public class MainActivity extends BridgeActivity {
|
|||||||
|
|
||||||
private void lockWebView() {
|
private void lockWebView() {
|
||||||
appLocked = true;
|
appLocked = true;
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
||||||
if (appLockOverlay != null) appLockOverlay.setVisibility(View.VISIBLE);
|
if (appLockOverlay != null) appLockOverlay.setVisibility(View.VISIBLE);
|
||||||
if (getBridge() != null) {
|
if (getBridge() != null) {
|
||||||
WebView webView = getBridge().getWebView();
|
WebView webView = getBridge().getWebView();
|
||||||
@@ -188,6 +272,7 @@ public class MainActivity extends BridgeActivity {
|
|||||||
|
|
||||||
private void unlockWebView(boolean reload) {
|
private void unlockWebView(boolean reload) {
|
||||||
appLocked = false;
|
appLocked = false;
|
||||||
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
|
||||||
if (getBridge() != null) {
|
if (getBridge() != null) {
|
||||||
WebView webView = getBridge().getWebView();
|
WebView webView = getBridge().getWebView();
|
||||||
webView.getSettings().setJavaScriptEnabled(true);
|
webView.getSettings().setJavaScriptEnabled(true);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ class AndroidMailTransportTest {
|
|||||||
assertEquals("true", properties.getProperty("mail.imap.starttls.enable"))
|
assertEquals("true", properties.getProperty("mail.imap.starttls.enable"))
|
||||||
assertEquals("true", properties.getProperty("mail.imap.starttls.required"))
|
assertEquals("true", properties.getProperty("mail.imap.starttls.required"))
|
||||||
assertEquals("true", properties.getProperty("mail.imap.ssl.checkserveridentity"))
|
assertEquals("true", properties.getProperty("mail.imap.ssl.checkserveridentity"))
|
||||||
|
assertNull(properties.getProperty("mail.imap.ssl.trust"))
|
||||||
|
assertNull(properties.getProperty("mail.imap.ssl.socketFactory"))
|
||||||
assertNull(properties.getProperty("mail.imap.ssl.enable"))
|
assertNull(properties.getProperty("mail.imap.ssl.enable"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,6 +27,8 @@ class AndroidMailTransportTest {
|
|||||||
assertEquals("imaps", properties.getProperty("mail.store.protocol"))
|
assertEquals("imaps", properties.getProperty("mail.store.protocol"))
|
||||||
assertEquals("true", properties.getProperty("mail.imaps.ssl.enable"))
|
assertEquals("true", properties.getProperty("mail.imaps.ssl.enable"))
|
||||||
assertEquals("true", properties.getProperty("mail.imaps.ssl.checkserveridentity"))
|
assertEquals("true", properties.getProperty("mail.imaps.ssl.checkserveridentity"))
|
||||||
|
assertNull(properties.getProperty("mail.imaps.ssl.trust"))
|
||||||
|
assertNull(properties.getProperty("mail.imaps.ssl.socketFactory"))
|
||||||
assertNull(properties.getProperty("mail.imaps.starttls.required"))
|
assertNull(properties.getProperty("mail.imaps.starttls.required"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,12 +39,16 @@ class AndroidMailTransportTest {
|
|||||||
)
|
)
|
||||||
assertEquals("true", startTls.getProperty("mail.smtp.starttls.enable"))
|
assertEquals("true", startTls.getProperty("mail.smtp.starttls.enable"))
|
||||||
assertEquals("true", startTls.getProperty("mail.smtp.starttls.required"))
|
assertEquals("true", startTls.getProperty("mail.smtp.starttls.required"))
|
||||||
|
assertNull(startTls.getProperty("mail.smtp.ssl.trust"))
|
||||||
|
assertNull(startTls.getProperty("mail.smtp.ssl.socketFactory"))
|
||||||
|
|
||||||
val implicitTls = AndroidMailTransport.smtpProperties(
|
val implicitTls = AndroidMailTransport.smtpProperties(
|
||||||
MailServerConnection("smtp.example.test", 465, true)
|
MailServerConnection("smtp.example.test", 465, true)
|
||||||
)
|
)
|
||||||
assertEquals("true", implicitTls.getProperty("mail.smtp.ssl.enable"))
|
assertEquals("true", implicitTls.getProperty("mail.smtp.ssl.enable"))
|
||||||
assertEquals("true", implicitTls.getProperty("mail.smtp.ssl.checkserveridentity"))
|
assertEquals("true", implicitTls.getProperty("mail.smtp.ssl.checkserveridentity"))
|
||||||
|
assertNull(implicitTls.getProperty("mail.smtp.ssl.trust"))
|
||||||
|
assertNull(implicitTls.getProperty("mail.smtp.ssl.socketFactory"))
|
||||||
assertNull(implicitTls.getProperty("mail.smtp.starttls.required"))
|
assertNull(implicitTls.getProperty("mail.smtp.starttls.required"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package studio.daybreak.mail
|
||||||
|
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class AndroidPgpPolicyTest {
|
||||||
|
private val firstFingerprint = "0123456789ABCDEF0123456789ABCDEF01234567"
|
||||||
|
private val secondFingerprint = "89ABCDEF0123456789ABCDEF0123456789ABCDEF"
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun unchangedOrLoweredTrustDoesNotPrompt() {
|
||||||
|
val verified = contact(firstFingerprint, "alice@example.test", "verified")
|
||||||
|
assertNull(AndroidPgpPolicy.storeChangeWarning(listOf(verified), listOf(verified)))
|
||||||
|
assertNull(AndroidPgpPolicy.storeChangeWarning(listOf(verified), listOf(verified.copy(trust = "unknown"))))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun trustElevationRequiresTheFullFingerprintWarning() {
|
||||||
|
val previous = contact(firstFingerprint, "alice@example.test", "unknown")
|
||||||
|
val warning = AndroidPgpPolicy.storeChangeWarning(
|
||||||
|
listOf(previous),
|
||||||
|
listOf(previous.copy(trust = "verified"))
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(warning!!.contains("alice@example.test"))
|
||||||
|
assertTrue(warning.contains("0123 4567 89AB CDEF"))
|
||||||
|
assertTrue(warning.contains("New trust: verified"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addingAKeyForAnExistingAddressRequiresReplacementWarning() {
|
||||||
|
val previous = contact(firstFingerprint, "alice@example.test", "unknown")
|
||||||
|
val replacement = contact(secondFingerprint, "ALICE@example.test", "unknown")
|
||||||
|
val warning = AndroidPgpPolicy.storeChangeWarning(listOf(previous), listOf(previous, replacement))
|
||||||
|
|
||||||
|
assertTrue(warning!!.contains("different key is already stored"))
|
||||||
|
assertTrue(warning.contains("0123 4567 89AB CDEF"))
|
||||||
|
assertTrue(warning.contains("89AB CDEF 0123 4567"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun plaintextPromptNamesRecipientsAndMatchingKeyFingerprints() {
|
||||||
|
val warning = AndroidPgpPolicy.plaintextSendWarning(
|
||||||
|
recipients = listOf("Alice@example.test", "bob@example.test"),
|
||||||
|
availableKeys = listOf(AndroidPgpPolicy.RecipientKey("alice@example.test", firstFingerprint)),
|
||||||
|
encryptionWasRequested = false
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(warning!!.contains("alice@example.test"))
|
||||||
|
assertTrue(warning.contains("0123 4567 89AB CDEF"))
|
||||||
|
assertTrue(warning.contains("bob@example.test — no key stored"))
|
||||||
|
assertTrue(warning.contains("readable by the mail provider"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun noPlaintextPromptWhenNoKeyExistsAndEncryptionWasNotRequested() {
|
||||||
|
assertNull(
|
||||||
|
AndroidPgpPolicy.plaintextSendWarning(
|
||||||
|
recipients = listOf("alice@example.test"),
|
||||||
|
availableKeys = emptyList(),
|
||||||
|
encryptionWasRequested = false
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun explicitEncryptionRequestPromptsEvenWhenNoRecipientKeyExists() {
|
||||||
|
val warning = AndroidPgpPolicy.plaintextSendWarning(
|
||||||
|
recipients = listOf("alice@example.test"),
|
||||||
|
availableKeys = emptyList(),
|
||||||
|
encryptionWasRequested = true
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(warning!!.contains("OpenPGP was requested"))
|
||||||
|
assertTrue(warning.contains("alice@example.test — no key stored"))
|
||||||
|
assertFalse(warning.contains("Fingerprint:"))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun contact(fingerprint: String, email: String, trust: String) =
|
||||||
|
AndroidPgpPolicy.ContactKey(fingerprint, listOf(email), trust)
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package studio.daybreak.mail
|
||||||
|
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class AndroidVaultKeyPolicyTest {
|
||||||
|
@Test
|
||||||
|
fun newKeyMayBeCreatedOnlyWhenThereIsNoEncryptedStore() {
|
||||||
|
assertTrue(AndroidVaultKeyPolicy.shouldCreateKey(hasEncryptedData = false))
|
||||||
|
assertFalse(AndroidVaultKeyPolicy.shouldCreateKey(hasEncryptedData = true))
|
||||||
|
assertTrue(AndroidVaultKeyPolicy.MISSING_KEY_MESSAGE.contains("not reset or replaced"))
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.5.8",
|
"version": "0.5.11",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.5.8",
|
"version": "0.5.11",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@capacitor/android": "^8.5.2",
|
"@capacitor/android": "^8.5.2",
|
||||||
"@capacitor/core": "^8.5.2",
|
"@capacitor/core": "^8.5.2",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ep-mail",
|
"name": "ep-mail",
|
||||||
"version": "0.5.8",
|
"version": "0.5.11",
|
||||||
"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",
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ const app = fs.readFileSync(path.join(root, 'app.js'), 'utf8');
|
|||||||
const transport = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidMailTransport.kt'), 'utf8');
|
const transport = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidMailTransport.kt'), 'utf8');
|
||||||
const mainActivity = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'MainActivity.java'), 'utf8');
|
const mainActivity = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'MainActivity.java'), 'utf8');
|
||||||
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 vault = fs.readFileSync(path.join(root, 'android', 'app', 'src', 'main', 'java', 'studio', 'daybreak', 'mail', 'AndroidAccountVault.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 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');
|
||||||
@@ -64,6 +67,15 @@ test('Android app lock is native-enforced and requires a secure device credentia
|
|||||||
assert.match(mainActivity, /setJavaScriptEnabled\(false\)/);
|
assert.match(mainActivity, /setJavaScriptEnabled\(false\)/);
|
||||||
assert.match(mainActivity, /createConfirmDeviceCredentialIntent/);
|
assert.match(mainActivity, /createConfirmDeviceCredentialIntent/);
|
||||||
assert.match(mainActivity, /android\.R\.id\.content/);
|
assert.match(mainActivity, /android\.R\.id\.content/);
|
||||||
|
assert.match(mainActivity, /settings\.setAllowFileAccess\(false\)/);
|
||||||
|
assert.match(mainActivity, /settings\.setAllowContentAccess\(false\)/);
|
||||||
|
assert.match(mainActivity, /setJavaScriptCanOpenWindowsAutomatically\(false\)/);
|
||||||
|
assert.match(mainActivity, /MIXED_CONTENT_NEVER_ALLOW/);
|
||||||
|
assert.match(mainActivity, /setWebContentsDebuggingEnabled\(BuildConfig\.DEBUG\)/);
|
||||||
|
assert.match(mainActivity, /addFlags\(WindowManager\.LayoutParams\.FLAG_SECURE\)/);
|
||||||
|
assert.match(mainActivity, /clearFlags\(WindowManager\.LayoutParams\.FLAG_SECURE\)/);
|
||||||
|
assert.match(mainActivity, /createVaultRecoveryOverlay/);
|
||||||
|
assert.match(mainActivity, /setJavaScriptEnabled\(false\)/);
|
||||||
assert.match(androidBridge, /getAppLockSettings/);
|
assert.match(androidBridge, /getAppLockSettings/);
|
||||||
assert.match(androidBridge, /setAppLockEnabled/);
|
assert.match(androidBridge, /setAppLockEnabled/);
|
||||||
assert.match(productivity, /Lock when leaving ep-mail/);
|
assert.match(productivity, /Lock when leaving ep-mail/);
|
||||||
@@ -76,6 +88,13 @@ 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, /showPgpConfirmation\(/);
|
||||||
|
assert.match(plugin, /onCancelled = \{ call\.reject\("OpenPGP key change cancelled\."\) \}/);
|
||||||
|
assert.match(plugin, /onConfirmed = \{ sendPrepared\(call, input\) \}/);
|
||||||
|
assert.match(plugin, /PLAINTEXT_CANCELLED/);
|
||||||
|
assert.match(androidPgpConfirmationGate, /compareAndSet\(false, true\)/);
|
||||||
|
assert.match(androidPgpPolicy, /fun storeChangeWarning/);
|
||||||
|
assert.match(androidPgpPolicy, /fun plaintextSendWarning/);
|
||||||
assert.match(androidPgp, /curve25519Legacy/);
|
assert.match(androidPgp, /curve25519Legacy/);
|
||||||
assert.match(androidPgp, /multipart\/encrypted/);
|
assert.match(androidPgp, /multipart\/encrypted/);
|
||||||
assert.match(androidPgp, /MAX_MESSAGE_BYTES = 25 \* 1024 \* 1024/);
|
assert.match(androidPgp, /MAX_MESSAGE_BYTES = 25 \* 1024 \* 1024/);
|
||||||
@@ -86,3 +105,11 @@ test('Android OpenPGP uses the encrypted vault and queues only built MIME data',
|
|||||||
assert.match(androidMailService, /"send" -> send\(account, data\)/);
|
assert.match(androidMailService, /"send" -> send\(account, data\)/);
|
||||||
assert.match(androidMailService, /private fun isEncryptedMessage/);
|
assert.match(androidMailService, /private fun isEncryptedMessage/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Android vault refuses to replace a missing key when encrypted data exists', () => {
|
||||||
|
assert.match(vault, /shouldCreateKey\(hasEncryptedData\)/);
|
||||||
|
assert.match(vault, /MISSING_KEY_MESSAGE/);
|
||||||
|
assert.match(mainActivity, /AndroidAccountVault\.INSTANCE\.read\(\)/);
|
||||||
|
assert.match(mainActivity, /Saved data could not be opened/);
|
||||||
|
assert.match(mainActivity, /ACTION_APPLICATION_DETAILS_SETTINGS/);
|
||||||
|
});
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ test('account and snooze UI consume the explicit mail API instead of selected le
|
|||||||
const shortcutsUi = fs.readFileSync(path.join(root, 'shortcuts.js'), 'utf8');
|
const shortcutsUi = fs.readFileSync(path.join(root, 'shortcuts.js'), 'utf8');
|
||||||
const productivityUi = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8');
|
const productivityUi = fs.readFileSync(path.join(root, 'productivity.js'), 'utf8');
|
||||||
assert.match(accountUi, /window\.epMailFeatures\.mail/);
|
assert.match(accountUi, /window\.epMailFeatures\.mail/);
|
||||||
|
assert.match(accountUi, /Downloaded attachment files and OpenPGP keys are kept/);
|
||||||
assert.match(attachmentUi, /^\(\(\) => \{/);
|
assert.match(attachmentUi, /^\(\(\) => \{/);
|
||||||
assert.match(snoozeUi, /window\.epMailFeatures\.mail/);
|
assert.match(snoozeUi, /window\.epMailFeatures\.mail/);
|
||||||
assert.match(snoozeUi, /^\(\(\) => \{/);
|
assert.match(snoozeUi, /^\(\(\) => \{/);
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ async function openAccountManager(){
|
|||||||
const editButton=event.target.closest('[data-edit-account]');
|
const editButton=event.target.closest('[data-edit-account]');
|
||||||
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)accountMailUi.openMailAccount(account);return}
|
if(editButton){const account=accounts.find(item=>item.id===editButton.dataset.editAccount);if(account)accountMailUi.openMailAccount(account);return}
|
||||||
const removeButton=event.target.closest('[data-remove-account]');
|
const removeButton=event.target.closest('[data-remove-account]');
|
||||||
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;accountMailUi.connectedAccount=active;if(active){accountMailUi.updateAccountCard(active);close();accountMailUi.state.activeFolder='Inbox';accountMailUi.setPageOffset(0);await accountMailUi.syncMailbox(false,{offset:0})}else{accountMailUi.updateAccountCard({email:'Connect a mailbox',imapHost:''});accountMailUi.state.messages.splice(0,accountMailUi.state.messages.length);accountMailUi.renderList();accountMailUi.select('#reader-pane').innerHTML=accountMailUi.emptyReader();accountMailUi.toast('Mail account removed');openAccountManager()}}catch(error){accountMailUi.toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
if(removeButton){const email=removeButton.closest('.account-row').querySelector('strong').textContent;if(!confirm(`Remove ${email} from this device?\n\nIts cached mail, drafts and pending sends will be removed. Downloaded attachment files and OpenPGP keys are kept; delete those separately if you want to remove them too.`))return;removeButton.disabled=true;try{const result=await window.daybreakMail.removeAccount(removeButton.dataset.removeAccount);const active=result.accounts.find(account=>account.id===result.activeId)||null;accountMailUi.connectedAccount=active;if(active){accountMailUi.updateAccountCard(active);close();accountMailUi.state.activeFolder='Inbox';accountMailUi.setPageOffset(0);await accountMailUi.syncMailbox(false,{offset:0})}else{accountMailUi.updateAccountCard({email:'Connect a mailbox',imapHost:''});accountMailUi.state.messages.splice(0,accountMailUi.state.messages.length);accountMailUi.renderList();accountMailUi.select('#reader-pane').innerHTML=accountMailUi.emptyReader();accountMailUi.toast('Mail account removed');openAccountManager()}}catch(error){accountMailUi.toast(error.message||'Could not remove the account');removeButton.disabled=false}return}
|
||||||
};
|
};
|
||||||
}catch(error){accountMailUi.toast(error.message||'Could not load mail accounts')}
|
}catch(error){accountMailUi.toast(error.message||'Could not load mail accounts')}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user