From 75ec270230cb361293d62f79710ccae4dd39bb01 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Fri, 16 Apr 2021 05:47:08 +0300 Subject: Almost passsing auth --- src/handlers.rs | 14 +++++++++----- tests/route_tests.rs | 8 +++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 376d079..2401c0d 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -139,8 +139,9 @@ pub async fn authenticate_user( } }; - // TODO: request iv is coming with base64 encoding <16-04-21, yigit> // - let cipher = match Aes128Cbc::new_var(&temp_key, &request.iv.as_bytes()) { + let byte_iv = base64::decode(&request.iv).unwrap(); + + let cipher = match Aes128Cbc::new_var(&temp_key, &byte_iv) { Ok(c) => c, Err(err) => { debug!( @@ -175,17 +176,19 @@ pub async fn authenticate_user( } }; + println!(">>>{:?}<<<", auth_packet); + let auth_plaintext = match cipher.decrypt_vec(&auth_packet) { Ok(p) => p, Err(err) => { - debug!( + println!( "Base64 decoded auth request did not decrypt correctly {:?} {}", &auth_packet, err ); let res_json = warp::reply::json(&GradeCoinResponse { res: ResponseType::Error, - message: "The Bas64 decoded auth request did not decrypt correctly".to_owned(), + message: "The Base64 decoded auth request did not decrypt correctly".to_owned(), }); return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); @@ -608,7 +611,8 @@ pub async fn authorized_propose_transaction( // this transaction was already checked for correctness at custom_filters, we can panic here if // it has been changed since - let hashed_transaction = Md5::digest((&serde_json::to_string(&new_transaction).unwrap()).as_ref()); + let hashed_transaction = + Md5::digest((&serde_json::to_string(&new_transaction).unwrap()).as_ref()); if token_payload.claims.tha != format!("{:x}", hashed_transaction) { println!( "the hash of the request {:x} did not match the hash given in jwt {:?}", diff --git a/tests/route_tests.rs b/tests/route_tests.rs index 0b7628c..537b3d8 100644 --- a/tests/route_tests.rs +++ b/tests/route_tests.rs @@ -266,8 +266,6 @@ FQIDAQAB let db = mocked_db(); let filter = consensus_routes(db.clone()); - - let res = warp::test::request() .method("POST") .json(&Block { @@ -447,9 +445,9 @@ FQIDAQAB let res = warp::test::request() .method("POST") .json(&InitialAuthRequest { - c: "llqkPAX8oGxBLFHGMNzwrCAP2WmsGZlOcm3mCp7+ZnX9p7BPffRvGcYHpif4htwU5RyR3fLo/VWERXqddVQkxhfuum0dFn1cpPfYTokc2BHpi61i4SXCaCHlJDxCtCKnujfEzMnS5hAKMQSyrwq/DPBwOSQ/XQeeMB0YF+l+ZfVJ8e6sQ5FfSK9rSInv+TokA7az6vR7Ky5fGjQ0GxKkO+SKLd5eHuGKgQ19JUQrj3k19GJn1h1cmWW1PYqVKFDp/RfWFL9weG8VynRND6xGK5fQarjdG0uMAk8Cy8ItOCAeMnBhUv/P2a721u3tA7L496r4E3ZwdgsiHe4iYzFiAdvWDWsLRlxXS+6Q2vUYSLgcFVsv2jyQ28c/ay3F1hYAHaqN4HiDhKz6bFCiyow1Doya2V24VQm5eUGxXErjEnLY1FWE5sqRn6DUnES3FT8VJoMtnhCFtZhO4Jk0cjh15p9r+vK6uJv0PUCKOOYhghFi5bLL34OpmzoV7u7Fj6tSc/e9UujbCfYc3r9g0oUQ+QKxw6R5Fcqf21TbffxX/i1tKElIhkatfWCaZ+c0scLNL4Jg3KbNqbensOFqzErr12pXHFy7QKXH1usnCJyC+9D7NncxKZ9JuVFJL19Ayq90o/IYWhtVlkhZs/F5UPIhl3G7f8OQ1tUgfdCfiXZ5qgg=".to_owned(), - iv: "RbZzPxu1IL+f+PZ/SJzi/Q==".to_owned(), - key: "baz".to_owned(), + c: "xsF0qqyokuvOZJ4CgnW4mzfLHaTZS3vLqr7y8LFx6pdKo0XKXBJ4+Ojx8Uz6CYrQZLPy39O485BZNtYtLzcfF/03MePBNgSRM6ccVuh6hJ8UUAjv9nf93gZlnGceMP0bLKEaYRHTsgyW+s0y0ki7/CfYn3vveLDd4NVkkgFUAebcmMuAJJt0OAzSLgsQ/kww6hOOsIcIlBNlLIi0dopCUxE5h7aPqV4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