Skip to main content

KeyIdentifier

Struct KeyIdentifier 

Source
pub struct KeyIdentifier {
Show 14 fields pub version: u32, pub flags: u32, pub l0: i32, pub l1: i32, pub l2: i32, pub root_key_id: RootKeyId, pub kdf_algorithm: String, pub kdf_parameters: Vec<u8>, pub secret_algorithm: String, pub secret_parameters: Vec<u8>, pub private_key_length: u32, pub public_key_length: u32, pub domain_name: String, pub forest_name: String,
}
Expand description

The KEY_IDENTIFIER carried in a protected blob: which root key and which tree node the content was encrypted for.

Fields§

§version: u32§flags: u32§l0: i32§l1: i32§l2: i32§root_key_id: RootKeyId§kdf_algorithm: String§kdf_parameters: Vec<u8>§secret_algorithm: String§secret_parameters: Vec<u8>§private_key_length: u32§public_key_length: u32§domain_name: String§forest_name: String

Implementations§

Source§

impl KeyIdentifier

Source

pub fn is_public_key(&self) -> bool

true when the blob was protected with the public-key half of the node (the key-agreement path) rather than the seed key directly.

Examples found in repository?
examples/inspect_blob.rs (line 63)
16fn main() -> ExitCode {
17    let args: Vec<String> = std::env::args().skip(1).collect();
18    let raw_mode = args.iter().any(|a| a == "--raw");
19    let Some(path) = args.iter().find(|a| !a.starts_with("--")) else {
20        eprintln!("usage: inspect_blob [--raw] <blob.bin>");
21        return ExitCode::FAILURE;
22    };
23
24    let bytes = match std::fs::read(path) {
25        Ok(b) => b,
26        Err(e) => {
27            eprintln!("cannot read {path}: {e}");
28            return ExitCode::FAILURE;
29        }
30    };
31
32    let blob_bytes = if raw_mode {
33        bytes
34    } else {
35        match LapsBlob::parse(&bytes) {
36            Ok(l) => {
37                println!(
38                    "LAPS header: updated {} (FILETIME {}), {} byte blob",
39                    filetime_to_iso(l.update_timestamp),
40                    l.update_timestamp,
41                    l.blob.len()
42                );
43                l.blob
44            }
45            Err(e) => {
46                eprintln!("not a LAPS attribute value ({e}); retry with --raw if this is a bare CMS blob");
47                return ExitCode::FAILURE;
48            }
49        }
50    };
51
52    let blob = match ProtectedBlob::parse(&blob_bytes) {
53        Ok(b) => b,
54        Err(e) => {
55            eprintln!("CMS parse failed: {e}");
56            return ExitCode::FAILURE;
57        }
58    };
59
60    let id = &blob.key_identifier;
61    println!("key identifier");
62    println!("  version            {}", id.version);
63    println!("  flags              {:#010x}{}", id.flags, if id.is_public_key() { " (public key)" } else { "" });
64    println!("  root key           {}", id.root_key_id);
65    println!("  tree node          L0 {} · L1 {} · L2 {}", id.l0, id.l1, id.l2);
66    println!("  kdf                {} ", id.kdf_algorithm);
67    match id.hash() {
68        Ok(h) => println!("  kdf hash           {}", h.name()),
69        Err(e) => println!("  kdf hash           UNPARSED: {e}"),
70    }
71    println!("  secret algorithm   {}", id.secret_algorithm);
72    println!("  private/public len {} / {}", id.private_key_length, id.public_key_length);
73    println!("  domain / forest    {} / {}", id.domain_name, id.forest_name);
74    println!("content");
75    println!("  key wrap           {}", blob.key_wrap_oid);
76    println!("  content cipher     {}", blob.content_cipher_oid);
77    println!("  nonce              {} ({} bytes)", hex(&blob.nonce), blob.nonce.len());
78    println!("  tag length         {}", blob.tag_len);
79    println!("  wrapped key        {} bytes", blob.encrypted_key.len());
80    println!("  ciphertext         {} bytes", blob.encrypted_content.len());
81    println!(
82        "\nTo decrypt: ask a DC for root key {} at L0 {} (MS-GKDI GetKey), then\n\
83         GroupKeyEnvelope::parse(response) and dpapi_ng::decrypt(&blob, &envelope).",
84        id.root_key_id, id.l0
85    );
86
87    ExitCode::SUCCESS
88}
Source

