MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / validate_break_glass

Method validate_break_glass

nodedb/src/control/security/emergency.rs:104–124  ·  view source on GitHub ↗

Validate break-glass key from file. Returns `true` if the provided key matches the key in the configured file. Used for emergency access when normal auth is unavailable.

(&self, provided_key: &str)

Source from the content-addressed store, hash-verified

102 /// Returns `true` if the provided key matches the key in the configured file.
103 /// Used for emergency access when normal auth is unavailable.
104 pub fn validate_break_glass(&self, provided_key: &str) -> bool {
105 let Some(ref path) = self.break_glass_key_path else {
106 return false;
107 };
108 let Ok(stored_key) = std::fs::read_to_string(path) else {
109 warn!(path = %path, "break-glass key file not readable");
110 return false;
111 };
112 let stored_trimmed = stored_key.trim();
113 if stored_trimmed.is_empty() {
114 return false;
115 }
116 // Constant-time comparison.
117 provided_key.len() == stored_trimmed.len()
118 && provided_key
119 .as_bytes()
120 .iter()
121 .zip(stored_trimmed.as_bytes())
122 .fold(0u8, |acc, (a, b)| acc | (a ^ b))
123 == 0
124 }
125
126 /// Check if an operation requires two-party authorization.
127 pub fn requires_two_party(&self, operation: &str) -> bool {

Callers

nothing calls this directly

Calls 5

foldMethod · 0.80
is_emptyMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected