跳转至

ADR-010: 审计跟踪完整性的见证链

状态

提议中

日期

2026-02-28

背景

生命攸关的审计要求

wifi-densepose-mat 灾害检测模块(ADR-001)会做出直接影响救援优先级的分诊分类:

分诊级别 操作 错误后果
P1 (立即/红色) 立即救援 漏报 → 幸存者等待中死亡
P2 (延迟/黄色) 1 小时内救援 误分类 → 救援延迟
P3 (轻微/绿色) 资源允许时救援 过度分诊 → 资源浪费
P4 (死亡/黑色) 不尝试救援 错误 P4 → 生者被遗弃

事后调查、责任程序和运营审查要求:

  1. 不可抵赖性:证明哪个设备在何时做出了哪个检测
  2. 篡改证据:检测记录是否事后被篡改
  3. 完整性:证明没有检测被删除或隐藏
  4. 因果链:重建导致每个分诊决策的事件序列
  5. 跨设备验证:跨多个 AP 相互印证检测结果

当前状态

检测结果通过标准 INSERT 操作记录到数据库(wifi-densepose-db)。日志可能被: - 事后被静默修改 - 被无痕删除 - 被回溯日期或重新排序 - 在数据库损坏时丢失

不存在任何密码学完整性机制。

RuVector 见证链

RuVector 实现了受区块链启发但无需共识开销的哈希链接审计跟踪:

  • 哈希链:每个条目包含前一个条目的 SHAKE-256 哈希,形成可篡改检测链
  • 签名:链锚点(每第 N 个条目)使用设备密钥对签名
  • 跨链证明:多个设备可以交叉引用彼此的链
  • 紧凑:每个链条目约 100-200 字节(哈希 + 元数据 + 签名引用)

决策

我们将实现 RuVector 见证链,作为 WiFi-DensePose 系统中所有检测事件、分诊决策和模型适配事件的主要审计机制。

见证链结构

┌────────────────────────────────────────────────────────────────────┐
│                      Witness Chain                                  │
├────────────────────────────────────────────────────────────────────┤
│                                                                     │
│  Entry 0          Entry 1          Entry 2          Entry 3        │
│  (Genesis)                                                          │
│  ┌──────────┐    ┌──────────┐    ┌──────────┐    ┌──────────┐     │
│  │ prev: ∅  │◀───│ prev: H0 │◀───│ prev: H1 │◀───│ prev: H2 │     │
│  │ event:   │    │ event:   │    │ event:   │    │ event:   │     │
│  │  INIT    │    │  DETECT  │    │  TRIAGE  │    │  ADAPT   │     │
│  │ hash: H0 │    │ hash: H1 │    │ hash: H2 │    │ hash: H3 │     │
│  │ sig: S0  │    │          │    │          │    │ sig: S1  │     │
│  │ (anchor) │    │          │    │          │    │ (anchor) │     │
│  └──────────┘    └──────────┘    └──────────┘    └──────────┘     │
│                                                                     │
│  H0 = SHAKE-256(INIT || device_id || timestamp)                    │
│  H1 = SHAKE-256(DETECT_DATA || H0 || timestamp)                   │
│  H2 = SHAKE-256(TRIAGE_DATA || H1 || timestamp)                   │
│  H3 = SHAKE-256(ADAPT_DATA || H2 || timestamp)                    │
│                                                                     │
│  Anchor signature S0 = ML-DSA-65.sign(H0, device_key)             │
│  Anchor signature S1 = ML-DSA-65.sign(H3, device_key)             │
│  Anchor interval: every 100 entries (configurable)                 │
└────────────────────────────────────────────────────────────────────┘

被见证事件类型

/// Events recorded in the witness chain
#[derive(Serialize, Deserialize, Clone)]
pub enum WitnessedEvent {
    /// Chain initialization (genesis)
    ChainInit {
        device_id: DeviceId,
        firmware_version: String,
        config_hash: [u8; 32],
    },

    /// Human presence detected
    HumanDetected {
        detection_id: Uuid,
        confidence: f64,
        csi_features_hash: [u8; 32],  // Hash of input data, not raw data
        location_estimate: Option<GeoCoord>,
        model_version: String,
    },

    /// Triage classification assigned or changed
    TriageDecision {
        survivor_id: Uuid,
        previous_level: Option<TriageLevel>,
        new_level: TriageLevel,
        evidence_hash: [u8; 32],  // Hash of supporting evidence
        deciding_algorithm: String,
        confidence: f64,
    },

