[wasm] Domi pairing: seal a phone's device key and label to the waiting PC; v0.7.0
This commit is contained in:
Generated
+8
-8
@@ -270,7 +270,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-gen"
|
name = "custos-gen"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -282,7 +282,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-keys"
|
name = "custos-keys"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
@@ -295,11 +295,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-qr"
|
name = "custos-qr"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-seal"
|
name = "custos-seal"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
"hkdf",
|
"hkdf",
|
||||||
@@ -312,7 +312,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-share"
|
name = "custos-share"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"chacha20poly1305",
|
"chacha20poly1305",
|
||||||
@@ -329,7 +329,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-totp"
|
name = "custos-totp"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-vault",
|
"custos-vault",
|
||||||
"data-encoding",
|
"data-encoding",
|
||||||
@@ -342,7 +342,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-vault"
|
name = "custos-vault"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"bip39",
|
"bip39",
|
||||||
@@ -361,7 +361,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "custos-wasm"
|
name = "custos-wasm"
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"custos-qr",
|
"custos-qr",
|
||||||
"custos-seal",
|
"custos-seal",
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "3"
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.6.0"
|
version = "0.7.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
|
repository = "https://gitea.marek-novak.cz/mnovak/CustosPublic"
|
||||||
|
|||||||
@@ -123,6 +123,15 @@ enum Request {
|
|||||||
r#pub: String,
|
r#pub: String,
|
||||||
context: 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 {
|
fn err(msg: impl ToString) -> Value {
|
||||||
@@ -415,6 +424,21 @@ pub fn handle(request: &[u8]) -> Value {
|
|||||||
Err(e) => err(e),
|
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 } => {
|
Request::PhoneApprove { wrapped, prf, r#pub, context } => {
|
||||||
let (Some(wrapped), Some(prf_key), Some(public)) = (b64(&wrapped), key32(&prf), b64(&r#pub)) else {
|
let (Some(wrapped), Some(prf_key), Some(public)) = (b64(&wrapped), key32(&prf), b64(&r#pub)) else {
|
||||||
return err("A malformed request.");
|
return err("A malformed request.");
|
||||||
|
|||||||
@@ -138,3 +138,21 @@ fn a_phone_pairs_then_opens_and_approves() {
|
|||||||
let pw = SecretString::from(PASSWORD);
|
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]
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user