Skip to content

Commit 592d4c5

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 c006e36 commit 592d4c5

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
@@ -182,7 +182,8 @@ impl RpcHandler {
182182

183183
fn ensure_admin(&self, token: &str) -> Result<()> {
184184
let token_hash = sha2::Sha256::new_with_prefix(token).finalize();
185-
if token_hash.as_slice() != self.state.config.admin_token_hash.as_slice() {
185+
use subtle::ConstantTimeEq;
186+
if !bool::from(token_hash.as_slice().ct_eq(self.state.config.admin_token_hash.as_slice())) {
186187
bail!("Invalid token");
187188
}
188189
Ok(())

0 commit comments

Comments
 (0)