    /// False detection corrected
    DetectionCorrected {
        detection_id: Uuid,
        correction_type: CorrectionType,  // FalsePositive | FalseNegative | Reclassified
        reason: String,
        corrected_by: CorrectorId,  // Device or operator
    },

    /// Model adapted via SONA
    ModelAdapted {
        adaptation_id: Uuid,
        trigger: AdaptationTrigger,
        lora_delta_hash: [u8; 32],
        performance_before: f64,
        performance_after: f64,
    },

    /// Zone scan completed
    ZoneScanCompleted {
        zone_id: ZoneId,
        scan_duration_ms: u64,
        detections_count: usize,
        coverage_percentage: f64,
    },

    /// Cross-device attestation received
    CrossAttestation {
        attesting_device: DeviceId,
        attested_chain_hash: [u8; 32],
        attested_entry_index: u64,
    },

    /// Operator action (manual override)
    OperatorAction {
        operator_id: String,
        action: OperatorActionType,
        target: Uuid,  // What was acted upon
        justification: String,
    },
}

链条目结构

/// A single entry in the witness chain
#[derive(Serialize, Deserialize)]
pub struct WitnessEntry {
    /// Sequential index in the chain
    index: u64,

    /// SHAKE-256 hash of the previous entry (32 bytes)
    previous_hash: [u8; 32],

    /// The witnessed event
    event: WitnessedEvent,

    /// Device that created this entry
    device_id: DeviceId,

    /// Monotonic timestamp (device-local, not wall clock)
    monotonic_timestamp: u64,

    /// Wall clock timestamp (best-effort, may be inaccurate)
    wall_timestamp: DateTime<Utc>,

    /// Vector clock for causal ordering (see ADR-008)
    vector_clock: VectorClock,

    /// This entry's hash: SHAKE-256(serialize(self without this field))
    entry_hash: [u8; 32],

    /// Anchor signature (present every N entries)
    anchor_signature: Option<HybridSignature>,
}

篡改检测

/// Verify witness chain integrity
pub fn verify_chain(chain: &[WitnessEntry]) -> Result<ChainVerification, AuditError> {
    let mut verification = ChainVerification::new();

    for (i, entry) in chain.iter().enumerate() {
        // 1. Verify hash chain linkage
        if i > 0 {
            let expected_prev_hash = chain[i - 1].entry_hash;
            if entry.previous_hash != expected_prev_hash {
                verification.add_violation(ChainViolation::BrokenLink {
                    entry_index: entry.index,
                    expected_hash: expected_prev_hash,
                    actual_hash: entry.previous_hash,
                });
            }
        }

        // 2. Verify entry self-hash
        let computed_hash = compute_entry_hash(entry);
        if computed_hash != entry.entry_hash {
            verification.add_violation(ChainViolation::TamperedEntry {
                entry_index: entry.index,
            });
        }

        // 3. Verify anchor signatures
        if let Some(ref sig) = entry.anchor_signature {
            let device_keys = load_device_keys(&entry.device_id)?;
            if !sig.verify(&entry.entry_hash, &device_keys.ed25519, &device_keys.ml_dsa)? {
                verification.add_violation(ChainViolation::InvalidSignature {
                    entry_index: entry.index,
                });
            }
        }

        // 4. Verify monotonic timestamp ordering
        if i > 0 && entry.monotonic_timestamp <= chain[i - 1].monotonic_timestamp {
            verification.add_violation(ChainViolation::NonMonotonicTimestamp {
                entry_index: entry.index,
            });
        }

        verification.verified_entries += 1;
    }

    Ok(verification)
}

跨设备证明

多个 AP 可以相互交叉引用彼此的链,以获得更强的保证:

Device A's chain:                    Device B's chain:
┌──────────┐                         ┌──────────┐
│ Entry 50 │                         │ Entry 73 │
│ H_A50    │◀────── cross-attest ───▶│ H_B73    │
└──────────┘                         └──────────┘

Device A records: CrossAttestation { attesting: B, hash: H_B73, index: 73 }
Device B records: CrossAttestation { attesting: A, hash: H_A50, index: 50 }

After cross-attestation:
- Neither device can rewrite entries before the attested point
  without the other device's chain becoming inconsistent
- An investigator can verify both chains agree on the attestation point

