Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,23 @@ jobs:
run: cargo fmt --check --all
- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
# A workspace build unifies features, so only a build of its own shows this crate without them.
- name: keygo-core holds no crypto without its feature
run: |
cargo clippy -p keygo-core --all-targets -- -D warnings
deps=$(cargo tree -p keygo-core -e normal --depth 1 --prefix none | tail -n +2 | cut -d' ' -f1 | sort | xargs)
[ "$deps" = "serde thiserror uuid" ] || { echo "unexpected keygo-core deps: $deps" >&2; exit 1; }
- name: keygo-server holds no crypto or client code
run: |
# Proves the pattern below still matches, so renaming the feature can't silently disable it.
client=$(cargo tree -p keygo-client -e features)
grep -q 'keygo-core feature "crypto"' <<<"$client"
server=$(cargo tree -p keygo-server -e features)
if grep -E 'keygo-client|keygo-core feature "crypto"' <<<"$server"; then exit 1; fi

# Rust-native tests (no NDK). Runs in parallel with android-test once lint passes.
rust-test:
needs: [ detect-changes ]
needs: [ detect-changes, rust-lint ]
if: needs.detect-changes.outputs.rust == 'true'
runs-on: ubuntu-latest

Expand Down Expand Up @@ -108,8 +121,14 @@ jobs:
restore-keys: ${{ runner.os }}-cargo-test-
- name: Build
run: cargo build --workspace --all-targets --verbose
# A workspace build unifies features, so keygo-client's "crypto" reaches every crate in it.
# keygo-core and keygo-server are also tested alone, in the form the server ships them.
- name: Run tests
run: cargo test --workspace --verbose
run: cargo test --workspace --exclude keygo-server --verbose
- name: Run keygo-core tests without crypto
run: cargo test -p keygo-core --verbose
- name: Run keygo-server tests
run: cargo test -p keygo-server --verbose
# Offline builds never see the schema, so a migration that changes a queried column would
# still compile against stale .sqlx data. Recompute it against the migrated database instead.
- name: Install sqlx-cli
Expand Down
8 changes: 5 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ Rust workspace (`rust/`, toolchain pinned in `rust-toolchain.toml`, edition 2024

| Crate | Purpose |
|-----------------|-------------------------------------------------------------------------------|
| `keygo-core` | Crypto, ARK session, passkeys, TOTP, backup, card formatting used by the app |
| `keygo-uniffi` | UniFFI bindings exposing `keygo-core` to Kotlin (`libkeygo_bindings.so`) |
| `keygo-core` | Key hierarchy, ids, `Sealed<T>`, shared by client and server. Crypto sits behind the `crypto` feature; the server must leave it off, so it can store wrapped keys but never hold one |
| `keygo-client` | App-only: ARK session, passkeys, TOTP, backup format, card formatting. The server must not depend on it. `keygo_client::crypto` re-exports `keygo-core` |
| `keygo-uniffi` | UniFFI bindings exposing `keygo-client` to Kotlin (`libkeygo_bindings.so`) |
| `keygo-opaque` | OPAQUE (opaque-ke, ristretto255 + Argon2) client/server wrapper, `forbid(unsafe_code)` |
| `keygo-server` | Self-hostable sync server (axum + sqlx/Postgres + clap CLI), see Sync Server |
| `tools/uniffi-bindgen` | Bindgen runner used by `make bindgen` |
Expand Down Expand Up @@ -198,7 +199,8 @@ Caddy as TLS proxy; `.env.example` sets `DOMAIN` and signups).
multiple statements.
- **Trailing commas** on multi-line parameter lists and collection literals.
- **Rust constructors** — ids are made with `random()`, secret material (keys, tokens, codes) with
`generate()`. Server ids come from the `random_id!`/`uuid_id!` macros in `domain/ids.rs`.
`generate()`. Ids the client and server share live in `keygo-core`; server-only ids come from the
`random_id!`/`uuid_id!` macros in `domain/ids.rs`.

