summaryrefslogtreecommitdiffstats
path: root/tests/set4.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/set4.rs')
-rw-r--r--tests/set4.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/set4.rs b/tests/set4.rs
index 89581e2..3f927d3 100644
--- a/tests/set4.rs
+++ b/tests/set4.rs
@@ -213,7 +213,7 @@ fn problem_31() {
let key = hex::decode(ready_r.recv().unwrap()).unwrap();
let file = "filename.txt";
- let got = matasano::crack_hmac_timing(file, |guess| {
+ let got = matasano::crack_hmac_timing_basic(file, |guess| {
let mut params = std::collections::HashMap::new();
params.insert("file", file.to_string());
params.insert("signature", guess.to_string());
@@ -231,3 +231,40 @@ fn problem_31() {
kill_w.send(()).unwrap();
}
+
+#[test]
+#[ignore]
+fn problem_32() {
+ 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)
+ .args(&["5"])
+ .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_advanced(file, |uri| {
+ let res = reqwest::get(uri).unwrap();
+ res.status().is_success()
+ });
+ let expected = matasano::sha1_hmac(file.as_bytes(), &key);
+ assert_eq!(got, expected);
+
+ kill_w.send(()).unwrap();
+}