Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kafkade
added a commit
to kafkade/toku
that referenced
this pull request
Dec 1, 2026
…a guard against silent plaintext (#290) ## Description Proves the Apple build plumbing for the iPhone + Mac app: `toku-ffi` now builds as an XCFramework with SQLCipher encryption backed by Apple's CommonCrypto, verified by a Swift smoke test on macOS and the iOS simulator. It also fixes a case where an "encrypted" library could silently be written in plaintext. ### What's included - **`toku-apple/build-xcframework.sh`** — builds `TokuFFI.xcframework` (iOS device, iOS simulator, macOS arm64; minimum iOS 26 / macOS 26) with `--features sqlcipher`. The module map exposes the header as `CTokuFFI`, so existing Swift imports are unchanged. Output goes to `toku-apple/build/` (git-ignored). - **`toku-apple/FFISmoke`** — a SwiftPM package that links the XCFramework and checks an encrypted library: open, add a book, wrong key rejected, plain open rejected, no plaintext on disk, reopen and read back. - **Crypto backend split in `toku-db`** — `sqlcipher` now uses CommonCrypto on Apple targets (about twice as fast to build, about 10 MB smaller static lib, no OpenSSL) and system `libcrypto` elsewhere. The previous bundled-OpenSSL behavior is the new `sqlcipher-vendored-openssl` feature. The CLI, web, and sync-client `sqlcipher` features point at it, so their behavior is unchanged. - **Guard against silent plaintext** — if a system SQLite is linked ahead of the bundled SQLCipher (the current Xcode project passes `-lsqlite3`), `PRAGMA key` was ignored and the database was written unencrypted while the open reported success. Keyed opens now require `PRAGMA cipher_version` to report SQLCipher, and otherwise fail with a clear error. Verified by re-running the smoke test with the system SQLite linked. - **CI** — the non-gating *SQLCipher feature (toku-db)* job now uses `sqlcipher-vendored-openssl` (Linux has no CommonCrypto). The job name is unchanged, so no branch-protection change is needed. - **Docs** — `docs/validations/apple-xcframework-sqlcipher.md` (backend comparison, the linkage finding, reproduction steps, CI plan), an Apple README section, and short decision notes in the encryption and product-direction ADRs. ### CI fixes (failures already present on `main`) - **Clippy** — CI's stable toolchain moved to Rust 1.100, whose `result_large_err` lint rejected the CSRF helper in `toku-web`; its error response is now boxed. Clippy passes on 1.96 and 1.100. - **Security audit** — the advisory database flagged 38 vulnerabilities in the existing lockfile. A semver-compatible `cargo update` fixes 29. `zip` 8 → 9 fixes 8 more (including path traversal and unchecked AES authentication on extraction). rusqlite 0.39 → 0.41 with refinery 0.9 → 0.10 picks up the patched bundled SQLite. Those upgrades raise the **MSRV to 1.92** (the CI job is renamed `MSRV (1.92)`; it is not a required check, so no branch-protection change is needed). - One advisory remains: RUSTSEC-2026-0502 in `sqlcipher-src`, compiled only by opt-in encrypted builds. It is blocked on refinery supporting rusqlite ≥ 0.42 (upstream rust-db/refinery#461), so it is ignored with a justification and tracked in #291. Not covered: a signed, sandboxed run on a physical device, which needs Apple Developer setup and the new app target. ## Related Issues Relates to #285 (all acceptance criteria met except the signed on-device run, pending #261 / #262) Relates to #262, #276, #291 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [x] Documentation update - [ ] Refactoring (no functional changes) - [x] CI / infrastructure - [ ] Other (describe below) ## Crate - [ ] `toku-core` — Domain models, traits, state machine - [x] `toku-db` — SQLite persistence, migrations, FTS5 - [ ] `toku-import` — Importers (Goodreads, Calibre, StoryGraph) - [ ] `toku-meta` — Metadata fetching (Open Library, Google Books) - [x] `toku-cli` — CLI binary (feature passthrough only; behavior unchanged) - [ ] `toku-export` — Exporters (CSV, JSON, Markdown, BibTeX) - [x] `docs/` — Documentation Also touched: `toku-ffi`, `toku-web`, `toku-sync-client` (feature passthroughs), `toku-apple/` (build script, smoke test). ## Data Integrity Checklist - [x] No user data is sent to any server without explicit opt-in (no network code touched) - [x] Import operations are idempotent (re-importing the same file creates no duplicates) — N/A, importers untouched - [x] User edits to metadata are never overwritten by auto-enrichment — N/A - [x] New fields track provenance (source + timestamp) — N/A, no new fields - [x] Export round-trip is preserved (if applicable) — N/A ## Checklist - [x] I have read [CONTRIBUTING.md](CONTRIBUTING.md) - [x] `cargo fmt --check` passes - [x] `cargo clippy --workspace -- -D warnings` passes (also with `--all-targets`, and `-p toku-db --features sqlcipher-vendored-openssl`) - [x] `cargo test --workspace` passes (48 suites, 589 passed, 0 failed) - [x] I have updated documentation (if applicable) Also run: - `cargo test -p toku-db --features sqlcipher` (CommonCrypto on macOS) — 156 passed - `cargo test -p toku-db --features sqlcipher-vendored-openssl` — 156 passed - `toku-apple/build-xcframework.sh` then `swift test` in `toku-apple/FFISmoke` — passed (macOS) - `xcodebuild test -scheme FFISmoke-Package -destination 'platform=iOS Simulator,name=iPhone 17 Pro,OS=26.5'` — TEST SUCCEEDED - `xcodebuild build-for-testing ... -destination 'generic/platform=iOS' CODE_SIGNING_ALLOWED=NO` — device slice links - `npx markdownlint-cli2 "**/*.md"` — 0 issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Widens the rusqlite range to
<= 0.43(same pattern as #457).rusqlite 0.42/0.43 use libsqlite3-sys 0.40, which bundles SQLite 3.54.1 and, for
bundled-sqlcipher, SQLCipher 4.20 (SQLite 3.54.1). That is the first SQLCipher build not affected by RUSTSEC-2026-0459, so projects using refinery with SQLCipher can't pick up the fix until refinery accepts these versions. No source changes were needed.Tested locally:
cd refinery && cargo test --features rusqlite --test rusqlite(28 passed)cd refinery_core && cargo test --features rusqlite-bundled(19 passed)examplesbuilds;cargo fmt --checkclean🤖 Generated with Claude Code