## Testing

Expand Down
3 changes: 2 additions & 1 deletion rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[alias]
serve = "run --bin keygo-server -- serve"
# `-p`, not `--bin`: `--bin` selects the whole workspace, which turns on keygo-core's crypto feature.
serve = "run -p keygo-server -- serve"
29 changes: 21 additions & 8 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions rust/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ check: ## cargo check the workspace
fmt: ## Format Rust code with cargo fmt
cargo fmt --all

test: ## cargo test the workspace
cargo test --workspace
test: ## cargo test the workspace, with keygo-core and keygo-server also built without crypto
cargo test --workspace --exclude keygo-server
cargo test -p keygo-core
cargo test -p keygo-server

clean: ## Remove build artifacts and generated jniLibs
cargo clean
Expand Down
31 changes: 31 additions & 0 deletions rust/crates/keygo-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "keygo-client"
version.workspace = true
edition.workspace = true

[dependencies]
keygo-core = { path = "../keygo-core", features = ["crypto"] }

thiserror.workspace = true
uuid.workspace = true
zeroize.workspace = true
base64.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true

async-trait = "0.1.89"
ciborium = "0.2.2"
coset = "0.4.2"
passkey = "0.6.0"
passkey-authenticator = { version = "0.6.0", features = ["tokio"] }
# Needed so passkey JSON responses are serialized into base64 strings
passkey-types = { version = "0.6.0", features = ["serialize_bytes_as_base64_string"] }

csv = "1.4.0"
email_address = "0.2.9"
subtle = "2.6"
totp-rs = { version = "6.0.0", features = ["otpauth", "zeroize"] }
url = "2.5.8"

[dev-dependencies]
tokio = { workspace = true, features = ["rt", "macros"] }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::crypto::kdf::new_salt;
use crate::crypto::{
AccountRootKey, CryptoError, Encrypts, NamespaceDataAad, NamespaceId, NamespaceKey,
NamespaceKeyAad, RootKEK, Sealed, SecretKind, SymmetricKey, UserId, VaultId, VaultKey, Wraps,
AccountRootKey, CryptoError, Encrypts, KeyMaterial, NamespaceDataAad, NamespaceId,
NamespaceKey, NamespaceKeyAad, RootKek, Sealed, SecretKind, UserId, VaultId, VaultKey, Wraps,
};
use std::sync::{Mutex, MutexGuard};
use subtle::ConstantTimeEq;
Expand Down Expand Up @@ -208,8 +208,8 @@ impl ArkSession {
}
}

