ADR-141:BFLD 隐私控制平面:命名模式、操作与运行时证明¶
| 字段 | 值 |
|---|---|
| 状态 | 已接受 — 部分(构件已构建并测试;集成胶水待定 — 参见实现状态,提交 7d88eb84c) |
| 日期 | 2026-05-28 |
| 决策者 | ruv |
| 代码库目标 | wifi-densepose-bfld(新模块 mode.rs + attestation.rs;扩展 lib.rs PrivacyClass、sink.rs、privacy_gate.rs、identity_risk.rs、emitter.rs、ha_discovery.rs) |
| 关联 | ADR-010(见证链)、ADR-118(BFLD)、ADR-120(隐私类别 + 哈希轮换)、ADR-121(身份风险评分)、ADR-122(RuView HA/Matter 暴露)、ADR-136(流式引擎)、ADR-139(WorldGraph)、ADR-140(语义状态记录)、ADR-143(RF SLAM v2) |
1. 背景¶
1.1 缺口¶
BFLD crate(v2/crates/wifi-densepose-bfld/src/)已经实现了一套完整的、由结构强制执行的隐私姿态,但它完全是以一个 4 值数字类别 来完成的——不存在部署 模式 的一等概念,也不存在离散隐私 操作 的概念。阅读实际代码:
lib.rs将PrivacyClass定义为#[repr(u8)],包含四个变体Raw = 0、Derived = 1、Anonymous = 2、Restricted = 3,外加allows_network()/allows_matter()/as_u8()(lib.rs:82-117)。这就是系统用来表达“此部署被允许发出什么”的全部词汇。没有任何东西命名节点为何处于类别 2 而非类别 3,也没有记录实际应用了哪些隐私变换。privacy_gate.rs实现了PrivacyGate::demote()——一个单调、清零(zeroizing)的变换器,在每次类别转换时剥离有效载荷段(compressed_angle_matrix、csi_delta、amplitude_proxy、phase_proxy)(privacy_gate.rs:31-75)。剥离是真实且不可逆的,但它是无声的:没有任何东西记录哪个帧的哪些段被清零。没有审计线索,下游验证者也无法证明哪些内容被剥离。sink.rs通过Sink::MIN_CLASS和运行时check_class::<S>()(sink.rs:47-55)在编译时强制执行 I1,并带有三个具体标记LocalKind/NetworkKind/MatterKind。MQTT 主题路由器(mqtt_topics.rs:109-157)和 HA 发现(ha_discovery.rs:61-129)硬编码了规则“仅在类别 >= Anonymous 时发布,且identity_risk仅在恰好为 Anonymous 时发布。”这是一个分布在两个文件中的隐式 ACL;它没有在单一位置声明,也没有绑定到命名模式。identity_risk.rs定义了GateAction { Accept, PredictOnly, Reject, Recalibrate }(identity_risk.rs:57-69)——但这些是基于每个事件的风险门控操作,而非隐私操作。没有任何枚举命名模式所强制执行的隐私变换(例如“抑制身份”、“丢弃原始数据”、“仅聚合”)。emitter.rs将privacy_class: PrivacyClass::Anonymous硬编码为构造默认值(emitter.rs:82),而 Soul Signature 门仅由是否提供SoulMatchOracle来控制(emitter.rs:138、coherence_gate.rs:71)。Soul Signature 是否为某部署启用并不是一项已声明的策略——而是构造现场布线的隐式结果。
结果是:部署的隐私姿态被编码在四个独立位置——构造的 PrivacyClass、SoulMatchOracle 的存在/缺失、按类别门控的 MQTT/HA 扇出,以及 signature_hasher 的安装——没有单一声明对象表示“此节点运行在 CareWithConsent 模式,即类别为 Derived、Soul Signature 启用、identity_risk 发布、原始数据绝不联网”。没有任何运行时工件可供监管者、Home Assistant 仪表板或 WorldGraph(ADR-139)读取以了解有效策略,也没有密码学证明表明该策略确实逐帧得到执行。
ADR-140(语义状态记录)要求每个语义状态都能追溯到 privacy_action。ADR-139(WorldGraph)需要 privacy_limited_by 注解来计算哪些边/区域因隐私而退化。目前两者都没有可绑定的对象:BFLD 暴露了数值类别,但没有操作,也没有证明。本 ADR 填补了这一缺口。
1.2 这里的“模式”“操作”与“证明”指什么¶
- PrivacyMode 是一种面向操作员的命名部署姿态(例如
CareWithConsent)。它是监管者或安装人员所推理的、对人类有意义的单元。它不是新的强制原语——它是一个映射到现有PrivacyClass的声明式选择,外加 Soul Signature 门决策和 MQTT/Matter ACL。 - PrivacyAction 是模式所强制执行的离散、可机器检查的隐私变换(例如
SuppressIdentity、DropRaw)。操作是人类模式与privacy_gate.rs已经执行的字节级剥离之间的桥梁。它们正是 ADR-140 的privacy_action字段所承载的内容。 - PrivacyAttestationProof 是一个哈希链式记录(依据 ADR-010),记录哪个模式处于活动状态、哪些操作得到了执行、每个事件剥离了哪些字段。它是证明所声明模式得到遵守的密码学连续性证明,以只读方式提供给 HA/Matter 诊断。
本 ADR 不做的事情:它不改变四个 PrivacyClass 字节值,不削弱任何结构不变量(来自 lib.rs:8-11 的 I1/I2/I3),也不替换 PrivacyGate::demote()——它记录 demote() 所做的操作。
1.3 管道位置¶
SensingInputs
→ BfldEmitter::emit() (identity_risk + CoherenceGate)
↑ consults
PrivacyModeRegistry::active_mode() ← NEW
↓ resolves to (PrivacyClass, Soul gate, ACL)
→ PrivacyGate::demote(frame, target_class) (existing; now records stripped fields)
↓ emits per-frame
PrivacyActionRecord { actions, fields_stripped } ← NEW
↓ folded into
PrivacyAttestationProof { mode, actions, fields_stripped_per_event, prev_hash } ← NEW (hash-chained, ADR-010)
↓ surfaced
mqtt_topics.rs / ha_discovery.rs (active mode + proof hash diagnostic entity)
↓ consumed by
ADR-139 privacy_limited_by / ADR-140 privacy_action
The registry is consulted once per class transition (not once per byte). The attestation chain is appended per emitted event window, not per frame, to bound chain growth (see §2.5).
2. 决策¶
2.1 PrivacyMode:五种命名变体,叠加在 PrivacyClass 之上¶
在新模块 mode.rs 中引入 PrivacyMode。它是现有 4 类 PrivacyClass 之上的语义抽象;它在线路上不增加任何新的强制字节。
// v2/crates/wifi-densepose-bfld/src/mode.rs
use crate::PrivacyClass;
/// Operator-facing deployment posture. Maps deterministically to a
/// `PrivacyClass`, a Soul Signature gate decision, and an MQTT/Matter ACL via
/// the `PrivacyModeRegistry`. Adds no new wire bytes — `PrivacyClass` remains
/// the only byte carried in `BfldFrameHeader`.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PrivacyMode {
/// Local research: raw BFI retained, never networked. Maps to `Raw`.
RawResearch = 0,
/// Single-home production: anonymous sensing, Soul Signature OFF.
/// Maps to `Anonymous`, no per-day rf_signature_hash.
PrivateHome = 1,
/// Multi-tenant / enterprise: anonymous + per-seed salt rotation so no
/// two seeds can correlate. Maps to `Anonymous`, multiseed salt domain.
EnterpriseAnonymous = 2,
/// Care deployment with explicit consent: identity-derived fields enabled
/// behind consent. Maps to `Derived`, Soul Signature ON.
CareWithConsent = 3,
/// Regulated / no-identity: strictest posture. Maps to `Restricted`.
StrictNoIdentity = 4,
}
impl PrivacyMode {
/// The `PrivacyClass` this mode resolves to. This is the *only* coupling
/// to the existing enforcement layer.
#[must_use]
pub const fn privacy_class(self) -> PrivacyClass {
match self {
Self::RawResearch => PrivacyClass::Raw,
Self::PrivateHome | Self::EnterpriseAnonymous => PrivacyClass::Anonymous,
Self::CareWithConsent => PrivacyClass::Derived,
Self::StrictNoIdentity => PrivacyClass::Restricted,
}
}
/// Whether Soul Signature (`SignatureHasher` install + non-`Null` oracle)
/// is enabled in this mode. See `emitter.rs:138` / `coherence_gate.rs:71`.
#[must_use]
pub const fn soul_signature_enabled(self) -> bool {
matches!(self, Self::CareWithConsent)
}
/// Whether per-seed (multiseed) salt isolation is required so two seeds
/// in the same site produce uncorrelated `rf_signature_hash` (invariant I3,
/// `signature_hasher.rs:8-18`). Enterprise turns this on; single-home does not.
#[must_use]
pub const fn multiseed_salt(self) -> bool {
matches!(self, Self::EnterpriseAnonymous)
}
/// Stable string token used in TOML config, MQTT diagnostics, and the
/// attestation proof. Lowercase snake form of the variant.
#[must_use]
pub const fn token(self) -> &'static str {
match self {
Self::RawResearch => "raw_research",
Self::PrivateHome => "private_home",
Self::EnterpriseAnonymous => "enterprise_anonymous",
Self::CareWithConsent => "care_with_consent",
Self::StrictNoIdentity => "strict_no_identity",
}
}
}
将 PrivacyMode 与 PrivacyClass 保持分离(而不是将二者合并为一个 5 变体类)是有意为之:PrivacyClass 是一个具有字节语义的线路/接收端强制原语,frame.rs、sink.rs::check_class 以及 NVS/MQTT 上的表示都依赖它。五种模式中的两种(PrivateHome、EnterpriseAnonymous)解析到相同的类(Anonymous),但盐域不同——它们在类层面不可区分。模式是严格更高层的概念,不得扰动现有字节契约。
2.2 PrivacyAction:强制转换词汇表¶
// v2/crates/wifi-densepose-bfld/src/mode.rs (continued)
/// A discrete privacy transformation a mode enforces. These are the
/// machine-checkable bridge between a human `PrivacyMode` and the byte-level
/// stripping already performed by `PrivacyGate::demote()` (`privacy_gate.rs`).
///
/// ADR-140's semantic-state `privacy_action` field carries the *strongest*
/// action enforced for the event that produced the state.
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum PrivacyAction {
/// No transformation: the frame is published as-is at its class.
Allow = 0,
/// Strip identity-derived fields (`identity_risk_score`, `rf_signature_hash`)
/// — the `Restricted` strip in `event.rs:112-117`.
SuppressIdentity = 1,
/// Down-sample the angle/CSI surface (the `compressed_angle_matrix` /
/// `csi_delta` zeroing in `privacy_gate.rs:48-55`).
ReduceResolution = 2,
/// Refuse to network a `Raw` frame (structural invariant I1, `sink.rs:35`).
DropRaw = 3,
/// Emit only aggregate sensing (presence/motion/count/confidence); no
/// per-subject or per-cluster surface leaves the node.
AggregateOnly = 4,
}
PrivacyAction 实现了 Ord,因此每个事件的动作集合可以归约为其最强动作,用于 ADR-140 的单值 privacy_action 字段(即最大值)。这些动作有意与 GateAction(identity_risk.rs:57)正交:GateAction 回答“这个事件是否风险过高而不能发布?”;PrivacyAction 回答“当前模式要求对每个事件施加什么隐私转换?”它们可以组合——某个模式可以强制 SuppressIdentity,同时按事件的门控独立执行 Reject。
2.3 PrivacyModeRegistry:单一事实来源 + 仅追加审计日志¶
注册表正是缺口(§1.1)所缺失的那个已声明对象。它拥有当前活动模式、模式→动作映射、ACL,以及见证验证器可以重放的仅追加审计日志。
// v2/crates/wifi-densepose-bfld/src/mode.rs (continued)
use crate::sink::Sink;
/// Declares the active mode and the policy it implies. Consulted by the
/// emitter/gate on every class transition. Holds an append-only, witness-
/// checkable audit log of every mode resolution and action enforcement.
#[derive(Debug)]
pub struct PrivacyModeRegistry {
active: PrivacyMode,
/// Append-only; never mutated in place. Each entry is hashed into the
/// attestation chain (§2.5).
audit_log: Vec<ModeAuditEntry>,
}
/// One append-only audit record. ADR-010 §"Hash chain" linkage is applied at
/// the `PrivacyAttestationProof` layer, not here — this is the raw event.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ModeAuditEntry {
/// Monotonic capture-clock ns (matches `BfldEvent::timestamp_ns`).
pub timestamp_ns: u64,
/// Mode active at the moment of this transition/resolution.
pub mode: PrivacyMode,
/// Class the mode resolved to.
pub resolved_class: PrivacyClass,
/// The set of actions enforced, sorted ascending (Ord), deduplicated.
pub actions_enforced: Vec<PrivacyAction>,
}
impl PrivacyModeRegistry {
/// Build a registry pinned to `mode`. The production-safe default is
/// `PrivateHome` (resolves to `Anonymous`, matching `emitter.rs:82`).
#[must_use]
pub fn new(mode: PrivacyMode) -> Self {
Self { active: mode, audit_log: Vec::new() }
}
/// The currently active mode.
#[must_use]
pub const fn active_mode(&self) -> PrivacyMode {
self.active
}
/// The set of actions this mode enforces, sorted ascending. Pure function
/// of `active` — the canonical mode→actions mapping (§2.4 table).
#[must_use]
pub fn enforced_actions(&self) -> Vec<PrivacyAction> {
actions_for(self.active)
}
/// Whether a specific action is enforced under the active mode. This is the
/// predicate ADR-139/ADR-140 query to decide `privacy_limited_by` and
/// `privacy_action`.
#[must_use]
pub fn is_action_enforced(&self, action: PrivacyAction) -> bool {
actions_for(self.active).contains(&action)
}
/// Whether the active mode's class may cross sink `S`. Re-uses the
/// existing compile-time ACL (`sink.rs::check_class`). This is the
/// declared-in-one-place MQTT/Matter ACL the gap (§1.1) lacked.
#[must_use]
pub fn allows_sink<S: Sink>(&self) -> bool {
crate::sink::check_class::<S>(self.active.privacy_class()).is_ok()
}
/// Record a class transition / resolution into the append-only log and
/// return the entry that was appended (so the caller can fold it into the
/// attestation chain). Called by the emitter on every transition.
pub fn record_transition(&mut self, timestamp_ns: u64) -> &ModeAuditEntry {
let entry = ModeAuditEntry {
timestamp_ns,
mode: self.active,
resolved_class: self.active.privacy_class(),
actions_enforced: actions_for(self.active),
};
self.audit_log.push(entry);
self.audit_log.last().expect("just pushed")
}
/// Read-only view of the audit log for the witness verifier.
#[must_use]
pub fn audit_log(&self) -> &[ModeAuditEntry] {
&self.audit_log
}
}
/// Canonical mode→actions mapping (§2.4). Pure, total, `const`-friendly.
#[must_use]
pub fn actions_for(mode: PrivacyMode) -> Vec<PrivacyAction> {
use PrivacyAction::{Allow, AggregateOnly, DropRaw, ReduceResolution, SuppressIdentity};
let v = match mode {
PrivacyMode::RawResearch => vec![Allow], // local-only; I1 still blocks network in sink.rs
PrivacyMode::PrivateHome => vec![SuppressIdentity, DropRaw],
PrivacyMode::EnterpriseAnonymous => vec![SuppressIdentity, DropRaw, AggregateOnly],
PrivacyMode::CareWithConsent => vec![DropRaw, ReduceResolution],
PrivacyMode::StrictNoIdentity => {
vec![SuppressIdentity, ReduceResolution, DropRaw, AggregateOnly]
}
};
v // already authored in ascending Ord order
}
审计日志由 Vec 支持,并且在 API 表面上是仅追加的(没有 pop,没有索引可变)。注册表仅对 record_transition 要求 &mut self;active_mode、enforced_actions、is_action_enforced 和 allows_sink 是 &self 读取,可安全地从发布路径调用。
2.4 模式 →(类别、Soul Gate、MQTT ACL)映射¶
这是缺口(§1.1)所缺失的显式、单点声明。每一行都由 PrivacyMode::privacy_class()、PrivacyMode::soul_signature_enabled() 以及现有的类别门控路由器强制执行。
| 模式 | PrivacyClass |
Soul Signature | 盐域 | MQTT/HA 暴露(现有路由器) | 强制操作 |
|---|---|---|---|---|---|
RawResearch |
Raw (0) |
关闭 | 每节点 | 无 —— 类别 0 从不联网(mqtt_topics.rs:111,I1 sink.rs:35) |
Allow |
PrivateHome |
Anonymous (2) |
关闭 | 每节点 | presence/motion/count/conf/identity_risk(ha_discovery.rs:116) |
SuppressIdentity、DropRaw |
EnterpriseAnonymous |
Anonymous (2) |
关闭 | multiseed(signature_hasher.rs 中每种子 site_salt) |
与 PrivateHome 相同 | SuppressIdentity、DropRaw、AggregateOnly |
CareWithConsent |
Derived (1) |
开启(SoulMatchOracle + SignatureHasher) |
每节点 | 仅 LAN/研究 —— 类别 1 不在公共树上(mqtt_topics.rs:111) |
DropRaw、ReduceResolution |
StrictNoIdentity |
Restricted (3) |
关闭 | 每节点 | 仅 presence/motion/count/conf;identity_risk 未发布(mqtt_topics.rs:147、event.rs:113) |
SuppressIdentity、ReduceResolution、DropRaw、AggregateOnly |
有两个映射需要说明:
PrivateHome与EnterpriseAnonymous均 →Anonymous。 区别在于盐隔离,而不是类别。Enterprise 启用multiseed_salt(),使得在相邻单元中观察同一个人的两个种子产生不相关的rf_signature_hash值,从而在共享租户边界上保持 I3(signature_hasher.rs:8-18)。单户家庭不需要此功能。两者都按照现有ha_discovery.rs:116规则在类别 2 发布identity_risk—— Enterprise 还在语义上额外强制执行AggregateOnly,抑制除五个聚合实体之外的任何区域级或每集群暴露面。CareWithConsent→Derived且 Soul 开启。 这是唯一解析到类别Derived的模式,与lib.rs:88-90的注释“Soul Signature 部署所需。” 相匹配。它启用soul-signature(Cargo 特性,Cargo.toml:24-27)并安装一个真实的SoulMatchOracle,以便门控的Recalibrate豁免(coherence_gate.rs:71-84)对已登记主体触发。类别Derived不在公共 MQTT 树上(mqtt_topics.rs:111要求>= Anonymous),因此已同意的身份数据保留在 LAN/研究表面上 ——DropRaw和ReduceResolution仍然适用。
2.5 PrivacyAttestationProof:按 ADR-010 哈希链¶
证明提供密码学连续性,证明所声明的模式已被遵守。它直接复用 ADR-010 见证链原语:每个证明条目包含前一个条目的 SHAKE-256/BLAKE3 哈希(ADR-010 §“哈希链”,previous_hash/entry_hash 链接),因此任何插入、删除或重新排序都会破坏验证。
// v2/crates/wifi-densepose-bfld/src/attestation.rs
#![cfg(feature = "std")]
use crate::mode::{PrivacyAction, PrivacyMode};
use blake3::Hasher; // already a dependency (Cargo.toml:33)
/// Per-event privacy enforcement record — the unit folded into the chain.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PrivacyActionRecord {
/// Capture-clock ns of the event this record attests.
pub timestamp_ns: u64,
/// Strongest action enforced for this event (ADR-140 `privacy_action`).
pub strongest_action: PrivacyAction,
/// Names of payload/event fields stripped for this event, e.g.
/// "compressed_angle_matrix", "rf_signature_hash". Sorted lexicographically
/// so the canonical-bytes hash is deterministic.
pub fields_stripped: Vec<&'static str>,
}
/// One link in the attestation hash chain. ADR-010-compatible.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PrivacyAttestationProof {
/// Active mode at the time this link was sealed.
pub mode: PrivacyMode,
/// All actions enforced under `mode`, ascending (from the registry).
pub actions_enforced: Vec<PrivacyAction>,
/// Per-event strip records covered by this link (a window, see below).
pub fields_stripped_per_event: Vec<PrivacyActionRecord>,
/// BLAKE3 hash of the *previous* link's `entry_hash`; all-zero for genesis.
pub prev_hash: [u8; 32],
/// BLAKE3 over (mode token || actions || records || prev_hash). Computed by
/// `seal()`; this is the value the next link references as `prev_hash`.
pub entry_hash: [u8; 32],
}
impl PrivacyAttestationProof {
/// Seal a new link given the previous link's `entry_hash` (or `[0u8; 32]`
/// for the genesis link). The hash binds mode, actions, and per-event
/// strips, so altering any field after sealing breaks the chain.
#[must_use]
pub fn seal(
mode: PrivacyMode,
actions_enforced: Vec<PrivacyAction>,
fields_stripped_per_event: Vec<PrivacyActionRecord>,
prev_hash: [u8; 32],
) -> Self {
let mut h = Hasher::new();
h.update(mode.token().as_bytes());
for a in &actions_enforced {
h.update(&[*a as u8]);
}
for rec in &fields_stripped_per_event {
h.update(&rec.timestamp_ns.to_le_bytes());
h.update(&[rec.strongest_action as u8]);
for f in &rec.fields_stripped {
h.update(f.as_bytes());
h.update(&[0u8]); // length-free field separator
}
}
h.update(&prev_hash);
let entry_hash = *h.finalize().as_bytes();
Self { mode, actions_enforced, fields_stripped_per_event, prev_hash, entry_hash }
}
/// Verify chain linkage against the previous link's `entry_hash` AND that
/// `entry_hash` recomputes from the sealed fields (tamper evidence).
#[must_use]
pub fn verify_link(&self, expected_prev: [u8; 32]) -> bool {
if self.prev_hash != expected_prev {
return false;
}
let recomputed = Self::seal(
self.mode,
self.actions_enforced.clone(),
self.fields_stripped_per_event.clone(),
self.prev_hash,
);
recomputed.entry_hash == self.entry_hash
}
/// Short proof hash for diagnostics: `"blake3:<16 hex>"` (first 8 bytes of
/// `entry_hash`). Surfaced on the HA diagnostic entity (§2.6).
#[must_use]
pub fn short_hash(&self) -> String {
let mut s = String::with_capacity(7 + 16);
s.push_str("blake3:");
for b in &self.entry_hash[..8] {
s.push_str(&format!("{b:02x}"));
}
s
}
}
链粒度——按窗口,而非按帧。 证明关联一个事件窗口(例如 BfldEmitter 的一个发射周期,emitter.rs:138),而不是一个 CSI 帧。按帧的链在 20 Hz 下每天会增长 1,728,000 个链接;按窗口可将链限制在已发布事件速率内,同时仍为每个剥离项提供证明(每个窗口的 fields_stripped_per_event 会枚举其中的按事件剥离项)。复用 BLAKE3(它已经是依赖项,Cargo.toml:33),而不是引入 ADR-010 MAT 路径中使用的 SHAKE-256——ADR-010 §“Hash chain” 指定了哈希链接链,但未指定固定算法;BFLD 已经使用 BLAKE3 计算其 rf_signature_hash(signature_hasher.rs:20),因此复用它可避免在无 std 能力的 crate 中引入第二个加密依赖。
集成到 MQTT 发现 + 只读 HA 诊断实体¶
当前模式和证明哈希以只读诊断形式暴露,使操作员、监管机构或 cognitum-v0 仪表盘能够在不触碰传感实体的情况下查看实时隐私状态。这会扩展 ha_discovery.rs 和 mqtt_topics.rs,二者已经对每个实体进行类别门控。
render_discovery_payloads()(ha_discovery.rs:61)会为sensor渲染新的发现负载,其entity_category = "diagnostic",unique-id 为<node>_bfld_privacy_mode,状态主题为ruview/<node>/bfld/privacy_mode/state。其状态是一个紧凑 JSON 对象{"mode":"care_with_consent","class":"derived","proof":"blake3:<16hex>","actions":["drop_raw","reduce_resolution"]}。- 该实体在每个
>= Anonymous类别下发布(与现有五个诊断传感器相同的门控)并且额外在仅限 LAN 的研究表面上以Raw/Derived类别发布——因为研究/护理部署最需要展示其自身的证明。公共 树的类别门控(mqtt_topics.rs:111)保持不变;诊断模式实体会无论类别如何都添加到本地诊断表面,因此证明始终可在节点上检查。 - 它是严格只读的:该实体没有
command_topic。模式变更是操作员/配置操作(TOML + 重启,§2.7),绝不是 MQTT 写入——这与privacy_gate.rs的“无promote”姿态一致。
该实体上的证明哈希是最近一次密封的 PrivacyAttestationProof 的 short_hash()。拥有完整链(通过未来的 attestation export CLI 导出)的验证者可以确认从创世到显示哈希的连续性。
注册表接入发射器¶
BfldEmitter(emitter.rs:65-88)获得一个拥有的 PrivacyModeRegistry,并在每个发射窗口密封一个证明链接。该变更是增量的——现有 emit()/emit_with_oracle() 签名保持不变;注册表通过新的 builder 配置。
// emitter.rs additions (sketch)
pub struct BfldEmitter {
// ...existing fields (node_id, default_zone_id, privacy_class, gate, ring, signature_hasher)
registry: PrivacyModeRegistry, // NEW — single source of truth
last_proof_hash: [u8; 32], // NEW — chain tail; [0;32] genesis
}
impl BfldEmitter {
/// Configure the emitter from a named mode. Sets `privacy_class` from
/// `mode.privacy_class()`, installs/clears the signature hasher and Soul
/// oracle per `mode.soul_signature_enabled()`, and pins the registry.
#[must_use]
pub fn with_mode(mut self, mode: PrivacyMode) -> Self {
self.privacy_class = mode.privacy_class();
self.registry = PrivacyModeRegistry::new(mode);
self
}
/// Active mode + freshly sealed proof for the most recent emit window.
/// Read by the HA diagnostic entity (§2.6).
#[must_use]
pub fn attestation(&self) -> Option<&PrivacyAttestationProof> { /* tail of sealed chain */ }
}
在每次 emit() 中,门控决策(emitter.rs:171)之后,发射器:(1)调用 registry.record_transition(ts);(2)构建一个 PrivacyActionRecord,枚举隐私门控实际剥离的字段(例如,在 Restricted 类别下,event.rs:112-117 中 identity_risk_score + rf_signature_hash 的剥离会产生 fields_stripped = ["identity_risk_score","rf_signature_hash"]);(3)调用 PrivacyAttestationProof::seal(mode, actions, records, self.last_proof_hash) 并更新 last_proof_hash。已配置的基线模式(默认 PrivateHome)保留当前 Anonymous 默认值(emitter.rs:82),因此未迁移的调用方会看到相同的行为,外加一个已填充的证明链。
下游消费者(ADR-139、ADR-140)¶
| 消费者 | 读取内容 | 绑定 |
|---|---|---|
| ADR-140 语义状态记录 | PrivacyActionRecord::strongest_action |
填充记录的必填 privacy_action 字段;证明 entry_hash 填充记录的隐私来源引用 |
| ADR-139 WorldGraph | PrivacyModeRegistry::is_action_enforced(AggregateOnly) / ReduceResolution |
其证据被 ReduceResolution 或 AggregateOnly 降级的区域/边会被标记为 privacy_limited_by = <mode token>,以便数字孪生将该区域标记为隐私降级,而不是传感器盲区 |
| ADR-136 流式引擎 | attestation() 短哈希 |
阶段边界帧契约可以为下游阶段携带当前模式令牌,而无需重新推导它 |
ha_discovery.rs / mqtt_topics.rs |
当前模式 + short_hash() |
只读诊断实体(§2.6) |
这符合项目规则:每个语义状态都可追溯到信号证据 + 模型版本 + 校准版本 + 隐私决策:ADR-141 提供隐私决策的一半——PrivacyActionRecord(执行了什么)加上链 entry_hash(证明其已被执行)——ADR-140 将其与来自 ADR-134/ADR-135 的信号/模型/校准来源一起记录。
3. 后果¶
3.1 积极影响¶
- 单一声明策略对象。 部署的隐私立场现在是一个命名的
PrivacyMode和一个PrivacyModeRegistry,而不是四个分散的接线决策。安装者选择CareWithConsent;注册表确定性地派生类别、Soul 门控、盐域和 ACL。 - 密码学连续性。
PrivacyAttestationProof使“我们在 StrictNoIdentity 下运行,并在每个事件上剥离身份”成为可验证的声明,而不是代码审查断言。该链复用 ADR-010 原语,因此现有见证验证器可以自然扩展。 - 监管机构/操作员可见性。 只读 HA 诊断实体暴露实时模式和证明哈希,而不扩大传感表面——对护理机构合规审计有用。
- 干净的 ADR-139/ADR-140 绑定。
privacy_action和privacy_limited_by现在具有具体、可查询的来源(is_action_enforced、strongest_action),从而满足语义状态的追溯要求。 - 无线路/字节变更。
PrivacyClass字节值、BfldFrameHeader、sink.rsACL 以及 MQTT 主题树均未改动。模式是纯增量的。
3.2 负面¶
- 两个同类模式。
PrivateHome和EnterpriseAnonymous都解析为Anonymous;差异(盐域、AggregateOnly)位于类层之上,只有当下游消费者遵循动作集时才有意义。仅查看PrivacyClass的消费者无法区分它们。 - 链增长。 即使按窗口粒度,繁忙节点也会累积证明链接。需要导出/修剪策略(在验证导出后进行创世重新锚定),并推迟到后续迭代。
emitter.rs增加状态。 发射器现在拥有一个注册表和链尾,使其内存占用增大,并使emit()不再是输入→事件的纯转换。密封成本(对一个小缓冲区执行一次 BLAKE3)是亚微秒级但非零。- 模式变更需要重启。 设计上没有用于在运行时更改模式的 MQTT 命令主题(与
privacy_gate.rs的无promote姿态一致)。操作员通过 TOML 配置 + 重启来更改模式,这比仪表盘开关更重的操作。
3.3 风险¶
| 风险 | 概率 | 影响 | 缓解措施 |
|---|---|---|---|
模式→动作映射与 privacy_gate.rs 实际剥离的内容发生漂移,导致证明声称的字段实际上并未被移除 |
中 | 证明说谎——比没有证明更糟 | PrivacyActionRecord.fields_stripped 来自实际门控输出(event.rs/privacy_gate.rs 的返回值),而不是来自模式表;单元测试断言记录的剥离字段等于门控清零的字节 |
EnterpriseAnonymous 多种子盐未真正隔离(两个种子共享一个盐)→ 同一类下 I3 被破坏 |
低 | 跨单元身份关联 | multiseed_salt() 门控每个种子的 site_salt 派生;验收测试断言跨种子汉明距离约 128 位(复用 tests/signature_hasher.rs 中 ADR-120 §2.7 AC2) |
| 链创世混淆:部署中途重启的节点会启动新的创世,破坏与先前链的连续性 | 中 | 验证器看到无法与篡改区分的间断 | 创世链接记录 prev_hash = [0;32] 和一个启动纪元;验证器将带有已记录重启事件的创世链接视为合法的重新锚定,而不是断裂 |
操作员选择 RawResearch 并假设原始数据永不联网,但配置错误的自定义 Sink 接受类 0 |
低 | I1 违规 | RawResearch 的 DropRaw 动作与编译时 sink.rs ACL(MIN_CLASS)冗余;注册表的 allows_sink::<NetworkKind>() 对 Raw 返回 false,提供运行时第二道防线 |
4. 考虑过的替代方案¶
4.1 将 PrivacyClass 扩展为五个以上变体,而不是新增 PrivacyMode¶
将模式合并到类枚举中可以避免第二个类型。被拒绝,因为 PrivacyClass 是线路与 sink 强制原语:其字节值在 BfldFrameHeader 中序列化,并在 sink.rs::check_class、MQTT 路由器和 NVS/Matter 表示中按值分支。两种模式(PrivateHome、EnterpriseAnonymous)共享同一类,但仅在盐域上不同——它们在字节层不可分离,因此不能成为类变体,除非发明现有 frame.rs/sink.rs 代码必须学习的字节语义。模式是严格更高层的,并且不得扰动字节契约。
4.2 每帧证明链¶
每个 CSI 帧一个链链接将证明每一帧。因增长问题被拒绝:20 Hz × 86,400 s = 每节点每天 170 万链接,无界。每窗口粒度(§2.5)以发布事件速率证明每个剥离(每个窗口枚举其每事件记录),该速率低几个数量级,同时不丢失任何剥离证据。
4.3 复用 GateAction 而不是新增 PrivacyAction 枚举¶
GateAction { Accept, PredictOnly, Reject, Recalibrate } 已经存在(identity_risk.rs:57)。被拒绝,因为它回答的是另一个问题——每事件风险门控——并且重载它会混淆“此事件有风险”与“此模式在每个事件上剥离身份”。它们可以组合(模式可以 SuppressIdentity,同时门控独立地 Reject);合并它们会失去这种正交性,并破坏 ADR-140 对独立于每事件风险的稳定 privacy_action 值的需求。
4.4 通过 MQTT 命令主题进行运行时模式变更¶
command_topic 可以让仪表盘实时切换模式。因与 privacy_gate.rs 没有 promote 相同的原因被拒绝:一个远程、默认未认证的 MQTT 写入如果削弱隐私(例如 StrictNoIdentity → RawResearch),就是一个权限提升面。模式是配置时 + 重启决策;诊断实体是只读的。
4.5 SHAKE-256(完全匹配 ADR-010)与 BLAKE3 复用¶
ADR-010 的 MAT 路径使用 SHAKE-256。在此采用它意味着在一个 #![cfg_attr(not(feature = "std"), no_std)] 的 crate 中引入第二个加密依赖(lib.rs:14)。被拒绝:ADR-010 §“哈希链”指定的是哈希链接链,而不是固定算法,并且 BFLD 已经依赖 BLAKE3 用于 rf_signature_hash(signature_hasher.rs:20、Cargo.toml:33)。复用 BLAKE3 可保持 no-std 占用最小,同时满足链接/防篡改契约。
5. 测试与验收标准¶
5.1 测试计划¶
T1 — 模式→类/Soul/盐映射(单元测试)。 对于五个 PrivacyMode 变体中的每一个,断言 privacy_class()、soul_signature_enabled() 和 multiseed_salt() 与 §2.4 表格完全匹配。断言 token() 通过 from_token() 解析器往返。
T2 — 规范动作集(单元测试)。 对于每个模式,断言 actions_for(mode) 等于 §2.4 “强制动作”列,按升序排序(Ord),并且已去重。断言 is_action_enforced 与所有 25 个(模式,动作)对的集合成员资格一致。
T3 — 与 sink.rs 的 ACL 一致性(单元测试)。 对于每个模式,断言 registry.allows_sink::<LocalKind>()、::<NetworkKind>()、::<MatterKind>() 等于 check_class::<S>(mode.privacy_class()).is_ok()——即注册表 ACL 从不与编译时 sink ACL 不一致。特别是 RawResearch.allows_sink::<NetworkKind>() == false(I1)。
T4 — 证明链链接(单元测试)。 封存一个创世链接(prev_hash = [0;32]),然后再封存三个链接,将每个 entry_hash 串联到下一个 prev_hash。断言 verify_link() 对全部四个链接相对于正确的前驱均通过。篡改某个链接的 mode,并断言 verify_link() 失败(篡改证据)。插入/删除/重排一个链接,并断言验证被破坏。
T5 — 记录的剥离字段等于实际门控输出(单元测试)。 运行 BfldEmitter::with_mode(StrictNoIdentity),发出一个本应携带 identity_risk_score + rf_signature_hash 的事件,并断言:(a) 发出的 BfldEvent 中这两个字段均为 None(现有 event.rs:113 行为),并且 (b) 封存的 PrivacyActionRecord.fields_stripped 等于 ["identity_risk_score","rf_signature_hash"](已排序)——证明该证明所证明的是实际被剥离的内容,而不是表格声称的内容。
T6 — 多种子盐隔离(单元测试,复用 ADR-120 AC2)。 在 EnterpriseAnonymous 中,两个使用不同按种子盐的发射器观察相同的身份特征,产生的 rf_signature_hash 值的汉明距离位于 [112, 144] 位(预期约 128 位)。在 PrivateHome 中使用共享节点盐的相同测试不要求实现隔离(记录该差异)。
T7 — 默认模式向后兼容性(单元测试)。 未调用 with_mode() 的 BfldEmitter::new(node_id) 行为与当前完全相同(类为 Anonymous,emitter.rs:82),并且其注册表报告 active_mode() == PrivateHome。
T8 — HA 诊断实体渲染(单元测试)。 render_discovery_payloads() 发出 privacy_mode 诊断传感器,其 entity_category = "diagnostic",没有 command_topic,并且状态 JSON 包含模式令牌、类、short_hash() 以及动作令牌。断言公共感知树(存在/运动等)与变更前输出逐字节相同(对 mqtt_topics.rs:109 无回归)。
T9 — 确定性证明(CI,扩展 ADR-028)。 从硬编码的模式序列封存一个固定的 4 个链接的链,并断言最终 entry_hash 与 archive/v1/data/proof/expected_features.sha256 中键 bfld_attestation_chain_v1 下记录的字节 SHA-256 常量匹配。使证明哈希端到端确定。
5.2 验收标准¶
- AC1:五种模式均解析为 §2.4 中精确的(类、Soul、盐、ACL、动作)元组——T1、T2、T3 通过。
- AC2:证明链具有篡改可检测性:任何单字段变更、插入、删除或重排都会使
verify_link()失败——T4 通过。 - AC3:对于每个发出的事件,
PrivacyActionRecord.fields_stripped等于门控实际清零的字段集合(证明不作伪)——T5 通过。 - AC4:
EnterpriseAnonymous跨种子保持 I3(跨种子汉明距离 ≈ 128 位)——T6 通过。 - AC5:未迁移的
BfldEmitter::new()在可观察行为上与当前完全相同,并且具有已填充的证明链——T7 通过;公共 MQTT 树逐字节相同——T8 通过。 - AC6:
is_action_enforced和strongest_action可被 ADR-139/ADR-140 调用,且无需对注册表进行&mut访问(读取路径为&self)。
5.3 见证 / 证明¶
根据 ADR-028/ADR-010,见证日志中新增三行:
| 行 | 能力 | 证据 |
|---|---|---|
| W-39 | 模式→动作映射是全函数且匹配 §2.4 | cargo test -p wifi-densepose-bfld mode::tests::mapping_table |
| W-40 | 证明链篡改可检测性 | cargo test -p wifi-densepose-bfld attestation::tests::tamper_breaks_chain |
| W-41 | 记录的剥离字段等于实际门控输出 | cargo test -p wifi-densepose-bfld attestation::tests::strips_match_gate |
见证包中的 source-hashes.txt 新增 SHA-256(mode.rs) 和 SHA-256(attestation.rs)。
6. 相关 ADR¶
| ADR | 关系 |
|---|---|
| ADR-010(见证链) | 复用:PrivacyAttestationProof 采用哈希链接链原语(previous_hash/entry_hash);BFLD 根据 §4.5 使用 BLAKE3 而非 SHAKE-256 |
| ADR-118(BFLD) | 扩展:在现有管道之上增加模式/动作/证明层;不变量 I1/I2/I3(lib.rs:8-11)保持不变 |
| ADR-120(隐私类 + 哈希轮换) | 扩展:PrivacyMode 映射到 PrivacyClass;EnterpriseAnonymous 形式化多种子 site_salt 隔离(signature_hasher.rs) |
| ADR-121(身份风险评分) | 组合:PrivacyAction 与 GateAction(identity_risk.rs:57)正交;Soul 门控豁免(coherence_gate.rs:71)由 CareWithConsent 启用 |
| ADR-122(HA/Matter 暴露) | 扩展:在 ha_discovery.rs/mqtt_topics.rs 中新增只读 privacy_mode 诊断实体;公共树保持不变 |
| ADR-136(流式引擎) | 消费者:活动模式令牌可搭载阶段边界帧契约 |
| ADR-139(WorldGraph) | 消费者:is_action_enforced(ReduceResolution/AggregateOnly) 驱动 privacy_limited_by 区域/边标记 |
| ADR-140(语义状态记录) | 消费者:strongest_action 填充 privacy_action;链 entry_hash 是隐私溯源引用 |
| ADR-143(RF SLAM v2) | 约束:反射器/锚点表面在活动模式下受 ReduceResolution/AggregateOnly 约束 |
7. 参考¶
生产代码¶
v2/crates/wifi-densepose-bfld/src/lib.rs—PrivacyClass(:82-117)、BfldError、结构不变量 I1/I2/I3(:8-11)v2/crates/wifi-densepose-bfld/src/sink.rs—Sink::MIN_CLASS、check_class(:47-55)、LocalKind/NetworkKind/MatterKindv2/crates/wifi-densepose-bfld/src/privacy_gate.rs—PrivacyGate::demote清零剥离(:31-75)v2/crates/wifi-densepose-bfld/src/identity_risk.rs—GateAction(:57-69)、风险评分区间v2/crates/wifi-densepose-bfld/src/emitter.rs—BfldEmitter默认类Anonymous(:82)、门控咨询(:171)v2/crates/wifi-densepose-bfld/src/event.rs—BfldEvent字段暴露表、apply_privacy_gating(:112-117)v2/crates/wifi-densepose-bfld/src/coherence_gate.rs—SoulMatchOracle、evaluate_with_oracleRecalibrate 豁免(:71-84)v2/crates/wifi-densepose-bfld/src/signature_hasher.rs— BLAKE3 带密钥rf_signature_hash、I3 站点隔离(:8-18)v2/crates/wifi-densepose-bfld/src/ha_discovery.rs— 类门控的发现渲染(:61-129)v2/crates/wifi-densepose-bfld/src/mqtt_topics.rs— 类门控的主题路由器(:109-157)v2/crates/wifi-densepose-bfld/Cargo.toml— BLAKE3 依赖(:33)、soul-signature特性(:24-27)
相关 ADR 文档¶
docs/adr/ADR-010-witness-chains-audit-trail-integrity.md— 哈希链原语docs/adr/ADR-118-bfld-beamforming-feedback-layer-for-detection.mddocs/adr/ADR-120-bfld-privacy-class-and-hash-rotation.mddocs/adr/ADR-121-bfld-identity-risk-scoring.mddocs/adr/ADR-122-bfld-ruview-ha-matter-exposure.md
实现状态与集成(2026-05-29)¶
属于 ADR-136 流式引擎系列——骨架/脚手架,信任优先,大部分尚未接入实时 20 Hz 路径。系列框架见 ADR-136(实现状态)。
已构建——经过测试的构建块(commit 7d88eb84c,issue #845):PrivacyMode / PrivacyAction / PrivacyModeRegistry,以及基于 BLAKE3 哈希链的 PrivacyAttestationProof(verify_chain() 可检测篡改)。no_std 安全(registry 在 ESP32 路径上受 std 门控)。6 个测试。
集成胶水——尚未接入实时路径: 将 registry 接入 PrivacyGate 类别转换、MQTT 发现负载,以及一个只读 Home Assistant 诊断实体,用于暴露当前模式 + 证明哈希。
信任贡献: 策略脊柱——隐私姿态是一条可检测篡改、可审计的链,而不是一个复选框;操作人员的模式选择主动决定身份数据是否甚至可能存在。
隐私单调性审查(2026-06-14)— 确认干净¶
一次超越 SOTA 的安全审查针对受治理信任周期
(wifi-densepose-engine::StreamingEngine::process_cycle_calibrated)检查了
本 ADR 所治理的隐私降级路径。单调性不变量成立:
降级只会使输出的类别更严格,绝不会更宽松。
验证(无行为变化,结果是一份带证据的清洁报告):
- 每个周期都会从当前模式的
target_class()(下限)重新计算effective_class,并最多应用一次单步降级 (demote_one,在Restricted处钳制)。不存在跨周期状态, 能让宽松类别覆盖严格类别。 - 强制矛盾(校准不匹配 / 阵列几何不足 / mesh 分区风险,ADR-032)会提高类别字节;干净周期恰好输出 基础类别。
- 由
forced_contradiction_never_relaxes_class固定,一个覆盖 全部五个PrivacyMode的属性测试断言effective_class.as_u8() >= base_class.as_u8()(在强制矛盾下,除非已在Restricted处钳制,否则严格大于), 在干净周期下== base。
失败关闭边界也已固定:空周期会报错(没有退化的
过度宽松输出,empty_cycle_fails_closed),单节点边界
被刻画为一种有效的非降级模式(single_node_cycle_is_well_formed)。
同一审查中相关的见证域分离修复记录在
ADR-137 中(见证折叠了 effective_class,因此降级可审计)。
安全与隐私审查(2026-06-14)¶
对 wifi-densepose-bfld 的超越 SOTA 隐私 + 安全审查(该 crate 不在 ADR-154–159 扫描范围内)。修复了两个真实 bug(每个都由一个在旧版本上失败的测试固定),多个维度确认干净。
发现¶
| # | 严重级别 | 位置 | 问题 | 修复 | 固定于 |
|---|---|---|---|---|---|
| 1 | 隐私绕过(HIGH) | pipeline.rs::process_to_frame |
文档中描述的线上字节生产路径将帧头标记为当前 PrivacyClass,但通过 BfldFrame::from_payload 将调用方的 BfldPayload 原样序列化——从未经过 PrivacyGate::demote。标记为 Anonymous(2)/Restricted(3) 的帧携带完整的 compressed_angle_matrix(身份表面)+ 幅度/相位 + csi_delta。NetworkSink 接受类别 ≥ Derived(1),因此身份表面可能越过节点边界,尽管类别字节是严格的——该字节对内容撒谎。 |
在构建后应用 PrivacyGate::demote(frame, active_class):一种同类别转换,剥离该类别禁止的区段;Raw/Derived 保留完整负载。 |
tests/pipeline_to_frame.rs::process_to_frame_at_anonymous_strips_identity_leaky_sections、…_in_privacy_mode_strips_amplitude_and_phase(修复前均 FAILED);…_at_derived_preserves_full_payload(过度剥离防护) |
| 2 | PII/注入(MEDIUM) | mqtt_topics.rs::render_events |
zone_activity 负载构建为 format!("\"{zone}\""),没有 JSON 转义(而 ha_discovery.rs 已经转义)。包含 "/\ 的区域名称会在 HA 状态主题上产生格式错误/可注入的 JSON。 |
json_string_literal() 转义器,镜像 ha_discovery::push_str_field。对正常区域名称值相同。 |
tests/mqtt_topic_routing.rs::zone_payload_escapes_json_metacharacters(修复前 FAILED) |
确认干净的维度(带证据)¶
- 事件字段隐私门控 —
BfldEvent::apply_privacy_gating在Restricted时将identity_risk_score+rf_signature_hash置空,并且serde(skip_serializing_if = "Option::is_none")完全省略它们。render_events/render_discovery_payloads拒绝类别 <Anonymous(比sink.rs中NetworkKind的MIN_CLASS = Derived更严格——面向更少泄漏的纵深防御)。由event_privacy_gating.rs、mqtt_topic_routing.rs、ha_discovery.rs覆盖。 - 见证/哈希框架(引擎
witness_ofbug 类别) — 干净。SignatureHasher::compute前缀一个固定 4 字节day_epoch,然后是一个固定宽度 canonical-f32 特征块(IdentityFeatures:Embedding =EMBEDDING_DIM*4,RiskFactors = 16 B)。PrivacyAttestationProof::compute哈希一个固定 32 字节prev_hash+ 三个固定 1 字节值。任何可变长度、操作员可影响的字符串都不会被拼接到任何摘要中——不可能发生长度前缀框架碰撞。 - 失败关闭 —
payload.rs::from_bytes拒绝截断/溢出/尾字节区段(checked_add、边界检查);frame.rs::from_bytes验证 magic/version/length/CRC;PrivacyClass::try_from拒绝未知字节;identity_risk::score将 NaN/退化因子映射到 0.0(隐私保守)。from_score(NaN) → Accept的选择是有文档记录的、刻意的仅发布聚合回退(NaN 从score()永远不会到达它);风险驱动的 NaN 不会泄漏身份,因为身份门控由类别字节驱动,而不是风险驱动。
观察(非缺陷)¶
ADR-141 控制平面(PrivacyMode/PrivacyModeRegistry)尚未接入输出路径 —— 发射器/流水线直接强制原始 PrivacyClass;注册表已导出并经过单元测试,但仅供参考。这与上述“集成胶水 — 尚未接入实时路径”状态一致。类字节强制(发射器 + 事件 + 渲染器 + 现已修复的 process_to_frame)是实时保证。接入注册表是文档中记录的下一步。
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 wi/RuView