[repo] Undo cargo fmt churn in files this branch does not change; CLAUDE.md: the trap

This commit is contained in:
2026-11-04 00:27:37 +01:00
parent 06410ab3be
commit 510d5eecd1
7 changed files with 34 additions and 113 deletions
+5 -19
View File
@@ -48,21 +48,11 @@ const PHONE_APPROVAL: &[u8] = b"custos phone approval v1";
#[derive(Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case", rename_all_fields = "camelCase")]
enum FactorIn {
Password {
password: SecretString,
},
Password { password: SecretString },
/// A factor service's or a device's answer, sealed to a key from `recipient` (`pub`) for `context`.
Sealed {
factor: FactorKind,
r#pub: String,
sealed: String,
context: String,
},
Sealed { factor: FactorKind, r#pub: String, sealed: String, context: String },
/// Material the page holds itself: a passkey's PRF output (base64).
Material {
factor: FactorKind,
material: SecretString,
},
Material { factor: FactorKind, material: SecretString },
}
#[derive(Deserialize)]
@@ -436,12 +426,8 @@ pub fn handle(request: &[u8]) -> Value {
}
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 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()) {
+10 -37
View File
@@ -17,14 +17,8 @@ fn call(v: Value) -> Value {
/// A version-2 vault: the master password and a TOTP factor with `totp` as its material.
fn vault(totp: &[u8]) -> Vault {
let pw = SecretString::from(PASSWORD);
let mut v = Vault::create_with(
Unlock::Password(&pw),
"Master password",
Unlock::Material(FactorKind::Totp, totp),
"TOTP",
FAST,
)
.unwrap();
let mut v = Vault::create_with(Unlock::Password(&pw), "Master password", Unlock::Material(FactorKind::Totp, totp), "TOTP", FAST)
.unwrap();
let mut login = Item::new(ItemType::WebLogin, "GitHub", 0);
login.set("password", SECRET, 0);
v.add(login);
@@ -59,8 +53,7 @@ fn open_with_password_and_a_sealed_totp_release() {
assert_eq!(me["match"], custos_seal::match_code(&public));
// What the factor service sends back after a valid code.
let sealed = BASE64.encode(&custos_seal::seal(&public, context.as_bytes(), &material).unwrap());
let sealed_in =
|ctx: &str| json!({ "kind": "sealed", "factor": "totp", "pub": me["pub"], "sealed": sealed, "context": ctx });
let sealed_in = |ctx: &str| json!({ "kind": "sealed", "factor": "totp", "pub": me["pub"], "sealed": sealed, "context": ctx });
let password = json!({ "kind": "password", "password": PASSWORD });
// Only the right context opens it.
@@ -98,9 +91,7 @@ fn a_phone_pairs_then_opens_and_approves() {
// The PC waits with a one-time key; the phone seals its pairing to it.
let pc = Recipient::generate();
let context = "pair:abc";
let r = call(
json!({ "op": "phone_enrol", "pub": BASE64.encode(&pc.public()), "context": context, "label": "Phone", "prf": prf64 }),
);
let r = call(json!({ "op": "phone_enrol", "pub": BASE64.encode(&pc.public()), "context": context, "label": "Phone", "prf": prf64 }));
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(), "the PC checks the code the phone shows");
@@ -114,8 +105,7 @@ fn a_phone_pairs_then_opens_and_approves() {
// The PC adds both factors.
let passkey_id = v.add_factor(Unlock::Material(FactorKind::Passkey, &prf), "Phone passkey").unwrap();
let approval_id =
v.add_factor_apart(Unlock::Material(FactorKind::Approval, &approval), "Phone", &[&passkey_id]).unwrap();
let approval_id = v.add_factor_apart(Unlock::Material(FactorKind::Approval, &approval), "Phone", &[&passkey_id]).unwrap();
let file = b64(&v);
// The phone opens it with its passkey and the master password.
@@ -140,18 +130,13 @@ fn a_phone_pairs_then_opens_and_approves() {
let req_pub = BASE64.encode(&requester.public());
assert_eq!(call(json!({ "op": "match_code", "pub": req_pub }))["match"], requester.match_code());
let ctx = format!("approval:{approval_id}:r1");
let wrong_key = call(
json!({ "op": "phone_approve", "wrapped": wrapped, "prf": BASE64.encode(&[8u8; 32]), "pub": req_pub, "context": ctx }),
);
let wrong_key = call(json!({ "op": "phone_approve", "wrapped": wrapped, "prf": BASE64.encode(&[8u8; 32]), "pub": req_pub, "context": ctx }));
assert_eq!(wrong_key["ok"], false);
let r = call(json!({ "op": "phone_approve", "wrapped": wrapped, "prf": prf64, "pub": req_pub, "context": ctx }));
let sealed = BASE64.decode(r["sealed"].as_str().unwrap().as_bytes()).unwrap();
let m = requester.open(&sealed, ctx.as_bytes()).unwrap();
let pw = SecretString::from(PASSWORD);
assert!(
Vault::open_with(&v.to_bytes().unwrap(), Unlock::Password(&pw), Unlock::Material(FactorKind::Approval, &m))
.is_ok()
);
assert!(Vault::open_with(&v.to_bytes().unwrap(), Unlock::Password(&pw), Unlock::Material(FactorKind::Approval, &m)).is_ok());
}
#[test]
@@ -159,9 +144,7 @@ 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 }),
);
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());
@@ -170,16 +153,6 @@ fn a_phone_pairs_as_a_domi_device() {
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
);
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);
}