fn derive_kek(password: &str, salt: &[u8]) -> ArkSessionResult<RootKEK> {
RootKEK::from_password(password.as_bytes(), salt).map_err(ArkSessionError::Derivation)
fn derive_kek(password: &str, salt: &[u8]) -> ArkSessionResult<RootKek> {
RootKek::from_password(password.as_bytes(), salt).map_err(ArkSessionError::Derivation)
}

#[cfg(test)]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::b64;
use crate::backup::BackupError;
use crate::backup::BackupKey;
pub use crate::crypto::KeySource;
use crate::crypto::kdf::argon2::Argon2Params;
use crate::crypto::kdf::new_salt;
use crate::crypto::{AccountRootKey, Encrypts, Sealed, aad};
use crate::crypto::{AccountRootKey, BackupAad, BackupKey, Encrypts, Sealed};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
Expand All @@ -14,13 +14,6 @@ pub struct EncryptionHeader {
pub nonce: Vec<u8>,
}

#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
#[serde(rename_all = "snake_case")]
pub enum KeySource {
Passphrase,
Ark,
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Kdf {
Expand Down Expand Up @@ -52,18 +45,6 @@ impl Kdf {
}
}

aad! {
/// Wire format: change only with a version bump.
pub struct BackupAad {
pub version: u32,
pub source: KeySource,
}
}

impl Encrypts for BackupKey {
type Aad = BackupAad;
}

#[derive(Clone, Copy)]
pub enum BackupCredential<'a> {
Passphrase(&'a [u8]),
Expand Down Expand Up @@ -161,7 +142,7 @@ mod tests {
use super::*;
use crate::backup::CURRENT_VERSION;
use crate::crypto::kdf::argon2::MAX_ARGON2_MEM_KIB;
use crate::crypto::{CryptoError, SymmetricKey};
use crate::crypto::{CryptoError, KeyMaterial};

#[test]
fn key_source_serialization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tests {
use super::*;
use crate::backup::encryption::{Kdf, KeySource};
use crate::backup::{Card, Login, Passkey, Vault};
use crate::crypto::{AccountRootKey, CryptoError, SymmetricKey};
use crate::crypto::{AccountRootKey, CryptoError, KeyMaterial};

fn sample_backup() -> Backup {
Backup {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod encryption;
mod error;
mod format;
mod key;
mod model;

pub use encryption::{BackupCredential, KeySource};
Expand All @@ -10,7 +9,6 @@ pub use format::csv::{
ColumnMapping, Confidence, CsvAnalysis, CsvColumn, ExportPreset, FieldConfidence, ImportReport,
};
pub use format::{csv, json};
pub use key::BackupKey;
pub use model::{Backup, Card, Login, Passkey, Vault};

pub const CURRENT_VERSION: u32 = 1;
Expand Down
10 changes: 10 additions & 0 deletions rust/crates/keygo-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![forbid(unsafe_code)]

pub mod ark_session;
mod b64;
pub mod backup;
pub mod card;
pub use keygo_core as crypto;
pub mod passkey;
pub mod totp;
mod url;
File renamed without changes.
46 changes: 22 additions & 24 deletions rust/crates/keygo-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
[package]
name = "keygo-core"
description = "KeyGo ids, key types and sealed blobs, shared by the client and the server."
version.workspace = true
edition.workspace = true

[features]
# Everything that can touch key material. The server stores sealed blobs and leaves this off.
crypto = [
"dep:aead",
"dep:aes-gcm-siv",
"dep:argon2",
"dep:bcs",
"dep:hkdf",
"dep:sha2",
"dep:zeroize",
]

[dependencies]
serde = { workspace = true, features = ["derive"] }
thiserror.workspace = true
uuid.workspace = true
zeroize.workspace = true
base64.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
sha2.workspace = true

aead = "0.6.0"
aes-gcm-siv = "0.12.1"
async-trait = "0.1.89"
ciborium = "0.2.2"
coset = "0.4.2"
passkey = "0.6.0"
passkey-authenticator = { version = "0.6.0", features = ["tokio"] }
# Needed so passkey JSON responses are serialized into base64 strings
passkey-types = { version = "0.6.0", features = ["serialize_bytes_as_base64_string"] }

argon2 = "0.6.0"
bcs = "0.2.0"
csv = "1.4.0"
email_address = "0.2.9"
hkdf = "0.13.0"
subtle = "2.6"
totp-rs = { version = "6.0.0", features = ["otpauth", "zeroize"] }
url = "2.5.8"
aead = { version = "0.6.0", optional = true }
aes-gcm-siv = { version = "0.12.1", optional = true }
argon2 = { version = "0.6.0", optional = true }
bcs = { version = "0.2.0", optional = true }
hkdf = { version = "0.13.0", optional = true }
sha2 = { workspace = true, optional = true }
zeroize = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
tokio = { workspace = true, features = ["rt", "macros"] }
base64.workspace = true
3 changes: 2 additions & 1 deletion rust/crates/keygo-core/src/crypto/aad.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::crypto::{CryptoResult, UserId, VaultId};
use crate::error::CryptoResult;
use crate::{UserId, VaultId};
use serde::Serialize;

/// AADs are BCS-encoded; the encoding is part of the stored format.
Expand Down
Loading
Loading