[repo] Undo cargo fmt churn in files this branch does not change; CLAUDE.md: the trap
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user