From a2f948d53fc22c3d6dd724adfee8ceb685179784 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 9 Apr 2019 04:51:56 -0400 Subject: use http response codes --- src/bin/timing_attack.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bin/timing_attack.rs b/src/bin/timing_attack.rs index ffcfac9..ac9c895 100644 --- a/src/bin/timing_attack.rs +++ b/src/bin/timing_attack.rs @@ -28,15 +28,19 @@ fn insecure_compare(a: &[u8], b: &[u8]) -> bool { true } -fn index(info: actix_web::Query, key: &[u8]) -> String { +fn index( + info: actix_web::Query, + key: &[u8], +) -> actix_web::Result { let hmac = matasano::sha1_hmac(&info.file.clone().into_bytes(), key); + println!("hmac for {} is {}", info.file, hex::encode(hmac)); if insecure_compare( &hex::decode(info.signature.clone()).unwrap(), &hmac[..], ) { - "true".to_string() + Ok("ok".to_string()) } else { - "false".to_string() + Err(actix_web::error::ErrorBadRequest("hmac failed")) } } @@ -50,7 +54,7 @@ fn main() { let key = key.clone(); actix_web::App::new().resource("/", |r| { r.method(actix_web::http::Method::GET) - .with(move |info: actix_web::Query| index(info, &key)) + .with(move |info| index(info, &key)) }) }) .bind("127.0.0.1:9000") -- cgit v1.2.3-54-g00ecf