Repository navigation
Slice 1 of #7938: client-only id-client facade and Android arm64 target #13445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Android `arm64-v8a` target for the `id-client` facade (slice 1, #7938/#13403) | ||
|
|
||
| ## What lives here | ||
|
|
||
| - `check-android.sh`: the slice-1 Android gate. Runs the | ||
| `android_dependency_boundary` check, then `cargo check -p id-client | ||
| --target aarch64-linux-android` when the target std is installed. | ||
| - This README: the build path contract for the later Kotlin shell. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Rust target std: `rustup target add aarch64-linux-android` | ||
| (toolchain file `pkgs/id/rust-toolchain.toml`, currently 1.99.1). | ||
| - Android NDK r27+ with `aarch64-linux-android35-clang` on `PATH`, or | ||
| set `ANDROID_NDK_HOME`. `cargo check` needs only the target std; | ||
| full `cargo build` / APK linkage needs the NDK linker. | ||
|
|
||
| ## Commands (run from `pkgs/id/`) | ||
|
|
||
| ```sh | ||
| ./android/check-android.sh | ||
| ``` | ||
|
|
||
| The script is pass/fail: boundary test first, then the Android target | ||
| resolve. Its output names the exact commands and results for the PR | ||
| record. No world hosting, drive, recovery, provider, push, or presence | ||
| surface is built here — client facade only. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/usr/bin/env bash | ||
| # Slice-1 Android gate for the id-client facade (#7938 child #13403). | ||
| # Pass/fail: host tests (unit + dependency boundary + authenticated | ||
| # session), then the Android arm64-v8a target resolve. | ||
| # | ||
| # Toolchain notes (verified 2026-11-23 on this host): | ||
| # - Host checks use the ambient `cargo` (nix 1.99.0 here) with NO `RUSTC` | ||
| # override: exporting a mismatched `RUSTC` poisons proc-macro reuse | ||
| # (E0514) by mixing the ambient cargo with another toolchain's rustc. | ||
| # - The Android check uses `rustup run <toolchain> cargo` with an | ||
| # explicit RUSTC scoped to that invocation only: the bare `rustc` on | ||
| # PATH belongs to a different sysroot and reports the android target | ||
| # as missing (E0463). The user-wide sccache wrapper | ||
| # (~/.cargo/config.toml `build.rustc-wrapper`) is bypassed there via | ||
| # a passthrough wrapper so the 1.99.1 target build never shares cache | ||
| # entries with the ambient 1.99.0 host build. | ||
| # - The `ring`/`aws-lc-sys` build scripts need the NDK clang: | ||
| # ANDROID_NDK_HOME must point at an installed NDK (e.g. | ||
| # ~/.local/share/android-sdk/ndk/27.0.12077973); cc-rs derives | ||
| # `aarch64-linux-android<api>-clang` from it. Without it the target | ||
| # check fails at C compilation, not at Rust resolution. | ||
| set -euo pipefail | ||
| cd "$(dirname "$0")/.." | ||
|
|
||
| TOOLCHAIN="${RUSTUP_TOOLCHAIN:-1.99.1}" | ||
|
|
||
| echo "== host: id-client tests (boundary + session) ==" | ||
| env -u RUSTC cargo test -p id-client | ||
|
|
||
| echo "== android target resolve: aarch64-linux-android ==" | ||
| if [ -z "${ANDROID_NDK_HOME:-}" ]; then | ||
| for candidate in "$HOME/.local/share/android-sdk/ndk/"*/; do | ||
| if [ -x "${candidate}toolchains/llvm/prebuilt/linux-x86_64/bin/clang" ]; then | ||
| export ANDROID_NDK_HOME="$candidate" | ||
| break | ||
| fi | ||
| done | ||
| fi | ||
| if [ -z "${ANDROID_NDK_HOME:-}" ]; then | ||
| echo "FAIL: ANDROID_NDK_HOME is unset and no NDK found under ~/.local/share/android-sdk/ndk/" | ||
| echo "install one with: sdkmanager --install \"ndk;27.0.12077973\"" | ||
| exit 1 | ||
| fi | ||
| echo "NDK: $ANDROID_NDK_HOME" | ||
| # cc-rs (used by ring/aws-lc-sys build scripts) does not derive the NDK | ||
| # clang from ANDROID_NDK_HOME; it needs CC/CXX/AR for the target triple. | ||
| # API 21 is the arm64-v8a minimum and keeps slice 1 compatible with the | ||
| # widest device range. | ||
| NDK_BIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" | ||
| export TARGET_CC="$NDK_BIN/aarch64-linux-android21-clang" | ||
| export TARGET_CXX="$NDK_BIN/aarch64-linux-android21-clang++" | ||
| export TARGET_AR="$NDK_BIN/llvm-ar" | ||
| # Passthrough wrapper: `exec`s the real compiler with no caching, so the | ||
| # Android-target build under toolchain $TOOLCHAIN cannot read or write | ||
| # sccache entries owned by the ambient host toolchain. | ||
| ID_CLIENT_PASSTHROUGH="$(mktemp)" | ||
| printf '#!/usr/bin/env bash\nexec "$@"\n' > "$ID_CLIENT_PASSTHROUGH" | ||
| chmod +x "$ID_CLIENT_PASSTHROUGH" | ||
| # Isolated target dir: the 1.99.1 android-resolve build (including its | ||
| # host proc-macros) must not share target/ with the ambient 1.99.0 host | ||
| # build — sharing produces E0514 cross-version reuse errors in both | ||
| # directions and confuses sccache. Verified 2026-11-23. | ||
| export CARGO_TARGET_DIR="$PWD/target/android-check" | ||
| export RUSTC="${RUSTC:-$(rustup which --toolchain "$TOOLCHAIN" rustc)}" | ||
| CARGO_BUILD_RUSTC_WRAPPER="$ID_CLIENT_PASSTHROUGH" \ | ||
| rustup run "$TOOLCHAIN" cargo check -p id-client --target aarch64-linux-android | ||
| rm -f "$ID_CLIENT_PASSTHROUGH" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| [package] | ||
| name = "id-client" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| rust-version = "1.96" | ||
| description = "Client-only Rust facade for the id native Android client v1 (slice 1 of #7938, child #13403)" | ||
| license = "MIT OR Apache-2.0" | ||
|
|
||
| # Slice 1 of the native Android client v1 plan (#7938, child issue | ||
| # #13403, design doc/2026-11-08T22-06-00Z_design_id_android_client): | ||
| # a dedicated client facade along the completed #3447 crate seams. | ||
| # This crate depends ONLY downward on client-safe leaves (id-core, | ||
| # id-caps, id-config, id-store, id-events, id-groups, id-sync, | ||
| # id-directory) and NEVER on id-worlds (wasmtime/russh/serve/listener), | ||
| # id-web (axum), id-cli, id-native-shell or id-hw-shell. The | ||
| # `android_dependency_boundary` test enforces that exclusion; the | ||
| # `authenticated_session` test proves one signed client session | ||
| # against an in-memory test world with no hosting surface. | ||
|
|
||
| [features] | ||
| default = [] | ||
|
|
||
| [dependencies] | ||
| anyhow = "1" | ||
| id-caps = { path = "../id-caps", default-features = false } | ||
| id-config = { path = "../id-config" } | ||
| id-core = { path = "../id-core", default-features = false } | ||
| id-directory = { path = "../id-directory", default-features = false } | ||
| id-events = { path = "../id-events", default-features = false } | ||
| id-groups = { path = "../id-groups", default-features = false } | ||
| id-store = { path = "../id-store", default-features = false } | ||
| id-sync = { path = "../id-sync", default-features = false } | ||
| ed25519-dalek = { version = "3", features = ["rand_core"] } | ||
| rand = "0.10" | ||
| serde = { version = "1", features = ["derive"] } | ||
| thiserror = "2" | ||
|
|
||
| [lints.rust] | ||
| unsafe_code = "warn" | ||
| rust_2018_idioms = { level = "warn", priority = -1 } | ||
| rust_2024_compatibility = { level = "warn", priority = -1 } | ||
| missing_debug_implementations = "warn" | ||
| missing_docs = "warn" | ||
| trivial_casts = "warn" | ||
| trivial_numeric_casts = "warn" | ||
| unused_lifetimes = "warn" | ||
| unused_qualifications = "warn" | ||
|
|
||
| [lints.clippy] | ||
| all = { level = "warn", priority = -1 } | ||
| pedantic = { level = "warn", priority = -1 } | ||
| nursery = { level = "warn", priority = -1 } | ||
| cargo = { level = "warn", priority = -1 } | ||
| unwrap_used = "deny" | ||
| expect_used = "deny" | ||
| panic = "deny" | ||
| unimplemented = "deny" | ||
| todo = "deny" | ||
| dbg_macro = "deny" | ||
| print_stdout = "allow" | ||
| print_stderr = "allow" | ||
| module_name_repetitions = "allow" | ||
| must_use_candidate = "allow" | ||
| missing_errors_doc = "allow" | ||
| missing_panics_doc = "allow" | ||
| redundant_pub_crate = "allow" | ||
| significant_drop_tightening = "allow" | ||
| option_if_let_else = "allow" | ||
| multiple_crate_versions = "allow" | ||
| cargo_common_metadata = "allow" | ||
| too_many_lines = "allow" | ||
| too_many_arguments = "allow" | ||
| fn_params_excessive_bools = "allow" | ||
| struct_excessive_bools = "allow" | ||
| cognitive_complexity = "allow" | ||
| future_not_send = "allow" | ||
| assert_is_empty = "allow" | ||
| chunks_exact_to_as_chunks = "allow" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| //! Client-only Rust facade for the native Android client v1. | ||
| //! | ||
| //! Slice 1 of #7938 (child #13403; design | ||
| //! `doc/2026-11-08T22-06-00Z_design_id_android_client`): the Kotlin shell | ||
| //! gets a server-free core boundary it can build against for `arm64-v8a`. | ||
| //! | ||
| //! Dependency direction is one way down, per the #3447 seam map: this | ||
| //! facade re-exports the client-safe leaves (`id-core`, `id-caps`, | ||
| //! `id-config`, `id-store`, `id-events`, `id-groups`, `id-sync`, | ||
| //! `id-directory`) and never depends on `id-worlds` (which owns | ||
| //! `wasmtime`, `russh`, and the serve/listener surfaces), `id-web` | ||
| //! (which owns `axum`), `id-cli`, or the shell crates. The | ||
| //! `tests/android_dependency_boundary.rs` check enforces that boundary; | ||
| //! keep it green when adding re-exports. | ||
| //! | ||
| //! No world hosting, remote-drive integration, recovery semantics, | ||
| //! phone-provider surfaces, push service, or background-presence promise | ||
| //! lives here — those are later slices. | ||
|
|
||
| pub mod session; | ||
|
|
||
| pub use session::{ClientIdentity, SessionError, TestWorld}; | ||
|
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A consumer depending on Useful? React with 👍 / 👎. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| //! One authenticated client session against a test world. | ||
| //! | ||
| //! The session is deliberately transport-free: the test world issues a | ||
| //! 32-byte challenge, the client signs it with its Ed25519 identity key, | ||
| //! and the world verifies the signature against the client's public key. | ||
| //! No world is hosted, no listener is opened, and no server/runtime | ||
| //! dependency (`wasmtime`, `axum`, `russh`) is involved — which is the | ||
| //! property the Android dependency boundary needs. | ||
|
|
||
| use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey}; | ||
|
|
||
| /// Errors from the client-only authenticated session. | ||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum SessionError { | ||
| /// The signature did not verify against the client's public key. | ||
| #[error("session signature did not verify")] | ||
| BadSignature, | ||
| /// The challenge is not the expected 32 bytes. | ||
| #[error("challenge must be exactly 32 bytes")] | ||
| BadChallenge, | ||
| } | ||
|
|
||
| /// A client-side Ed25519 identity (hardware backing arrives in slice 2; | ||
| /// | ||
| /// here the key is held in memory). | ||
| #[derive(Debug)] | ||
| pub struct ClientIdentity { | ||
| signing: SigningKey, | ||
| } | ||
|
|
||
| impl ClientIdentity { | ||
| /// Generate a fresh random identity. | ||
| #[must_use] | ||
| pub fn generate() -> Self { | ||
| Self { | ||
| signing: SigningKey::generate(&mut rand::rng()), | ||
| } | ||
| } | ||
|
|
||
| /// The public half the world pins for this client. | ||
| #[must_use] | ||
| pub fn verifying_key(&self) -> VerifyingKey { | ||
| self.signing.verifying_key() | ||
| } | ||
|
|
||
| /// Sign a 32-byte server challenge. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`SessionError::BadChallenge`] when the challenge is not | ||
| /// exactly 32 bytes. | ||
| pub fn sign_challenge(&self, challenge: &[u8]) -> Result<Signature, SessionError> { | ||
| if challenge.len() != 32 { | ||
| return Err(SessionError::BadChallenge); | ||
| } | ||
| Ok(self.signing.sign(challenge)) | ||
| } | ||
| } | ||
|
|
||
| /// An in-memory test world: it issues challenges and verifies sessions. | ||
| /// | ||
| /// This is the slice-1 stand-in for "a test world" in the acceptance | ||
| /// criteria — no hosting, no drive, no presence, just the auth gate the | ||
| /// later shell will build on. | ||
| #[derive(Debug)] | ||
| pub struct TestWorld { | ||
| challenge: [u8; 32], | ||
| } | ||
|
|
||
| impl TestWorld { | ||
| /// Create a test world with a fresh random challenge. | ||
| #[must_use] | ||
| pub fn new() -> Self { | ||
| use rand::Rng as _; | ||
| let mut challenge = [0_u8; 32]; | ||
| rand::rng().fill_bytes(&mut challenge); | ||
| Self { challenge } | ||
| } | ||
|
|
||
| /// The current challenge the client must sign. | ||
| #[must_use] | ||
| pub const fn challenge(&self) -> &[u8; 32] { | ||
| &self.challenge | ||
| } | ||
|
|
||
| /// Verify one authenticated client session. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns [`SessionError::BadSignature`] when the signature does not | ||
| /// verify against `client_key`. | ||
| pub fn verify_session( | ||
| &self, | ||
| client_key: &VerifyingKey, | ||
| signature: &Signature, | ||
| ) -> Result<(), SessionError> { | ||
| client_key | ||
| .verify(&self.challenge, signature) | ||
| .map_err(|_| SessionError::BadSignature) | ||
| } | ||
| } | ||
|
|
||
| impl Default for TestWorld { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| #![allow(clippy::unwrap_used, clippy::expect_used)] | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_roundtrip_verifies() { | ||
| let client = ClientIdentity::generate(); | ||
| let world = TestWorld::new(); | ||
| let sig = client.sign_challenge(world.challenge()).unwrap(); | ||
| world.verify_session(&client.verifying_key(), &sig).unwrap(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_wrong_key_rejected() { | ||
| let client = ClientIdentity::generate(); | ||
| let other = ClientIdentity::generate(); | ||
| let world = TestWorld::new(); | ||
| let sig = client.sign_challenge(world.challenge()).unwrap(); | ||
| let err = world | ||
| .verify_session(&other.verifying_key(), &sig) | ||
| .unwrap_err(); | ||
| assert!(matches!(err, SessionError::BadSignature)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_bad_challenge_length_rejected() { | ||
| let client = ClientIdentity::generate(); | ||
| let err = client.sign_challenge(&[0_u8; 7]).unwrap_err(); | ||
| assert!(matches!(err, SessionError::BadChallenge)); | ||
|
Comment on lines
+135
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new session API enforces challenge-length and signature-integrity invariants, but its tests exercise only individual examples: this rejection test checks just a seven-byte challenge, and there is no property coverage in AGENTS.md reference: AGENTS.md:L37-L39 Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When invoked with
--dry-run,--help, or a stray positional argument, this script silently ignores the argument and runs the host tests and Android checks, including filesystem writes. Declare that the gate accepts no arguments and reject unexpected input with a non-zero usage exit before the first subprocess. This violates the operator-script argument contract in rootAGENTS.md.AGENTS.md reference: AGENTS.md:L44-L48
Useful? React with 👍 / 👎.