证明频率:在连接运行期间每 5 分钟一次,并在重大事件(P1 分诊、区域完成)时立即执行。

存储与检索

见证链存储在 RVF 容器的 WITNESS 段中:

/// Witness chain storage manager
pub struct WitnessChainStore {
    /// Current chain being appended to
    active_chain: Vec<WitnessEntry>,

    /// Anchor signature interval
    anchor_interval: usize,  // 100

    /// Device signing key
    device_key: DeviceKeyPair,

    /// Cross-attestation peers
    attestation_peers: Vec<DeviceId>,

    /// RVF container for persistence
    container: RvfContainer,
}

impl WitnessChainStore {
    /// Append an event to the chain
    pub fn witness(&mut self, event: WitnessedEvent) -> Result<u64, AuditError> {
        let index = self.active_chain.len() as u64;
        let previous_hash = self.active_chain.last()
            .map(|e| e.entry_hash)
            .unwrap_or([0u8; 32]);

        let mut entry = WitnessEntry {
            index,
            previous_hash,
            event,
            device_id: self.device_key.device_id(),
            monotonic_timestamp: monotonic_now(),
            wall_timestamp: Utc::now(),
            vector_clock: self.get_current_vclock(),
            entry_hash: [0u8; 32],  // Computed below
            anchor_signature: None,
        };

        // Compute entry hash
        entry.entry_hash = compute_entry_hash(&entry);

        // Add anchor signature at interval
        if index % self.anchor_interval as u64 == 0 {
            entry.anchor_signature = Some(
                self.device_key.sign_hybrid(&entry.entry_hash)?
            );
        }

        self.active_chain.push(entry);

        // Persist to RVF container
        self.container.append_witness(&self.active_chain.last().unwrap())?;

        Ok(index)
    }

    /// Query chain for events in a time range
    pub fn query_range(&self, start: DateTime<Utc>, end: DateTime<Utc>)
        -> Vec<&WitnessEntry>
    {
        self.active_chain.iter()
            .filter(|e| e.wall_timestamp >= start && e.wall_timestamp <= end)
            .collect()
    }

    /// Export chain for external audit
    pub fn export_for_audit(&self) -> AuditBundle {
        AuditBundle {
            chain: self.active_chain.clone(),
            device_public_key: self.device_key.public_keys(),
            cross_attestations: self.collect_cross_attestations(),
            chain_summary: self.compute_summary(),
        }
    }
}

性能影响

操作 延迟 说明
追加条目 0.05 ms 哈希计算 + 序列化
带锚定签名的追加 0.5 ms + ML-DSA-65 签名
验证单个条目 0.02 ms 哈希比较
验证锚点 0.3 ms ML-DSA-65 验证
完整链验证(10K 条目) 50 ms 顺序哈希验证
交叉证明 1 ms 签名 + 网络往返

存储需求

链长度 每小时条目数 每小时大小 每天大小
低活动 ~100 ~20 KB ~480 KB
正常运行 ~1,000 ~200 KB ~4.8 MB
灾难响应 ~10,000 ~2 MB ~48 MB
高强度扫描 ~50,000 ~10 MB ~240 MB

后果

正面影响

  • 防篡改:对历史记录的任何修改都可检测
  • 不可否认:签名锚点可证明设备身份
  • 完整历史:每次检测、分诊和更正都会被记录
  • 交叉验证:多设备证明可增强保证
  • 取证可靠:可导出用于法律程序的审计包
  • 低开销:每个条目 0.05ms;正常运行时存储开销极小

负面

  • 仅追加增长:链单调增长;长期部署需要归档策略
  • 密钥管理:设备密钥必须被配置和保护
  • 时钟依赖:墙钟时间戳为尽力而为;单调时间戳为设备本地
  • 验证成本:长链的完整链验证需要可观时间(50ms/10K 条目)
  • 隐私张力:详细审计轨迹包含运营情报

监管合规

要求 Witness Chains 如何满足该要求
GDPR(删除权) 存储事件哈希而非个人数据;原始数据可删除,同时链可证明历史完整性
HIPAA(审计控制) 完整的访问/修改日志,具备不可否认性
ISO 27001(信息安全) 防篡改记录、访问日志、完整性验证
NIST SP 800-53(AU 控制) 审计记录生成、保护与审查能力
FEMA ICS(事件指挥) 所有操作决策的保管链

参考资料

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 wi/RuView