diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md index bec89a8..af0380b 100644 --- a/docs/PROTOCOL.md +++ b/docs/PROTOCOL.md @@ -329,7 +329,7 @@ sent, and a peer cannot negotiate it. | --- | --- | --- | | invite | `onionwire-invite-v2`, `0x00`-separated over `k`, `o`, `spk`, `kem` | same; `onionwire:v1` over `onionwire-invite-v1` `0x00`-separated `k`,`o`,`spk`, or over `k \|\| o \|\| spk` (legacy only) | | `loc ` | `"onionwire-loc-v1"` `0x00` `onion` `0x00` `ts` | same; `onion \|\| LF \|\| ts` (legacy only) | -| `prf ` | `"onionwire-prf-v1"` `0x00` `name` `0x00` `bio` `0x00` `xmr_addr` `0x00` `ts` | same; the four fields joined by LF (not yet gated — see below) | +| `prf ` | `"onionwire-prf-v1"` `0x00` `name` `0x00` `bio` `0x00` `xmr_addr` `0x00` `ts` | same; the four fields joined by LF (legacy only) | | `inv ` | `"onionwire-inv-v1"` `0x00` `amount_atomic` `0x00` `address` `0x00` `memo` `0x00` `ts` | same; the four fields joined by LF (legacy only) | | `rcp ` | `"onionwire-rcp-v1"` `0x00` `txid` `0x00` `amount_atomic` `0x00` `address` `0x00` `ts` | same; the four fields joined by LF (legacy only) | | `tip ` | `"onionwire-tip-v1"` `0x00` `txid` `0x00` `amount_atomic` `0x00` `address` `0x00` `memo` `0x00` `ts` | same; the five fields joined by LF (legacy only) | @@ -337,10 +337,6 @@ sent, and a peer cannot negotiate it. The tag suffixes do say `-v1`; that is the tag's own version, not the invite string version. -`prf ` is the one frame whose legacy fallback is not yet gated: it is accepted -unconditionally in this revision and moving it under `LEGACY_SIGS` is a -separate change. - **Mixed-fleet consequence.** Older builds verify only the untagged bytes, so they reject every tagged signature from a new sender — including `tip `, which older builds emitted and verified untagged. That direction needs the peer @@ -401,8 +397,8 @@ ed25519_sign(identity_sk, ``` **Legacy accept:** a signature over the four fields joined by LF is still -accepted on verify. New profile frames MUST use the domain-separated form. -Do not emit legacy. This fallback is not yet read through `LEGACY_SIGS`. +accepted on verify while `LEGACY_SIGS` is on. New profile frames MUST use the +domain-separated form. Do not emit legacy. Apply only for an existing friend, valid signature, newer `ts`. Not a public profile. Not a directory. diff --git a/src/profile.rs b/src/profile.rs index 8a8ac24..0bd762d 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -95,12 +95,13 @@ pub fn verify(identity_pk: &[u8], prf: &Profile) -> bool { &signature, ) .is_ok() - || vk - .verify( - &sign_msg_v1(&prf.display_name, &prf.bio, &prf.xmr_addr, prf.ts), - &signature, - ) - .is_ok() + || (crate::pay::legacy_sigs() + && vk + .verify( + &sign_msg_v1(&prf.display_name, &prf.bio, &prf.xmr_addr, prf.ts), + &signature, + ) + .is_ok()) } pub fn encode(prf: &Profile) -> Vec { diff --git a/tests/app_sig.rs b/tests/app_sig.rs index 523ddea..3ddb80d 100644 --- a/tests/app_sig.rs +++ b/tests/app_sig.rs @@ -212,6 +212,23 @@ fn untagged_loc(sk: &SigningKey, onion: &str, ts: i64) -> Loc { } } +fn untagged_prf(sk: &SigningKey, name: &str, bio: &str, xmr_addr: &str, ts: i64) -> Profile { + let mut msg = Vec::from(name.as_bytes()); + for f in [bio, xmr_addr] { + msg.push(b'\n'); + msg.extend_from_slice(f.as_bytes()); + } + msg.push(b'\n'); + msg.extend_from_slice(ts.to_string().as_bytes()); + Profile { + display_name: name.into(), + bio: bio.into(), + xmr_addr: xmr_addr.into(), + ts, + sig: sk.sign(&msg).to_bytes().to_vec(), + } +} + fn untagged_inv(sk: &SigningKey, amount: &str, address: &str, memo: &str, ts: i64) -> Invoice { let mut msg = Vec::from(amount.as_bytes()); msg.push(b'\n'); @@ -302,6 +319,27 @@ fn legacy_off_rejects_untagged_loc() { ); } +#[test] +fn legacy_off_rejects_untagged_prf() { + let (sk, pk) = keypair(); + let legacy = untagged_prf(&sk, "Ali", "hi", "", 2_000_000_000); + let tagged = profile::sign(&sk.to_bytes(), "Ali", "hi", "", 2_000_000_000).unwrap(); + pay::with_legacy_sigs(false, || { + assert!( + !profile::verify(&pk, &legacy), + "untagged prf must be rejected with legacy off" + ); + assert!( + profile::verify(&pk, &tagged), + "tagged prf must still verify with legacy off" + ); + }); + assert!( + profile::verify(&pk, &legacy), + "the switch restores acceptance after the scoped override" + ); +} + #[test] fn legacy_off_rejects_untagged_inv() { let (sk, pk) = keypair();