diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index d0decfb..aaa3c69 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -2,6 +2,30 @@
All notable changes to bolt-daemon. Newest first.
+## fix: pairing UI shows the peer HELLO name, never a socket address — 2026-10-24
+
+`pairing.request` under `--pairing-policy ask` was built from the transport
+address. The QUIC answerer passes a synthetic `0.0.0.0:0`, and the WS
+answerer passes the real TCP peer (`192.168.4.25:55170`). `remote_device_type`
+was always the literal `unknown`. HELLO carried no device name, so the Accept
+sheet and the post-accept session label had nothing else to show.
+
+- HELLO inner JSON gains optional `deviceName` and `deviceType`. Both are
+ omitted when this daemon has no usable name, so legacy peers and golden
+ vectors stay valid. A bind address or `ip:port` is never sealed in.
+- This daemon advertises `--device-name`, or the hostname with one trailing
+ `.local` removed. `--device-type` defaults to `desktop`.
+- The answerer reads the peer HELLO before Stage A and puts that name and
+ type on `pairing.request`. `session.connected` carries the same pair.
+ When the peer sent nothing usable, both events use `Unknown device` /
+ `unknown`.
+- CLI: `--device-name`, `--device-type`. Stderr: `[DEVICE] advertising name=`
+ or `[DEVICE] no usable local name`.
+
+An inbound MacBook running this build seals its computer/host name into the
+HELLO it sends the Studio. The Studio Accept sheet shows that name. An older
+MacBook that omits `deviceName` shows as `Unknown device`.
+
## docs: retire WebRTC-era operator docs/scripts, rewrite contract for current CLI — 2026-07-21
Public-tree cleanup; no protocol or runtime behavior change.
diff --git a/docs/DAEMON_CONTRACT.md b/docs/DAEMON_CONTRACT.md
index 657db40..5a5ca14 100644
--- a/docs/DAEMON_CONTRACT.md
+++ b/docs/DAEMON_CONTRACT.md
@@ -29,6 +29,8 @@ longer exist.
| `--socket-path` | `/tmp/bolt-daemon.sock` | IPC Unix socket path (Windows: named pipe). |
| `--data-dir` | identity `~/.bolt`, trust `~/.config/bolt-daemon` | Unified data directory. When set: identity at `
/identity.key`, trust at `/pins/trust.json`, signal files and endpoint metadata in ``. |
| `--pairing-policy` | `ask` | `ask`, `allow`, or `deny`. Invalid value → exit 1. |
+| `--device-name` | hostname | Human name sealed into this daemon's HELLO as `deviceName`. A blank, over-long, or address-shaped value is ignored and the hostname is used (one trailing `.local` removed). When neither is usable, HELLO omits `deviceName`. |
+| `--device-type` | `desktop` | Type sealed into HELLO as `deviceType` when a name is advertised. Accepted values: `phone`, `tablet`, `laptop`, `desktop`, `browser`. Anything else stays `desktop`. |
| `--phase-timeout-secs` | `30` | Per-phase timeout in seconds. Unparseable values are ignored and the default applies (the flag is not validated). |
### WsEndpoint Mode
@@ -97,6 +99,8 @@ NOT change these without a `docs/CHANGELOG.md` entry.
| `[bolt-daemon] mode=` | Startup | Banner; mode/pairing/timeout/paths echo |
| `[bolt-daemon] FATAL:` | Any | Fatal error, exit 1 follows |
| `[bolt-daemon] parent-death watchdog active` | Sidecar | Watchdog armed against parent PID |
+| `[DEVICE] advertising name=` | Startup | Usable local name will be sealed into HELLO |
+| `[DEVICE] no usable local name` | Startup | HELLO omits `deviceName` |
| `[IPC] listening on` | Startup | IPC server bound |
| `[WS_ENDPOINT] starting on` | Startup | WS endpoint about to serve |
| `[WT_CERT] hash=` | Startup | Ephemeral WT certificate generated |
@@ -145,7 +149,11 @@ The app SHOULD NOT enable transfer UI until `daemon.status` is received.
feature-gated endpoints. Zero WebRTC at runtime.
- **Session protection:** NaCl-box encrypted HELLO with capability
negotiation, Profile Envelope v1 framing post-HELLO, BTR-encrypted
- transfers when negotiated. Protocol violations fail closed.
+ transfers when negotiated. Protocol violations fail closed. HELLO may
+ include optional `deviceName` and `deviceType`. Legacy HELLOs that omit
+ them still parse. The answerer copies those fields onto `pairing.request`
+ and `session.connected`. A missing or address-shaped name becomes
+ `Unknown device`.
- **Discovery/signaling** is an app-layer concern. The daemon takes direct
connect instructions (`connect_remote.signal`) and serves inbound
connections; it does not talk to a rendezvous server at runtime.
diff --git a/docs/IPC_CONTRACT.md b/docs/IPC_CONTRACT.md
index 647a73b..bcfae46 100644
--- a/docs/IPC_CONTRACT.md
+++ b/docs/IPC_CONTRACT.md
@@ -164,7 +164,9 @@ A peer session has been established.
```json
{
"remote_peer_id": "base64-encoded-identity-public-key",
- "negotiated_capabilities": ["file_transfer"]
+ "negotiated_capabilities": ["file_transfer"],
+ "remote_device_name": "Evan's MacBook Pro",
+ "remote_device_type": "laptop"
}
```
@@ -172,6 +174,10 @@ A peer session has been established.
|-------|------|-------------|
| `remote_peer_id` | string | Remote peer's identity public key (base64) |
| `negotiated_capabilities` | string[] | Capabilities negotiated for this session |
+| `remote_device_name` | string | Human name from the peer HELLO. `"Unknown device"` when the peer omitted `deviceName` or sent a bind/socket address. |
+| `remote_device_type` | string | `phone`, `tablet`, `laptop`, `desktop`, `browser`, or `"unknown"` |
+
+Older consumers that ignore unknown fields keep working. A payload missing these two fields deserializes as `"Unknown device"` / `"unknown"`.
### `session.sas`
@@ -216,8 +222,8 @@ A remote peer is requesting to pair. Consumer must respond with a `pairing.decis
```json
{
"request_id": "evt-5",
- "remote_device_name": "iPhone 15",
- "remote_device_type": "mobile",
+ "remote_device_name": "Evan's MacBook Pro",
+ "remote_device_type": "laptop",
"remote_identity_pk_b64": "base64-encoded-key",
"sas": "A1B2C3",
"capabilities_requested": ["file_transfer"]
@@ -227,10 +233,10 @@ A remote peer is requesting to pair. Consumer must respond with a `pairing.decis
| Field | Type | Description |
|-------|------|-------------|
| `request_id` | string | Correlation ID — MUST be echoed in the decision response |
-| `remote_device_name` | string | Human-readable name of the remote device |
-| `remote_device_type` | string | Device type (e.g., "mobile", "desktop") |
-| `remote_identity_pk_b64` | string | Remote identity public key (base64) |
-| `sas` | string | Short Authentication String for verification |
+| `remote_device_name` | string | Human name from the peer HELLO (`deviceName`). `"Unknown device"` when that field is absent or is a bind address / socket address (`0.0.0.0:0`, `192.168.4.25:55170`). The transport address is never copied here. |
+| `remote_device_type` | string | `phone`, `tablet`, `laptop`, `desktop`, `browser`, or `"unknown"` |
+| `remote_identity_pk_b64` | string | Remote identity public key (base64). Empty when Stage A has not yet filled it. |
+| `sas` | string | Short Authentication String for verification. Empty when Stage A has not yet filled it. |
| `capabilities_requested` | string[] | Capabilities the remote peer is requesting |
### `transfer.incoming.request`
diff --git a/src/device_label.rs b/src/device_label.rs
new file mode 100644
index 0000000..de06bd2
--- /dev/null
+++ b/src/device_label.rs
@@ -0,0 +1,327 @@
+//! Human-readable device labels for pairing and session IPC.
+//!
+//! Socket addresses and bind addresses (`0.0.0.0:0`, `192.168.4.25:55170`) are
+//! transport coordinates, not names. The UI must never show them as the remote
+//! device. A name comes from HELLO (`deviceName` / `deviceType`) or from this
+//! daemon's own hostname / `--device-name`. When nothing usable is known, the
+//! placeholder is [`PeerDisplay::UNKNOWN_NAME`].
+
+/// Placeholder shown when HELLO carries no usable device name.
+pub const UNKNOWN_DEVICE_NAME: &str = "Unknown device";
+
+const UNKNOWN_DEVICE_TYPE: &str = "unknown";
+
+/// Types this daemon will advertise or accept from a peer HELLO.
+const KNOWN_DEVICE_TYPES: &[&str] = &["phone", "tablet", "laptop", "desktop", "browser"];
+
+/// Maximum accepted device-name length, in Unicode scalars.
+const MAX_DEVICE_NAME_CHARS: usize = 128;
+
+/// Name and type safe to put in `pairing.request` and `session.connected`.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct PeerDisplay {
+ pub device_name: String,
+ pub device_type: String,
+}
+
+impl PeerDisplay {
+ pub const UNKNOWN_NAME: &'static str = UNKNOWN_DEVICE_NAME;
+
+ /// No usable identity yet.
+ pub fn unknown() -> Self {
+ Self {
+ device_name: UNKNOWN_DEVICE_NAME.to_string(),
+ device_type: UNKNOWN_DEVICE_TYPE.to_string(),
+ }
+ }
+
+ /// Build a display label from optional HELLO fields.
+ ///
+ /// Bind addresses, raw IPs, and `ip:port` socket addresses are discarded.
+ /// A missing or unusable name becomes [`UNKNOWN_DEVICE_NAME`]. An unrecognized
+ /// type becomes `"unknown"` rather than a guessed platform.
+ pub fn from_hello(name: Option<&str>, device_type: Option<&str>) -> Self {
+ Self {
+ device_name: usable_device_name(name)
+ .unwrap_or_else(|| UNKNOWN_DEVICE_NAME.to_string()),
+ device_type: normalize_remote_device_type(device_type),
+ }
+ }
+}
+
+/// Device name and type this daemon seals into its own HELLO.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct DeviceClaim {
+ pub device_name: String,
+ pub device_type: String,
+}
+
+/// Local name this process will advertise. `name` is empty when neither the
+/// override nor the hostname is usable; HELLO then omits `deviceName`.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct LocalDeviceLabel {
+ pub name: String,
+ pub device_type: String,
+}
+
+/// Resolve the name advertised in outbound HELLO.
+///
+/// `--device-name` wins when it is a real name. Otherwise the machine hostname
+/// is used, with a single trailing `.local` removed (macOS `hostname` form).
+/// A bind address or socket address is never advertised.
+pub fn resolve_local_label(
+ name_override: Option<&str>,
+ type_override: Option<&str>,
+) -> LocalDeviceLabel {
+ resolve_local_label_with_hostname(name_override, type_override, system_hostname().as_deref())
+}
+
+/// Same as [`resolve_local_label`], with the hostname injected so tests do not
+/// depend on the machine they run on.
+pub fn resolve_local_label_with_hostname(
+ name_override: Option<&str>,
+ type_override: Option<&str>,
+ hostname: Option<&str>,
+) -> LocalDeviceLabel {
+ let host = hostname.map(strip_trailing_local);
+ let name = usable_device_name(name_override)
+ .or_else(|| usable_device_name(host.as_deref()))
+ .unwrap_or_default();
+ LocalDeviceLabel {
+ name,
+ device_type: advertised_device_type(type_override),
+ }
+}
+
+/// Claim to seal into HELLO, or `None` when `name` is blank or address-shaped.
+pub fn claim_from_local(name: &str, device_type: &str) -> Option {
+ let device_name = usable_device_name(Some(name))?;
+ Some(DeviceClaim {
+ device_name,
+ device_type: advertised_device_type(Some(device_type)),
+ })
+}
+
+/// `session.connected` payload. The display name is re-checked so a socket
+/// address cannot leak into the event even if a caller passes one through.
+pub fn session_connected_payload(
+ remote_peer_id: &str,
+ negotiated_capabilities: &[String],
+ display: &PeerDisplay,
+) -> serde_json::Value {
+ let shown = PeerDisplay::from_hello(Some(&display.device_name), Some(&display.device_type));
+ serde_json::json!({
+ "remote_peer_id": remote_peer_id,
+ "negotiated_capabilities": negotiated_capabilities,
+ "remote_device_name": shown.device_name,
+ "remote_device_type": shown.device_type,
+ })
+}
+
+/// A name a person can recognize. `None` for blanks, control characters,
+/// over-long strings, IP addresses, and socket addresses.
+pub fn usable_device_name(raw: Option<&str>) -> Option {
+ let trimmed = raw?.trim();
+ if trimmed.is_empty() || trimmed.chars().count() > MAX_DEVICE_NAME_CHARS {
+ return None;
+ }
+ if trimmed.chars().any(|c| c.is_control()) {
+ return None;
+ }
+ if is_raw_address(trimmed) {
+ return None;
+ }
+ Some(trimmed.to_string())
+}
+
+fn normalize_remote_device_type(raw: Option<&str>) -> String {
+ match canonical_device_type(raw) {
+ Some(kind) => kind,
+ None => UNKNOWN_DEVICE_TYPE.to_string(),
+ }
+}
+
+/// Type this daemon puts in its own HELLO. An omitted or unrecognized override
+/// stays `"desktop"` — the daemon is a desktop sidecar, not an unknown peer.
+fn advertised_device_type(raw: Option<&str>) -> String {
+ canonical_device_type(raw).unwrap_or_else(|| "desktop".to_string())
+}
+
+fn canonical_device_type(raw: Option<&str>) -> Option {
+ let trimmed = raw?.trim();
+ if trimmed.is_empty() {
+ return None;
+ }
+ let lower = trimmed.to_ascii_lowercase();
+ if KNOWN_DEVICE_TYPES.contains(&lower.as_str()) {
+ Some(lower)
+ } else {
+ None
+ }
+}
+
+/// True for bind addresses, raw IPs, `ip:port`, and URLs whose host is an IP.
+fn is_raw_address(name: &str) -> bool {
+ if name.parse::().is_ok() || name.parse::().is_ok() {
+ return true;
+ }
+ if let Some(inner) = name
+ .strip_prefix('[')
+ .and_then(|rest| rest.strip_suffix(']'))
+ {
+ if inner.parse::().is_ok() {
+ return true;
+ }
+ }
+ if let Some((_, rest)) = name.split_once("://") {
+ let hostport = rest.split(['/', '?', '#']).next().unwrap_or(rest);
+ if hostport.parse::().is_ok()
+ || hostport.parse::().is_ok()
+ {
+ return true;
+ }
+ }
+ false
+}
+
+fn system_hostname() -> Option {
+ let mut buf = [0u8; 256];
+ let rc = unsafe { libc::gethostname(buf.as_mut_ptr().cast::(), buf.len()) };
+ if rc != 0 {
+ return None;
+ }
+ let end = buf.iter().position(|byte| *byte == 0).unwrap_or(buf.len());
+ let raw = std::str::from_utf8(&buf[..end]).ok()?.trim();
+ if raw.is_empty() {
+ None
+ } else {
+ Some(raw.to_string())
+ }
+}
+
+/// macOS `hostname` is often `Name.local`. One trailing suffix is presentation,
+/// not part of the name a person recognizes.
+fn strip_trailing_local(raw: &str) -> String {
+ let trimmed = raw.trim();
+ trimmed
+ .strip_suffix(".local")
+ .unwrap_or(trimmed)
+ .trim()
+ .to_string()
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn human_names_are_usable() {
+ assert_eq!(
+ usable_device_name(Some(" Evan's MacBook Pro ")).as_deref(),
+ Some("Evan's MacBook Pro")
+ );
+ assert_eq!(
+ usable_device_name(Some("Mac Studio")).as_deref(),
+ Some("Mac Studio")
+ );
+ }
+
+ #[test]
+ fn bind_and_socket_addresses_are_not_names() {
+ for raw in [
+ "",
+ " ",
+ "0.0.0.0",
+ "0.0.0.0:0",
+ "127.0.0.1:1",
+ "192.168.4.25:55170",
+ "::",
+ "[::]",
+ "[::1]:55170",
+ "ws://192.168.4.25:9100",
+ "ws://0.0.0.0:9100",
+ ] {
+ assert!(
+ usable_device_name(Some(raw)).is_none(),
+ "{raw:?} must not be a device name"
+ );
+ }
+ }
+
+ #[test]
+ fn hello_display_uses_name_or_placeholder() {
+ let named = PeerDisplay::from_hello(Some("Evan's MacBook Pro"), Some("Laptop"));
+ assert_eq!(named.device_name, "Evan's MacBook Pro");
+ assert_eq!(named.device_type, "laptop");
+
+ let missing = PeerDisplay::from_hello(None, None);
+ assert_eq!(missing, PeerDisplay::unknown());
+
+ let socket = PeerDisplay::from_hello(Some("192.168.4.25:55170"), Some("nope"));
+ assert_eq!(socket.device_name, UNKNOWN_DEVICE_NAME);
+ assert_eq!(socket.device_type, "unknown");
+
+ let bind = PeerDisplay::from_hello(Some("0.0.0.0:0"), Some("desktop"));
+ assert_eq!(bind.device_name, UNKNOWN_DEVICE_NAME);
+ assert_eq!(bind.device_type, "desktop");
+ }
+
+ #[test]
+ fn local_label_prefers_override_then_hostname() {
+ let named = resolve_local_label_with_hostname(
+ Some("Evan's MacBook Pro"),
+ Some("laptop"),
+ Some("ignored-host"),
+ );
+ assert_eq!(named.name, "Evan's MacBook Pro");
+ assert_eq!(named.device_type, "laptop");
+
+ let from_host =
+ resolve_local_label_with_hostname(None, None, Some("Evans-MacBook-Pro.local"));
+ assert_eq!(from_host.name, "Evans-MacBook-Pro");
+ assert_eq!(from_host.device_type, "desktop");
+
+ let bind_override_falls_through = resolve_local_label_with_hostname(
+ Some("0.0.0.0:0"),
+ Some("desktop"),
+ Some("Mac Studio.local"),
+ );
+ assert_eq!(bind_override_falls_through.name, "Mac Studio");
+
+ let nothing =
+ resolve_local_label_with_hostname(Some("192.168.4.25:55170"), None, Some("0.0.0.0"));
+ assert!(nothing.name.is_empty());
+ assert!(claim_from_local(¬hing.name, ¬hing.device_type).is_none());
+ }
+
+ #[test]
+ fn claim_rejects_socket_and_keeps_a_real_name() {
+ assert!(claim_from_local("0.0.0.0:0", "desktop").is_none());
+ let claim = claim_from_local("Mac Studio", "desktop").expect("real name");
+ assert_eq!(claim.device_name, "Mac Studio");
+ assert_eq!(claim.device_type, "desktop");
+ }
+
+ #[test]
+ fn session_connected_payload_never_carries_a_socket() {
+ let payload = session_connected_payload(
+ "identity-b64",
+ &["bolt.file-hash".to_string()],
+ &PeerDisplay {
+ device_name: "192.168.4.25:55170".to_string(),
+ device_type: "unknown".to_string(),
+ },
+ );
+ assert_eq!(payload["remote_device_name"], UNKNOWN_DEVICE_NAME);
+ assert_eq!(payload["remote_peer_id"], "identity-b64");
+ assert_ne!(payload["remote_device_name"], "192.168.4.25:55170");
+
+ let named = session_connected_payload(
+ "identity-b64",
+ &[],
+ &PeerDisplay::from_hello(Some("Evan's MacBook Pro"), Some("laptop")),
+ );
+ assert_eq!(named["remote_device_name"], "Evan's MacBook Pro");
+ assert_eq!(named["remote_device_type"], "laptop");
+ }
+}
diff --git a/src/ipc/trust.rs b/src/ipc/trust.rs
index f3a0de0..8a15726 100644
--- a/src/ipc/trust.rs
+++ b/src/ipc/trust.rs
@@ -17,6 +17,8 @@ use std::time::Duration;
use serde::{Deserialize, Serialize};
+use crate::device_label::PeerDisplay;
+
use super::id::generate_request_id;
use super::server::ApprovalHandle;
use super::types::{Decision, IpcMessage, PairingRequestPayload};
@@ -332,6 +334,7 @@ pub async fn check_pairing_approval(
trust_path: &Path,
from_peer: &str,
policy: PairingPolicy,
+ remote_display: &PeerDisplay,
) -> Option {
// Note: We no longer check trust store here at Stage A.
// The trust store is keyed by identity_key_hex which is unknown at this point.
@@ -366,12 +369,19 @@ pub async fn check_pairing_approval(
}
};
- // Build pairing request
+ // Build pairing request. `from_peer` is the transport address and is only
+ // for logs. The sheet shows the HELLO device name, or "Unknown device"
+ // when the peer did not send one. A socket or bind address is never a name,
+ // even if a caller passes one in `remote_display`.
let request_id = generate_request_id();
+ let shown = PeerDisplay::from_hello(
+ Some(remote_display.device_name.as_str()),
+ Some(remote_display.device_type.as_str()),
+ );
let payload = PairingRequestPayload {
request_id: request_id.clone(),
- remote_device_name: from_peer.to_string(),
- remote_device_type: "unknown".to_string(),
+ remote_device_name: shown.device_name,
+ remote_device_type: shown.device_type,
remote_identity_pk_b64: String::new(),
sas: String::new(),
capabilities_requested: vec!["file_transfer".to_string()],
@@ -408,6 +418,8 @@ pub async fn check_pairing_approval(
#[cfg(test)]
mod tests {
use super::*;
+ use crate::device_label::PeerDisplay;
+ use crate::ipc::server::ApprovalHandle;
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::sync::atomic::{AtomicU64, Ordering};
@@ -562,21 +574,42 @@ mod tests {
#[tokio::test]
async fn check_approval_no_ipc_no_trust_returns_none() {
let path = temp_trust_path();
- let result = check_pairing_approval(None, &path, "unknown-peer", PairingPolicy::Ask).await;
+ let result = check_pairing_approval(
+ None,
+ &path,
+ "unknown-peer",
+ PairingPolicy::Ask,
+ &PeerDisplay::unknown(),
+ )
+ .await;
assert!(result.is_none(), "should return None when no IPC server");
}
#[tokio::test]
async fn check_approval_policy_deny_returns_none() {
let path = temp_trust_path();
- let result = check_pairing_approval(None, &path, "any-peer", PairingPolicy::Deny).await;
+ let result = check_pairing_approval(
+ None,
+ &path,
+ "any-peer",
+ PairingPolicy::Deny,
+ &PeerDisplay::unknown(),
+ )
+ .await;
assert!(result.is_none(), "policy=deny should return None");
}
#[tokio::test]
async fn check_approval_policy_allow_returns_allow_once() {
let path = temp_trust_path();
- let result = check_pairing_approval(None, &path, "any-peer", PairingPolicy::Allow).await;
+ let result = check_pairing_approval(
+ None,
+ &path,
+ "any-peer",
+ PairingPolicy::Allow,
+ &PeerDisplay::unknown(),
+ )
+ .await;
assert_eq!(
result,
Some(Decision::AllowOnce),
@@ -817,4 +850,69 @@ mod tests {
let _ = std::fs::remove_dir_all(path.parent().unwrap());
}
+
+ async fn answer_pairing_request(from_peer: &str, display: &PeerDisplay) -> serde_json::Value {
+ let path = temp_trust_path();
+ let (handle, event_rx) = ApprovalHandle::for_test(true);
+ let display = display.clone();
+ let from_peer = from_peer.to_string();
+ let approval = check_pairing_approval(
+ Some(&handle),
+ &path,
+ &from_peer,
+ PairingPolicy::Ask,
+ &display,
+ );
+ let mut payload = None;
+ let respond = async {
+ for _ in 0..200 {
+ if let Ok(msg) = event_rx.try_recv() {
+ if msg.msg_type == "pairing.request" {
+ let request_id = msg.payload["request_id"].as_str().unwrap().to_string();
+ payload = Some(msg.payload);
+ for _ in 0..200 {
+ if handle.test_deliver(&request_id, Decision::AllowOnce) {
+ return;
+ }
+ tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;
+ }
+ return;
+ }
+ }
+ tokio::time::sleep(tokio::time::Duration::from_millis(5)).await;
+ }
+ };
+ let (decision, ()) = tokio::join!(approval, respond);
+ assert_eq!(decision, Some(Decision::AllowOnce));
+ payload.expect("pairing.request")
+ }
+
+ #[tokio::test]
+ async fn pairing_request_shows_hello_name_not_socket() {
+ let payload = answer_pairing_request(
+ "0.0.0.0:0",
+ &PeerDisplay::from_hello(Some("Evan's MacBook Pro"), Some("laptop")),
+ )
+ .await;
+ assert_eq!(payload["remote_device_name"], "Evan's MacBook Pro");
+ assert_eq!(payload["remote_device_type"], "laptop");
+ assert_ne!(payload["remote_device_name"], "0.0.0.0:0");
+ }
+
+ #[tokio::test]
+ async fn pairing_request_placeholder_when_only_a_socket_is_known() {
+ let payload = answer_pairing_request(
+ "192.168.4.25:55170",
+ &PeerDisplay {
+ device_name: "192.168.4.25:55170".to_string(),
+ device_type: "unknown".to_string(),
+ },
+ )
+ .await;
+ assert_eq!(payload["remote_device_name"], PeerDisplay::UNKNOWN_NAME);
+ assert_eq!(payload["remote_device_type"], "unknown");
+ let name = payload["remote_device_name"].as_str().unwrap();
+ assert!(!name.contains("192.168.4.25"));
+ assert!(!name.contains("0.0.0.0"));
+ }
}
diff --git a/src/ipc/types.rs b/src/ipc/types.rs
index 608efcf..02c45a6 100644
--- a/src/ipc/types.rs
+++ b/src/ipc/types.rs
@@ -75,6 +75,20 @@ pub struct DaemonStatusPayload {
pub struct SessionConnectedPayload {
pub remote_peer_id: String,
pub negotiated_capabilities: Vec,
+ /// Human name from the peer HELLO. `"Unknown device"` when none was sent.
+ #[serde(default = "default_unknown_device_name")]
+ pub remote_device_name: String,
+ /// Peer device type from HELLO, or `"unknown"`.
+ #[serde(default = "default_unknown_device_type")]
+ pub remote_device_type: String,
+}
+
+fn default_unknown_device_name() -> String {
+ crate::device_label::UNKNOWN_DEVICE_NAME.to_string()
+}
+
+fn default_unknown_device_type() -> String {
+ "unknown".to_string()
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
diff --git a/src/lib.rs b/src/lib.rs
index 15a272d..c5e154a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,6 +4,10 @@
//! stable public API. This is an application crate, not a reusable library.
//! Use `test_support` (behind the `test-support` feature) for integration tests.
+/// Human device names for pairing and session IPC. Socket addresses are not names.
+#[doc(hidden)]
+pub mod device_label;
+
#[doc(hidden)]
pub mod dc_messages;
#[doc(hidden)]
diff --git a/src/main.rs b/src/main.rs
index f2bfc72..8857688 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,8 +16,8 @@
// Re-export into the binary crate so existing `crate::` paths still resolve.
#[allow(unused_imports)]
pub(crate) use bolt_daemon::{
- connect_signal, dc_messages, envelope, identity_store, ipc, session, transfer, web_hello,
- HELLO_PAYLOAD,
+ connect_signal, dc_messages, device_label, envelope, identity_store, ipc, session, transfer,
+ web_hello, HELLO_PAYLOAD,
};
mod ice_filter;
@@ -63,6 +63,10 @@ pub(crate) struct Args {
pub(crate) pairing_policy: ipc::trust::PairingPolicy,
pub(crate) socket_path: Option,
pub(crate) data_dir: Option,
+ /// Human name sealed into HELLO. Falls back to the hostname when omitted.
+ pub(crate) device_name: Option,
+ /// Device type sealed into HELLO (`phone`, `tablet`, `laptop`, `desktop`, `browser`).
+ pub(crate) device_type: Option,
/// QUIC listen address (answerer, e.g. "0.0.0.0:4433").
#[cfg(feature = "transport-quic")]
pub(crate) quic_listen: Option,
@@ -101,6 +105,8 @@ fn parse_args_from(argv: &[String]) -> Args {
let mut phase_timeout_secs: Option = None;
let mut socket_path = None;
let mut data_dir = None;
+ let mut device_name = None;
+ let mut device_type = None;
#[cfg(feature = "transport-ws")]
let mut ws_listen = None;
#[cfg(feature = "transport-webtransport")]
@@ -165,6 +171,14 @@ fn parse_args_from(argv: &[String]) -> Args {
i += 1;
data_dir = argv.get(i).cloned();
}
+ "--device-name" => {
+ i += 1;
+ device_name = argv.get(i).cloned();
+ }
+ "--device-type" => {
+ i += 1;
+ device_type = argv.get(i).cloned();
+ }
#[cfg(feature = "transport-ws")]
"--ws-listen" => {
i += 1;
@@ -223,6 +237,8 @@ fn parse_args_from(argv: &[String]) -> Args {
pairing_policy: pairing_policy.unwrap_or(ipc::trust::PairingPolicy::Ask),
socket_path,
data_dir,
+ device_name,
+ device_type,
#[cfg(feature = "transport-ws")]
ws_listen,
#[cfg(feature = "transport-webtransport")]
@@ -437,10 +453,24 @@ fn main() {
.as_ref()
.map(|dd| ipc::trust::trust_path_from_data_dir(dd))
.unwrap_or_else(ipc::trust::default_trust_path);
+ let local_device = device_label::resolve_local_label(
+ args.device_name.as_deref(),
+ args.device_type.as_deref(),
+ );
+ if local_device.name.is_empty() {
+ eprintln!("[DEVICE] no usable local name; HELLO omits deviceName");
+ } else {
+ eprintln!(
+ "[DEVICE] advertising name={:?} type={}",
+ local_device.name, local_device.device_type
+ );
+ }
let session_trust_config = session_loop::SessionTrustConfig {
trust_path,
pairing_policy: args.pairing_policy,
approval,
+ local_device_name: local_device.name,
+ local_device_type: local_device.device_type,
};
// File send signal: the native shell writes a file path to data_dir/send_file.signal
@@ -851,3 +881,23 @@ fn main() {
}
// ── Tests ───────────────────────────────────────────────────
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn device_flags_are_parsed() {
+ let argv = [
+ "bolt-daemon",
+ "--device-name",
+ "Evan's MacBook Pro",
+ "--device-type",
+ "laptop",
+ ]
+ .map(str::to_string);
+ let args = parse_args_from(&argv);
+ assert_eq!(args.device_name.as_deref(), Some("Evan's MacBook Pro"));
+ assert_eq!(args.device_type.as_deref(), Some("laptop"));
+ }
+}
diff --git a/src/session_loop.rs b/src/session_loop.rs
index a647156..ccf9f3b 100644
--- a/src/session_loop.rs
+++ b/src/session_loop.rs
@@ -62,6 +62,7 @@ pub use crate::ws_validation::validate_send_file_path;
use crate::ws_validation::{parse_transfer_id_bytes, sanitize_filename, MAX_TRANSFER_SIZE};
// BTR crypto extracted to ws_btr (MODULARITY-AUDITABILITY-2).
+use crate::device_label::{session_connected_payload, PeerDisplay};
use crate::ipc::server::ApprovalHandle;
use crate::ipc::trust::{
check_pairing_approval, enforce_stage_b, identity_key_to_hex, PairingPolicy, StageBResult,
@@ -99,6 +100,7 @@ pub(crate) async fn enforce_session_trust(
transport: &str,
peer_addr: SocketAddr,
remote_identity_pk: &[u8; 32],
+ remote_display: &PeerDisplay,
) -> Result> {
let identity_hex = identity_key_to_hex(remote_identity_pk);
let Some(config) = trust_config else {
@@ -142,6 +144,7 @@ pub(crate) async fn enforce_session_trust(
&config.trust_path,
&peer_addr.to_string(),
PairingPolicy::Ask,
+ remote_display,
)
.await
{
@@ -464,8 +467,11 @@ use bolt_core::crypto::{generate_ephemeral_keypair, KeyPair};
use bolt_core::session::SessionContext;
use crate::envelope::{build_error_payload, decode_envelope_with_btr, route_inner_message};
+#[cfg(test)]
+use crate::web_hello::build_hello_message;
use crate::web_hello::{
- build_hello_message, daemon_capabilities, negotiate_capabilities, parse_hello_typed, HelloError,
+ build_hello_message_with_device, daemon_capabilities, negotiate_capabilities,
+ parse_hello_typed, HelloError,
};
// ── Configuration ────────────────────────────────────────────
@@ -492,6 +498,31 @@ pub struct SessionTrustConfig {
/// `PairingPolicy::Ask`. `None` in headless and test paths, where `ask` stays
/// fail-closed: no channel means no approval, which means deny.
pub approval: Option,
+ /// Name sealed into this daemon's HELLO. Empty means omit `deviceName`.
+ pub local_device_name: String,
+ /// Type sealed into this daemon's HELLO (`desktop` unless overridden).
+ pub local_device_type: String,
+}
+
+impl SessionTrustConfig {
+ /// Device claim for outbound HELLO, if the configured name is usable.
+ pub(crate) fn device_claim(&self) -> Option {
+ crate::device_label::claim_from_local(&self.local_device_name, &self.local_device_type)
+ }
+}
+
+fn hello_for_peer(
+ identity_pk: &[u8; 32],
+ session_kp: &KeyPair,
+ remote_session_pk: &[u8; 32],
+ trust_config: Option<&SessionTrustConfig>,
+) -> Result> {
+ let claim = trust_config.and_then(SessionTrustConfig::device_claim);
+ build_hello_message_with_device(identity_pk, session_kp, remote_session_pk, claim.as_ref())
+}
+
+fn peer_display_from_hello(hello: &crate::web_hello::WebHelloInner) -> PeerDisplay {
+ PeerDisplay::from_hello(hello.device_name.as_deref(), hello.device_type.as_deref())
}
// Manual Debug: ApprovalHandle holds channels that are not usefully printable, so
@@ -503,6 +534,8 @@ impl std::fmt::Debug for SessionTrustConfig {
.field("trust_path", &self.trust_path)
.field("pairing_policy", &self.pairing_policy)
.field("approval", &self.approval.is_some())
+ .field("local_device_name", &self.local_device_name)
+ .field("local_device_type", &self.local_device_type)
.finish()
}
}
@@ -571,8 +604,13 @@ pub async fn connect_to_remote_ws(
eprintln!("[WS_CLIENT] received remote session-key");
// Step 3: Send HELLO (sealed with remote's session public key)
- let hello_msg = build_hello_message(&identity.public_key, &session_kp, &remote_session_pk)
- .map_err(|e| format!("[WS_CLIENT] failed to build HELLO: {e}"))?;
+ let hello_msg = hello_for_peer(
+ &identity.public_key,
+ &session_kp,
+ &remote_session_pk,
+ trust_config.as_ref(),
+ )
+ .map_err(|e| format!("[WS_CLIENT] failed to build HELLO: {e}"))?;
ws_sink
.send(Message::Text(hello_msg))
.await
@@ -588,7 +626,7 @@ pub async fn connect_to_remote_ws(
.and_then(|v| v.get("legacy")?.as_bool())
.unwrap_or(false);
- let (negotiated, remote_identity_pk, sas) = if is_legacy {
+ let (negotiated, remote_identity_pk, sas, remote_display) = if is_legacy {
// ── EA2 fail-closed: reject a legacy (no-identity) HELLO response ────
// A `legacy: true` response carries no identity key. Accepting it ran the
// outbound session with a zero identity, an empty SAS, and NO
@@ -616,12 +654,14 @@ pub async fn connect_to_remote_ws(
let remote_identity_pk =
crate::web_hello::decode_public_key(&hello_inner.identity_public_key)
.map_err(|e| format!("[WS_CLIENT] invalid remote identity key: {e}"))?;
+ let remote_display = peer_display_from_hello(&hello_inner);
enforce_session_trust(
trust_config.as_ref(),
SessionTrustRole::Offerer,
"WS_CLIENT",
synthetic_peer_addr,
&remote_identity_pk,
+ &remote_display,
)
.await?;
@@ -633,7 +673,7 @@ pub async fn connect_to_remote_ws(
);
eprintln!("[SAS] {sas}");
eprintln!("[WS_CLIENT] HELLO response ok, caps={negotiated:?}");
- (negotiated, remote_identity_pk, sas)
+ (negotiated, remote_identity_pk, sas, remote_display)
};
// Build session context
@@ -649,10 +689,7 @@ pub async fn connect_to_remote_ws(
emit_ipc(
ipc_tx.as_ref(),
"session.connected",
- serde_json::json!({
- "remote_peer_id": remote_pk_b64_identity,
- "negotiated_capabilities": negotiated,
- }),
+ session_connected_payload(&remote_pk_b64_identity, &negotiated, &remote_display),
);
if !sas.is_empty() {
emit_ipc(
@@ -733,8 +770,13 @@ pub async fn connect_to_remote_quic(
.map_err(|e| format!("[QUIC_CLIENT] invalid remote session key: {e}"))?;
eprintln!("[QUIC_CLIENT] received remote session-key");
- let hello_msg = build_hello_message(&identity.public_key, &session_kp, &remote_session_pk)
- .map_err(|e| format!("[QUIC_CLIENT] failed to build HELLO: {e}"))?;
+ let hello_msg = hello_for_peer(
+ &identity.public_key,
+ &session_kp,
+ &remote_session_pk,
+ trust_config.as_ref(),
+ )
+ .map_err(|e| format!("[QUIC_CLIENT] failed to build HELLO: {e}"))?;
sender
.send_message(hello_msg.as_bytes())
.await
@@ -753,12 +795,14 @@ pub async fn connect_to_remote_quic(
let negotiated = negotiate_capabilities(&local_caps, &hello_inner.capabilities);
let remote_identity_pk = crate::web_hello::decode_public_key(&hello_inner.identity_public_key)
.map_err(|e| format!("[QUIC_CLIENT] invalid remote identity key: {e}"))?;
+ let remote_display = peer_display_from_hello(&hello_inner);
enforce_session_trust(
trust_config.as_ref(),
SessionTrustRole::Offerer,
"QUIC_CLIENT",
remote,
&remote_identity_pk,
+ &remote_display,
)
.await?;
@@ -782,10 +826,7 @@ pub async fn connect_to_remote_quic(
emit_ipc(
ipc_tx.as_ref(),
"session.connected",
- serde_json::json!({
- "remote_peer_id": remote_pk_b64_identity,
- "negotiated_capabilities": negotiated,
- }),
+ session_connected_payload(&remote_pk_b64_identity, &negotiated, &remote_display),
);
emit_ipc(
ipc_tx.as_ref(),
@@ -874,17 +915,24 @@ pub async fn handle_quic_framed_stream(
let remote_identity_pk = crate::web_hello::decode_public_key(&hello_inner.identity_public_key)
.map_err(|e| format!("[QUIC_SESSION] {peer_addr} invalid remote identity key: {e}"))?;
+ let remote_display = peer_display_from_hello(&hello_inner);
enforce_session_trust(
trust_config.as_ref(),
SessionTrustRole::Answerer,
"QUIC_SESSION",
peer_addr,
&remote_identity_pk,
+ &remote_display,
)
.await?;
- let hello_response = build_hello_message(&identity.public_key, &session_kp, &remote_session_pk)
- .map_err(|e| format!("[QUIC_HELLO] {peer_addr} failed to build HELLO response: {e}"))?;
+ let hello_response = hello_for_peer(
+ &identity.public_key,
+ &session_kp,
+ &remote_session_pk,
+ trust_config.as_ref(),
+ )
+ .map_err(|e| format!("[QUIC_HELLO] {peer_addr} failed to build HELLO response: {e}"))?;
sender
.send_message(hello_response.as_bytes())
.await
@@ -910,10 +958,7 @@ pub async fn handle_quic_framed_stream(
emit_ipc(
ipc_tx,
"session.connected",
- serde_json::json!({
- "remote_peer_id": remote_pk_b64,
- "negotiated_capabilities": negotiated,
- }),
+ session_connected_payload(&remote_pk_b64, &negotiated, &remote_display),
);
emit_ipc(
ipc_tx,
@@ -1154,8 +1199,13 @@ async fn handle_connection(
eprintln!("[WS_HELLO] {peer_addr} negotiated capabilities: {negotiated:?}");
// ── Step 6: Send HELLO response ──────────────────────────
- let hello_response = build_hello_message(&identity.public_key, &session_kp, &remote_session_pk)
- .map_err(|e| format!("[WS_HELLO] {peer_addr} failed to build HELLO response: {e}"))?;
+ let hello_response = hello_for_peer(
+ &identity.public_key,
+ &session_kp,
+ &remote_session_pk,
+ trust_config,
+ )
+ .map_err(|e| format!("[WS_HELLO] {peer_addr} failed to build HELLO response: {e}"))?;
ws_sink
.send(Message::Text(hello_response))
.await
@@ -1165,12 +1215,14 @@ async fn handle_connection(
// ── Step 7: Build session context ────────────────────────
let remote_identity_pk = crate::web_hello::decode_public_key(&hello_inner.identity_public_key)
.map_err(|e| format!("[WS_SESSION] {peer_addr} invalid remote identity key: {e}"))?;
+ let remote_display = peer_display_from_hello(&hello_inner);
enforce_session_trust(
trust_config,
SessionTrustRole::Answerer,
"WS_SESSION",
peer_addr,
&remote_identity_pk,
+ &remote_display,
)
.await?;
@@ -1195,10 +1247,7 @@ async fn handle_connection(
emit_ipc(
ipc_tx,
"session.connected",
- serde_json::json!({
- "remote_peer_id": remote_pk_b64,
- "negotiated_capabilities": negotiated,
- }),
+ session_connected_payload(&remote_pk_b64, &negotiated, &remote_display),
);
emit_ipc(
ipc_tx,
@@ -1754,6 +1803,7 @@ pub(crate) static SESSION_GLOBALS_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mu
#[cfg(test)]
mod tests {
use super::*;
+ use crate::device_label::PeerDisplay;
use crate::envelope::{decode_envelope, encode_envelope};
use bolt_core::crypto::generate_ephemeral_keypair;
use bolt_core::identity::generate_identity_keypair;
@@ -1779,6 +1829,8 @@ mod tests {
)),
pairing_policy: PairingPolicy::Allow,
approval: None,
+ local_device_name: String::new(),
+ local_device_type: String::new(),
}
}
@@ -1826,6 +1878,8 @@ mod tests {
trust_path: tmp_dir.path().join("trust.json"),
pairing_policy: PairingPolicy::Ask,
approval: None,
+ local_device_name: String::new(),
+ local_device_type: String::new(),
};
let identity = generate_identity_keypair();
@@ -1835,6 +1889,7 @@ mod tests {
"WS_SESSION",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
@@ -1853,6 +1908,7 @@ mod tests {
"WS_SESSION",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
assert!(
@@ -1866,6 +1922,7 @@ mod tests {
"QUIC_SESSION",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
assert!(offerer.is_err(), "missing trust_config must deny (offerer)");
@@ -1885,6 +1942,8 @@ mod tests {
trust_path,
pairing_policy: PairingPolicy::Ask,
approval: None,
+ local_device_name: String::new(),
+ local_device_type: String::new(),
};
let result = enforce_session_trust(
@@ -1893,6 +1952,7 @@ mod tests {
"QUIC_SESSION",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
@@ -1913,6 +1973,8 @@ mod tests {
trust_path,
pairing_policy: PairingPolicy::Allow,
approval: None,
+ local_device_name: String::new(),
+ local_device_type: String::new(),
};
let result = enforce_session_trust(
@@ -1921,6 +1983,7 @@ mod tests {
"QUIC_CLIENT",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
@@ -1934,26 +1997,31 @@ mod tests {
// ever wrote a pin. These pin the prompt-and-persist loop end to end.
/// Drive `enforce_session_trust` while answering the emitted `pairing.request`
- /// with `decision`. Returns the enforcement result and the request_id observed on
- /// the IPC event channel, so callers can assert the event actually fired.
+ /// with `decision`. Returns the enforcement result, the request_id, and the
+ /// device name on the IPC event.
async fn ask_with_ui_decision(
trust: &SessionTrustConfig,
handle: &ApprovalHandle,
event_rx: &std::sync::mpsc::Receiver,
identity_pk: &[u8; 32],
decision: Decision,
+ peer_addr: std::net::SocketAddr,
+ remote_display: &PeerDisplay,
) -> (
Result>,
Option,
+ Option,
) {
let mut observed_request_id = None;
+ let mut observed_device_name = None;
let enforce = enforce_session_trust(
Some(trust),
SessionTrustRole::Answerer,
"WS_SESSION",
- "127.0.0.1:1".parse().unwrap(),
+ peer_addr,
identity_pk,
+ remote_display,
);
// Answer as the UI decision router would. The request is emitted before the
@@ -1964,6 +2032,9 @@ mod tests {
if msg.msg_type == "pairing.request" {
let request_id = msg.payload["request_id"].as_str().unwrap().to_string();
observed_request_id = Some(request_id.clone());
+ observed_device_name = msg.payload["remote_device_name"]
+ .as_str()
+ .map(|name| name.to_string());
for _ in 0..200 {
if handle.test_deliver(&request_id, decision) {
return;
@@ -1978,7 +2049,7 @@ mod tests {
};
let (result, ()) = tokio::join!(enforce, respond);
- (result, observed_request_id)
+ (result, observed_request_id, observed_device_name)
}
fn ask_trust_config(trust_path: PathBuf, handle: &ApprovalHandle) -> SessionTrustConfig {
@@ -1986,6 +2057,8 @@ mod tests {
trust_path,
pairing_policy: PairingPolicy::Ask,
approval: Some(handle.clone()),
+ local_device_name: String::new(),
+ local_device_type: String::new(),
}
}
@@ -1999,12 +2072,14 @@ mod tests {
let (handle, event_rx) = ApprovalHandle::for_test(true);
let trust = ask_trust_config(trust_path.clone(), &handle);
- let (result, request_id) = ask_with_ui_decision(
+ let (result, request_id, _) = ask_with_ui_decision(
&trust,
&handle,
&event_rx,
&identity.public_key,
Decision::AllowAlways,
+ "127.0.0.1:1".parse().unwrap(),
+ &PeerDisplay::unknown(),
)
.await;
@@ -2030,12 +2105,14 @@ mod tests {
let (handle, event_rx) = ApprovalHandle::for_test(true);
let trust = ask_trust_config(trust_path.clone(), &handle);
- let (result, _) = ask_with_ui_decision(
+ let (result, _, _) = ask_with_ui_decision(
&trust,
&handle,
&event_rx,
&identity.public_key,
Decision::AllowOnce,
+ "127.0.0.1:1".parse().unwrap(),
+ &PeerDisplay::unknown(),
)
.await;
@@ -2057,12 +2134,14 @@ mod tests {
let (handle, event_rx) = ApprovalHandle::for_test(true);
let trust = ask_trust_config(trust_path.clone(), &handle);
- let (result, _) = ask_with_ui_decision(
+ let (result, _, _) = ask_with_ui_decision(
&trust,
&handle,
&event_rx,
&identity.public_key,
Decision::DenyAlways,
+ "127.0.0.1:1".parse().unwrap(),
+ &PeerDisplay::unknown(),
)
.await;
@@ -2084,12 +2163,14 @@ mod tests {
let (handle, event_rx) = ApprovalHandle::for_test(true);
let trust = ask_trust_config(trust_path.clone(), &handle);
- let (result, _) = ask_with_ui_decision(
+ let (result, _, _) = ask_with_ui_decision(
&trust,
&handle,
&event_rx,
&identity.public_key,
Decision::DenyOnce,
+ "127.0.0.1:1".parse().unwrap(),
+ &PeerDisplay::unknown(),
)
.await;
@@ -2117,6 +2198,7 @@ mod tests {
"WS_SESSION",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
@@ -2150,6 +2232,7 @@ mod tests {
"WS_SESSION",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
@@ -2172,12 +2255,14 @@ mod tests {
let (handle, event_rx) = ApprovalHandle::for_test(true);
let trust = ask_trust_config(trust_path, &handle);
- let (_result, request_id) = ask_with_ui_decision(
+ let (_result, request_id, device_name) = ask_with_ui_decision(
&trust,
&handle,
&event_rx,
&identity.public_key,
Decision::AllowOnce,
+ "192.168.4.25:55170".parse().unwrap(),
+ &PeerDisplay::unknown(),
)
.await;
@@ -2185,12 +2270,81 @@ mod tests {
request_id.is_some(),
"enforce_session_trust must emit pairing.request under ask with no pin"
);
+ assert_eq!(
+ device_name.as_deref(),
+ Some(PeerDisplay::UNKNOWN_NAME),
+ "a socket address is not a device name"
+ );
assert!(
!request_id.unwrap().is_empty(),
"pairing.request must carry a request_id"
);
}
+ /// Inbound MacBook connect: the accept sheet uses the HELLO name, not the
+ /// synthetic QUIC address `0.0.0.0:0` or the TCP peer socket.
+ #[tokio::test]
+ async fn ask_pairing_request_uses_hello_device_name() {
+ let tmp_dir = tempfile::tempdir().unwrap();
+ let trust_path = tmp_dir.path().join("trust.json");
+ let identity = generate_identity_keypair();
+ let (handle, event_rx) = ApprovalHandle::for_test(true);
+ let trust = ask_trust_config(trust_path, &handle);
+ let display = PeerDisplay::from_hello(Some("Evan's MacBook Pro"), Some("laptop"));
+
+ let (_result, _request_id, device_name) = ask_with_ui_decision(
+ &trust,
+ &handle,
+ &event_rx,
+ &identity.public_key,
+ Decision::AllowOnce,
+ "0.0.0.0:0".parse().unwrap(),
+ &display,
+ )
+ .await;
+
+ assert_eq!(device_name.as_deref(), Some("Evan's MacBook Pro"));
+ }
+
+ /// The answerer's HELLO response carries this daemon's name so the peer can
+ /// show it. A socket-shaped local name is omitted.
+ #[test]
+ fn hello_for_peer_seals_local_device_name() {
+ let identity = generate_identity_keypair();
+ let session_kp = generate_ephemeral_keypair();
+ let remote = generate_ephemeral_keypair();
+ let trust = SessionTrustConfig {
+ trust_path: std::env::temp_dir().join("bolt-hello-name-trust.json"),
+ pairing_policy: PairingPolicy::Ask,
+ approval: None,
+ local_device_name: "Evan's MacBook Pro".to_string(),
+ local_device_type: "laptop".to_string(),
+ };
+ let msg = hello_for_peer(
+ &identity.public_key,
+ &session_kp,
+ &remote.public_key,
+ Some(&trust),
+ )
+ .unwrap();
+ let inner = parse_hello_typed(msg.as_bytes(), &session_kp.public_key, &remote).unwrap();
+ assert_eq!(inner.device_name.as_deref(), Some("Evan's MacBook Pro"));
+ assert_eq!(inner.device_type.as_deref(), Some("laptop"));
+
+ let mut socket_trust = trust.clone();
+ socket_trust.local_device_name = "0.0.0.0:0".to_string();
+ let bare = hello_for_peer(
+ &identity.public_key,
+ &session_kp,
+ &remote.public_key,
+ Some(&socket_trust),
+ )
+ .unwrap();
+ let inner = parse_hello_typed(bare.as_bytes(), &session_kp.public_key, &remote).unwrap();
+ assert!(inner.device_name.is_none());
+ assert!(inner.device_type.is_none());
+ }
+
/// An existing pin must short-circuit: no prompt, no UI consultation.
#[tokio::test]
async fn ask_with_existing_pin_does_not_prompt() {
@@ -2211,6 +2365,7 @@ mod tests {
"WS_SESSION",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
@@ -2236,6 +2391,7 @@ mod tests {
"WS_CLIENT",
"127.0.0.1:1".parse().unwrap(),
&identity.public_key,
+ &PeerDisplay::unknown(),
)
.await;
@@ -2615,6 +2771,8 @@ mod tests {
trust_path,
pairing_policy: PairingPolicy::Allow,
approval: None,
+ local_device_name: String::new(),
+ local_device_type: String::new(),
};
let server_handle = tokio::spawn(async move {
diff --git a/src/web_hello.rs b/src/web_hello.rs
index 9f1dacb..67fc911 100644
--- a/src/web_hello.rs
+++ b/src/web_hello.rs
@@ -81,6 +81,22 @@ pub struct WebHelloInner {
#[serde(rename = "identityPublicKey")]
pub identity_public_key: String,
pub capabilities: Vec,
+ /// Human-readable name of the sending device. Absent on legacy HELLOs.
+ /// Never a bind address or socket address; those are omitted by the builder
+ /// and ignored by display code.
+ #[serde(
+ default,
+ rename = "deviceName",
+ skip_serializing_if = "Option::is_none"
+ )]
+ pub device_name: Option,
+ /// `phone` | `tablet` | `laptop` | `desktop` | `browser`. Absent on legacy HELLOs.
+ #[serde(
+ default,
+ rename = "deviceType",
+ skip_serializing_if = "Option::is_none"
+ )]
+ pub device_type: Option,
}
// ── Key helpers (profile-level, stays in daemon) ────────────
@@ -112,15 +128,38 @@ pub fn build_hello_message(
identity_pk: &[u8; 32],
session_kp: &KeyPair,
remote_public_key: &[u8; 32],
+) -> Result> {
+ build_hello_message_with_device(identity_pk, session_kp, remote_public_key, None)
+}
+
+/// Build a HELLO that also carries a human device name, when `device` is set.
+///
+/// `None` omits `deviceName` / `deviceType` so legacy peers see the same inner
+/// JSON as before. A claim whose name is a socket or bind address is dropped.
+pub fn build_hello_message_with_device(
+ identity_pk: &[u8; 32],
+ session_kp: &KeyPair,
+ remote_public_key: &[u8; 32],
+ device: Option<&crate::device_label::DeviceClaim>,
) -> Result> {
// Default to base capabilities (no WT). Endpoints that need WT
// advertisement use daemon_capabilities(true) for negotiation;
// the HELLO response capabilities are informational.
+ // Re-validate so a socket-shaped claim cannot be sealed into HELLO.
+ let claim = device.and_then(|claim| {
+ crate::device_label::claim_from_local(&claim.device_name, &claim.device_type)
+ });
+ let (device_name, device_type) = match claim {
+ Some(claim) => (Some(claim.device_name), Some(claim.device_type)),
+ None => (None, None),
+ };
let inner = WebHelloInner {
msg_type: "hello".to_string(),
version: 1,
identity_public_key: to_base64(identity_pk),
capabilities: daemon_capabilities(false),
+ device_name,
+ device_type,
};
let inner_json = serde_json::to_vec(&inner)?;
let sealed = seal_box_payload(&inner_json, remote_public_key, &session_kp.secret_key)
@@ -262,12 +301,18 @@ mod tests {
version: 1,
identity_public_key: "AAAA".to_string(),
capabilities: vec!["bolt.profile-envelope-v1".to_string()],
+ device_name: None,
+ device_type: None,
};
let json = serde_json::to_string(&inner).unwrap();
assert!(json.contains("\"type\":\"hello\""));
assert!(json.contains("\"version\":1"));
assert!(json.contains("\"identityPublicKey\":\"AAAA\""));
assert!(json.contains("\"capabilities\":[\"bolt.profile-envelope-v1\"]"));
+ assert!(
+ !json.contains("deviceName") && !json.contains("deviceType"),
+ "absent device fields must stay off the wire"
+ );
let decoded: WebHelloInner = serde_json::from_str(&json).unwrap();
assert_eq!(decoded.version, 1);
assert_eq!(decoded.identity_public_key, "AAAA");
@@ -299,6 +344,8 @@ mod tests {
version: 1,
identity_public_key: to_base64(&kp_a.public_key),
capabilities: daemon_capabilities(false),
+ device_name: None,
+ device_type: None,
};
let plaintext = serde_json::to_vec(&inner).unwrap();
@@ -530,6 +577,8 @@ mod tests {
version: 1,
identity_public_key: to_base64(&identity.public_key),
capabilities: caps,
+ device_name: None,
+ device_type: None,
};
let plaintext = serde_json::to_vec(&inner).unwrap();
let sealed =
@@ -558,6 +607,8 @@ mod tests {
version: 1,
identity_public_key: to_base64(&identity.public_key),
capabilities: caps,
+ device_name: None,
+ device_type: None,
};
let plaintext = serde_json::to_vec(&inner).unwrap();
let sealed =
@@ -591,6 +642,8 @@ mod tests {
version: 1,
identity_public_key: to_base64(&identity.public_key),
capabilities: vec![],
+ device_name: None,
+ device_type: None,
};
let plaintext = serde_json::to_vec(&inner).unwrap();
let sealed =
@@ -621,6 +674,8 @@ mod tests {
version: 1,
identity_public_key: to_base64(&identity.public_key),
capabilities: vec![long_cap],
+ device_name: None,
+ device_type: None,
};
let plaintext = serde_json::to_vec(&inner).unwrap();
let sealed =
@@ -655,6 +710,8 @@ mod tests {
version: 1,
identity_public_key: to_base64(&identity.public_key),
capabilities: vec![cap_64.clone()],
+ device_name: None,
+ device_type: None,
};
let plaintext = serde_json::to_vec(&inner).unwrap();
let sealed =
@@ -669,4 +726,52 @@ mod tests {
assert!(result.is_ok());
assert_eq!(result.unwrap().capabilities, vec![cap_64]);
}
+
+ #[test]
+ fn legacy_hello_without_device_fields_still_parses() {
+ let json = r#"{"type":"hello","version":1,"identityPublicKey":"AA","capabilities":[]}"#;
+ let inner: WebHelloInner = serde_json::from_str(json).unwrap();
+ assert!(inner.device_name.is_none());
+ assert!(inner.device_type.is_none());
+ }
+
+ #[test]
+ fn hello_roundtrip_carries_device_name_and_drops_a_socket() {
+ use crate::device_label::DeviceClaim;
+
+ let identity_a = generate_identity_keypair();
+ let session_a = bolt_core::crypto::generate_ephemeral_keypair();
+ let session_b = bolt_core::crypto::generate_ephemeral_keypair();
+ let claim = DeviceClaim {
+ device_name: "Evan's MacBook Pro".to_string(),
+ device_type: "laptop".to_string(),
+ };
+
+ let msg = build_hello_message_with_device(
+ &identity_a.public_key,
+ &session_a,
+ &session_b.public_key,
+ Some(&claim),
+ )
+ .unwrap();
+ let inner = parse_hello_message(msg.as_bytes(), &session_a.public_key, &session_b).unwrap();
+ assert_eq!(inner.device_name.as_deref(), Some("Evan's MacBook Pro"));
+ assert_eq!(inner.device_type.as_deref(), Some("laptop"));
+
+ let socket = DeviceClaim {
+ device_name: "192.168.4.25:55170".to_string(),
+ device_type: "desktop".to_string(),
+ };
+ let bare = build_hello_message_with_device(
+ &identity_a.public_key,
+ &session_a,
+ &session_b.public_key,
+ Some(&socket),
+ )
+ .unwrap();
+ let inner =
+ parse_hello_message(bare.as_bytes(), &session_a.public_key, &session_b).unwrap();
+ assert!(inner.device_name.is_none());
+ assert!(inner.device_type.is_none());
+ }
}
diff --git a/src/wt_endpoint.rs b/src/wt_endpoint.rs
index 1d061b2..496be62 100644
--- a/src/wt_endpoint.rs
+++ b/src/wt_endpoint.rs
@@ -22,8 +22,12 @@ use wtransport::{Connection, Endpoint, Identity, ServerConfig};
use bolt_core::crypto::{generate_ephemeral_keypair, KeyPair};
use bolt_core::session::SessionContext;
+use crate::device_label::PeerDisplay;
+#[cfg(test)]
+use crate::web_hello::build_hello_message;
use crate::web_hello::{
- build_hello_message, daemon_capabilities, negotiate_capabilities, parse_hello_typed, HelloError,
+ build_hello_message_with_device, daemon_capabilities, negotiate_capabilities,
+ parse_hello_typed, HelloError,
};
// TRANSPORT-UNIFY-1 Phase 2: WT routes through the shared session loop; the
// envelope/BTR/transfer machinery is inherited from it, not re-owned here.
@@ -282,8 +286,16 @@ async fn handle_incoming_session(
eprintln!("[WT_HELLO] {peer_addr} negotiated capabilities: {negotiated:?}");
// ── Step 7: Send HELLO response ──────────────────────────
- let hello_response = build_hello_message(&identity.public_key, &session_kp, &remote_session_pk)
- .map_err(|e| format!("[WT_HELLO] {peer_addr} failed to build HELLO response: {e}"))?;
+ let local_claim = trust_config
+ .as_ref()
+ .and_then(SessionTrustConfig::device_claim);
+ let hello_response = build_hello_message_with_device(
+ &identity.public_key,
+ &session_kp,
+ &remote_session_pk,
+ local_claim.as_ref(),
+ )
+ .map_err(|e| format!("[WT_HELLO] {peer_addr} failed to build HELLO response: {e}"))?;
write_frame(&mut send, hello_response.as_bytes()).await?;
eprintln!("[WT_HELLO] {peer_addr} sent HELLO response");
@@ -296,12 +308,17 @@ async fn handle_incoming_session(
// (item 2); Ask/Deny/Allow per the current policy. A denied peer never reaches
// run_session_with_outbound / transfer handling. Authorization gating only: not
// verification, pins nothing.
+ let remote_display = PeerDisplay::from_hello(
+ hello_inner.device_name.as_deref(),
+ hello_inner.device_type.as_deref(),
+ );
enforce_session_trust(
trust_config.as_ref(),
SessionTrustRole::Answerer,
"WT_SESSION",
peer_addr,
&remote_identity_pk,
+ &remote_display,
)
.await?;
@@ -369,6 +386,8 @@ mod tests {
)),
pairing_policy: crate::ipc::trust::PairingPolicy::Allow,
approval: None,
+ local_device_name: String::new(),
+ local_device_type: String::new(),
}
}
@@ -385,6 +404,8 @@ mod tests {
.join(format!("bolt-wt-test-deny-{}-{n}.json", std::process::id())),
pairing_policy: crate::ipc::trust::PairingPolicy::Deny,
approval: None,
+ local_device_name: String::new(),
+ local_device_type: String::new(),
}
}