Skip to content

Commit 12ce98b

Browse files
committed
kms: use constant-time comparison for admin token verification
Replace timing-vulnerable `!=` with `subtle::ConstantTimeEq` to prevent timing side-channel attacks on admin token hash comparison.
1 parent 00d3a9f commit 12ce98b

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kms/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ load_config.workspace = true
3131
serde-human-bytes.workspace = true
3232
reqwest = { workspace = true, features = ["json"] }
3333
sha2.workspace = true
34+
subtle = "2"
3435
sha3.workspace = true
3536
k256.workspace = true
3637
rand.workspace = true

kms/src/main_service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ impl RpcHandler {
138138

139139
fn ensure_admin(&self, token: &str) -> Result<()> {
140140
let token_hash = sha2::Sha256::new_with_prefix(token).finalize();
141-
if token_hash.as_slice() != self.state.config.admin_token_hash.as_slice() {
141+
use subtle::ConstantTimeEq;
142+
if !bool::from(token_hash.as_slice().ct_eq(self.state.config.admin_token_hash.as_slice())) {
142143
bail!("Invalid token");
143144
}
144145
Ok(())

0 commit comments

Comments
 (0)