dpapi-ng 0.1.0

Pure-Rust DPAPI-NG (CNG group protection) and MS-GKDI key derivation — decrypt Windows LAPS, gMSA and dMSA password blobs without a Windows host.
Documentation

dpapi-ng

crates.io docs.rs

DPAPI-NG (CNG "group protection") and MS-GKDI key derivation, in pure Rust. No FFI, no Windows host, no bcrypt.dll.

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 that lives on the domain controllers. The blob carries no key — only a key identifier: 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) and derives downwards.

This crate does everything except the RPC call.

use dpapi_ng::{decrypt, laps_password_from_json, LapsBlob};
use dpapi_ng::gkdi::GroupKeyEnvelope;

// 1. Split the LAPS attribute and parse the CMS blob.
let laps = LapsBlob::parse(&attr_value)?;
let blob = laps.protected()?;

// 2. Ask a DC for the node named in blob.key_identifier (your DCE/RPC, not ours).
let envelope = GroupKeyEnvelope::parse(&get_key_response)?;

// 3. Derive down the tree and open the content.
let plaintext = decrypt(&blob, &envelope)?;
println!("{:?}", laps_password_from_json(&plaintext));

What is in here

  • gkdi::KeyIdentifier — which root key and tree node a blob was protected for.
  • gkdi::GroupKeyEnvelope — what GetKey returns.
  • gkdi::compute_l2_key — the L0/L1/L2 tree walk. Pure computation, no network.
  • kdf — the SP800-108 counter-mode KDF over SHA-1/256/384/512.
  • cms::ProtectedBlob — the CMS EnvelopedData, its KEKRecipientInfo and the AES-GCM content parameters, on a small hand-written DER reader rather than a codegen'd ASN.1 stack.
  • LapsBlob + laps_password_from_json — the Windows LAPS attribute header and its UTF-16LE JSON payload.

Transport is deliberately out of scope

GetKey is one MS-GKDI RPC call over \pipe\lsass with authentication and sealing, and every project that needs this already has a DCE/RPC stack. Make the call, hand the response bytes to GroupKeyEnvelope::parse, and keep this crate free of a transport dependency.

Status

The structures, the KDF, the tree walk and the CMS path are covered by tests, including an end-to-end build-then-decrypt of a real EnvelopedData (AES key-wrap plus AES-256-GCM).

One detail is still pinned down against live data rather than by specification: Windows has used more than one KEK derivation from the L2 seed key across versions, so decrypt_with_seed_key tries the known candidates in order. This is safe rather than sloppy — AES key-wrap and AES-GCM are both authenticated, so a wrong KEK fails loudly instead of producing plausible garbage. If you know the derivation your environment uses, call decrypt_with_kek directly.

License

MIT