Skip to main content

Crate dpapi_ng

Crate dpapi_ng 

Source
Expand description

DPAPI-NG (CNG “group protection”) and MS-GKDI, in pure Rust.

Windows LAPS (msLAPS-EncryptedPassword), gMSA and dMSA managed passwords are all protected the same way: a CMS EnvelopedData whose content key is wrapped under a KEK derived from a KDS root key held by the domain controllers. The blob itself carries no key — only a gkdi::KeyIdentifier saying which root key and which node of its L0/L1/L2 tree. A principal allowed to read the secret asks a DC for that node (GetKey over MS-GKDI), then derives downwards.

The full pipeline:

  1. LapsBlob::parse / cms::ProtectedBlob::parse — unwrap the CMS, recover the key identifier.
  2. Fetch the envelope from a DC: either [rpc::get_key] (feature rpc) or hand the reply bytes to gkdi::GroupKeyEnvelope::parse yourself.
  3. gkdi::compute_l2_key — walk the tree down to the exact node. Pure computation.
  4. cms::ProtectedBlob + decrypt_with_seed_key — unwrap the content key and open the AES-GCM content.

Without the rpc feature the crate is pure computation (no dcerpc/tokio dep): bring your own transport and feed the GetKey reply bytes to GroupKeyEnvelope::parse.

Modules§

cms
The CMS EnvelopedData wrapper a DPAPI-NG blob is packaged in.
der
Just enough DER to walk a CMS EnvelopedData. No schema, no codegen — a tag/length/value reader with bounds checks, because the only ASN.1 this crate meets is one known shape.
gkdi
MS-GKDI: the Group Key Distribution structures and the L0/L1/L2 key-tree walk.
kdf
SP800-108 counter-mode KDF — the one MS-GKDI uses to walk the key tree.

Structs§

LapsBlob
The header Windows LAPS puts in front of the DPAPI-NG blob in msLAPS-EncryptedPassword: an update timestamp and the blob length.

Enums§

DpapiError

Functions§

decrypt
The whole path in one call: a blob plus the GetKey envelope that covers it.
decrypt_content
Open the AES-256-GCM content with an already-unwrapped content-encryption key.
decrypt_with_kek
Decrypt a blob with a known key-encryption key: AES key-unwrap the content key, then open the AES-256-GCM content.
decrypt_with_seed_key
Decrypt a blob given the L2 seed key for its node.
laps_password_from_json
Windows LAPS stores the decrypted password as UTF-16LE JSON: {"n":"<account>","t":"<hex time>","p":"<password>"}. Pull the password out without pulling in a JSON dependency.

Type Aliases§

Result