[wasm] Domi pairing: seal a phone's device key and label to the waiting PC; v0.7.0

This commit is contained in:
2026-11-03 18:54:09 +01:00
parent 1c4bf4b373
commit 6c696ba3a6
4 changed files with 51 additions and 9 deletions
Generated
+8 -8
View File
@@ -270,7 +270,7 @@ dependencies = [
[[package]]
name = "custos-gen"
version = "0.6.0"
version = "0.7.0"
dependencies = [
"custos-vault",
"data-encoding",
@@ -282,7 +282,7 @@ dependencies = [
[[package]]
name = "custos-keys"
version = "0.6.0"
version = "0.7.0"
dependencies = [
"custos-vault",
"ed25519-dalek",
@@ -295,11 +295,11 @@ dependencies = [
[[package]]
name = "custos-qr"
version = "0.6.0"
version = "0.7.0"
[[package]]
name = "custos-seal"
version = "0.6.0"
version = "0.7.0"
dependencies = [
"chacha20poly1305",
"hkdf",
@@ -312,7 +312,7 @@ dependencies = [
[[package]]
name = "custos-share"
version = "0.6.0"
version = "0.7.0"
dependencies = [
"argon2",
"chacha20poly1305",
@@ -329,7 +329,7 @@ dependencies = [
[[package]]
name = "custos-totp"
version = "0.6.0"
version = "0.7.0"
dependencies = [
"custos-vault",
"data-encoding",
@@ -342,7 +342,7 @@ dependencies = [
[[package]]
name = "custos-vault"
version = "0.6.0"
version = "0.7.0"
dependencies = [
"argon2",
"bip39",
@@ -361,7 +361,7 @@ dependencies = [
[[package]]
name = "custos-wasm"
version = "0.6.0"
version = "0.7.0"
dependencies = [
"custos-qr",
"custos-seal",
+1 -1
View File
@@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/*"]
[workspace.package]
version = "0.6.0"
version = "0.7.0"
edition = "2024"
license = "MPL-2.0"
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
+24
View File
@@ -123,6 +123,15 @@ enum Request {
r#pub: String,
context: String,
},
/// Pairs this phone as a Domi device (Custos docs/07_domi_identity.md): seals its device label and its
/// Ed25519 device public key (`device`, base64url, made non-extractable by the page) to the PC that
/// waits with `pub`, for `domi-pair:<id>`. Returns the box and its sender code. Nothing secret goes in.
DomiPair {
r#pub: String,
id: String,
label: String,
device: String,
},
}
fn err(msg: impl ToString) -> Value {
@@ -415,6 +424,21 @@ pub fn handle(request: &[u8]) -> Value {
Err(e) => err(e),
}
}
Request::DomiPair { r#pub, id, label, device } => {
let device_ok = data_encoding::BASE64URL_NOPAD.decode(device.as_bytes()).is_ok_and(|d| d.len() == 32);
let id_ok = !id.is_empty() && id.len() <= 64 && id.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_');
let (Some(public), true, true) = (b64(&r#pub), device_ok, id_ok) else { return err("A malformed request.") };
let label: String = label.trim().chars().filter(|c| !c.is_control()).take(40).collect();
let plain = json!({ "label": label, "device": device }).to_string();
match custos_seal::seal(&public, format!("domi-pair:{id}").as_bytes(), plain.as_bytes()) {
Ok(sealed) => json!({
"ok": true,
"code": custos_seal::sender_code(&sealed).unwrap_or_default(),
"sealed": BASE64.encode(&sealed),
}),
Err(e) => err(e),
}
}
Request::PhoneApprove { wrapped, prf, r#pub, context } => {
let (Some(wrapped), Some(prf_key), Some(public)) = (b64(&wrapped), key32(&prf), b64(&r#pub)) else {
return err("A malformed request.");
+18
View File
@@ -138,3 +138,21 @@ fn a_phone_pairs_then_opens_and_approves() {
let pw = SecretString::from(PASSWORD);
assert!(Vault::open_with(&v.to_bytes().unwrap(), Unlock::Password(&pw), Unlock::Material(FactorKind::Approval, &m)).is_ok());
}
#[test]
fn a_phone_pairs_as_a_domi_device() {
// The PC waits with a one-time key; the phone seals its device public key and label to it.
let pc = Recipient::generate();
let device = data_encoding::BASE64URL_NOPAD.encode(&[5u8; 32]);
let r = call(json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "abc_-1", "label": " Pixel\n", "device": device }));
assert_eq!(r["ok"], true, "{r}");
let sealed = BASE64.decode(r["sealed"].as_str().unwrap().as_bytes()).unwrap();
assert_eq!(r["code"], custos_seal::sender_code(&sealed).unwrap());
assert!(pc.open(&sealed, b"domi-pair:other").is_err(), "the box is for this pairing only");
let plain: Value = serde_json::from_slice(&pc.open(&sealed, b"domi-pair:abc_-1").unwrap()).unwrap();
assert_eq!(plain, json!({ "label": "Pixel", "device": device }));
// Malformed: a device key of the wrong length, an id that would change the context.
let short = data_encoding::BASE64URL_NOPAD.encode(&[5u8; 31]);
assert_eq!(call(json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "abc", "label": "x", "device": short }))["ok"], false);
assert_eq!(call(json!({ "op": "domi_pair", "pub": BASE64.encode(&pc.public()), "id": "a:b", "label": "x", "device": device }))["ok"], false);
}