pub fn parse(b: &[u8]) -> Result<KeyIdentifier>

Source

pub fn to_bytes(&self) -> Vec<u8> ⓘ

Source

pub fn hash(&self) -> Result<HashAlg>

The hash the key tree for this blob is derived with.

Examples found in repository?
examples/inspect_blob.rs (line 67)
16fn main() -> ExitCode {
17    let args: Vec<String> = std::env::args().skip(1).collect();
18    let raw_mode = args.iter().any(|a| a == "--raw");
19    let Some(path) = args.iter().find(|a| !a.starts_with("--")) else {
20        eprintln!("usage: inspect_blob [--raw] <blob.bin>");
21        return ExitCode::FAILURE;
22    };
23
24    let bytes = match std::fs::read(path) {
25        Ok(b) => b,
26        Err(e) => {
27            eprintln!("cannot read {path}: {e}");
28            return ExitCode::FAILURE;
29        }
30    };
31
32    let blob_bytes = if raw_mode {
33        bytes
34    } else {
35        match LapsBlob::parse(&bytes) {
36            Ok(l) => {
37                println!(
38                    "LAPS header: updated {} (FILETIME {}), {} byte blob",
39                    filetime_to_iso(l.update_timestamp),
40                    l.update_timestamp,
41                    l.blob.len()
42                );
43                l.blob
44            }
45            Err(e) => {
46                eprintln!("not a LAPS attribute value ({e}); retry with --raw if this is a bare CMS blob");
47                return ExitCode::FAILURE;
48            }
49        }
50    };
51
52    let blob = match ProtectedBlob::parse(&blob_bytes) {
53        Ok(b) => b,
54        Err(e) => {
55            eprintln!("CMS parse failed: {e}");
56            return ExitCode::FAILURE;
57        }
58    };
59
60    let id = &blob.key_identifier;
61    println!("key identifier");
62    println!("  version            {}", id.version);
63    println!("  flags              {:#010x}{}", id.flags, if id.is_public_key() { " (public key)" } else { "" });
64    println!("  root key           {}", id.root_key_id);
65    println!("  tree node          L0 {} · L1 {} · L2 {}", id.l0, id.l1, id.l2);
66    println!("  kdf                {} ", id.kdf_algorithm);
67    match id.hash() {
68        Ok(h) => println!("  kdf hash           {}", h.name()),
69        Err(e) => println!("  kdf hash           UNPARSED: {e}"),
70    }
71    println!("  secret algorithm   {}", id.secret_algorithm);
72    println!("  private/public len {} / {}", id.private_key_length, id.public_key_length);
73    println!("  domain / forest    {} / {}", id.domain_name, id.forest_name);
74    println!("content");
75    println!("  key wrap           {}", blob.key_wrap_oid);
76    println!("  content cipher     {}", blob.content_cipher_oid);
77    println!("  nonce              {} ({} bytes)", hex(&blob.nonce), blob.nonce.len());
78    println!("  tag length         {}", blob.tag_len);
79    println!("  wrapped key        {} bytes", blob.encrypted_key.len());
80    println!("  ciphertext         {} bytes", blob.encrypted_content.len());
81    println!(
82        "\nTo decrypt: ask a DC for root key {} at L0 {} (MS-GKDI GetKey), then\n\
83         GroupKeyEnvelope::parse(response) and dpapi_ng::decrypt(&blob, &envelope).",
84        id.root_key_id, id.l0
85    );
86
87    ExitCode::SUCCESS
88}

Trait Implementations§

Source§

impl Clone for KeyIdentifier

Source§

fn clone(&self) -> KeyIdentifier

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyIdentifier

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for KeyIdentifier

Source§

impl PartialEq for KeyIdentifier

Source§

fn eq(&self, other: &KeyIdentifier) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KeyIdentifier

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.