Skip to main content

ms_gkdi/
lib.rs

1//! MS-GKDI — Group Key Distribution.
2//!
3//! Extracted from `dpapi-ng` so the tree walk, KDF, and `ISDKey` RPC caller can be reused
4//! without pulling in the DPAPI-NG CMS layer. The three public modules are:
5//!
6//! * [`gkdi`] — `KEY_IDENTIFIER` / `GROUP_KEY_ENVELOPE` parsers and the L0/L1/L2 walk.
7//! * [`kdf`]  — SP800-108 counter-mode KDF and the `"KDS service"` label.
8//! * [`rpc`]  — `ISDKey::GetKey` over sealed ncacn_ip_tcp (via the `dcerpc` crate).
9//!
10//! **UNVALIDATED CRYPTO — DO NOT PUBLISH.** See `README.md`: this 0.1.0-dev tag is local
11//! only. The derivation has not been cross-checked against a live Server 2022 DC or against
12//! Microsoft's reference `dpapi-ng.py`. Ship after the KAT harness lands.
13
14pub mod gkdi;
15pub mod kdf;
16pub mod rpc;
17
18mod cursor;
19
20/// Errors surfaced by the parsers and the tree walk. Kept as a plain enum so callers can
21/// `match` on the specific failure without stringly inspecting a message.
22#[derive(Debug, thiserror::Error, PartialEq, Eq)]
23pub enum GkdiError {
24    #[error("truncated: {0}")]
25    Truncated(&'static str),
26    #[error("bad {what} magic: {got:#010x}")]
27    BadMagic { what: &'static str, got: u32 },
28    #[error("unsupported algorithm: {0}")]
29    UnsupportedAlgorithm(String),
30    #[error("the envelope carries a public key, not seed keys — ask the DC for the private half")]
31    PublicKeyEnvelope,
32    #[error("the envelope has no {0} seed key")]
33    MissingSeedKey(&'static str),
34    #[error("tree index out of range: l1={l1} l2={l2}")]
35    BadTreeIndex { l1: i32, l2: i32 },
36}
37
38pub type Result<T> = std::result::Result<T, GkdiError>;