summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-04-10 04:22:20 -0400
committerJesse Luehrs <doy@tozt.net>2019-04-10 04:27:40 -0400
commit47f666beb8c88408af55bf832fe507f959d34374 (patch)
tree8303cec3d09f153dc80d9a51f30ee48969fd0b62 /tests
parent36d1c3b7d72496600edeabdc50d2cd96f7b1f703 (diff)
downloadmatasano-47f666beb8c88408af55bf832fe507f959d34374.tar.gz
matasano-47f666beb8c88408af55bf832fe507f959d34374.zip
problem 31
Diffstat (limited to 'tests')
-rw-r--r--tests/set4.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/set4.rs b/tests/set4.rs
index c0c06e3..ebcbd76 100644
--- a/tests/set4.rs
+++ b/tests/set4.rs
@@ -1,4 +1,5 @@
use rand::Rng;
+use std::io::Read;
mod util;
@@ -184,3 +185,48 @@ fn problem_30() {
== &mac[..]
));
}
+
+#[test]
+#[ignore]
+fn problem_31() {
+ let exe_path = std::env::current_exe().unwrap();
+ let exe_dir = exe_path.parent().unwrap().parent().unwrap();
+ let server_bin = exe_dir.join("timing_attack");
+
+ let (ready_w, ready_r) = std::sync::mpsc::channel();
+ let (kill_w, kill_r) = std::sync::mpsc::channel();
+ std::thread::spawn(move || {
+ let mut child = std::process::Command::new(server_bin)
+ .stdout(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+ let mut key = [0u8; 32];
+ let _ = child.stdout.as_mut().unwrap().read_exact(&mut key);
+ ready_w.send(key).unwrap();
+
+ let _ = kill_r.recv();
+ child.kill().unwrap();
+ child.wait().unwrap();
+ });
+
+ let key = hex::decode(ready_r.recv().unwrap()).unwrap();
+
+ let file = "filename.txt";
+ let got = matasano::crack_hmac_timing(file, |guess| {
+ let mut params = std::collections::HashMap::new();
+ params.insert("file", file);
+ params.insert("signature", guess);
+ let res = reqwest::get(&format!(
+ "{}{}",
+ "http://localhost:9000/?",
+ matasano::create_query_string(params)
+ ))
+ .unwrap();
+ let status = res.status();
+ status.is_success()
+ });
+ let expected = matasano::sha1_hmac(file.as_bytes(), &key);
+ assert_eq!(got, expected);
+
+ kill_w.send(()).unwrap();
+}