From 45d98cdbf95580ea7e21d17a0518993fe23914a0 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Fri, 16 Apr 2021 14:41:35 +0300 Subject: Passing auth test --- scripts/encryptor.py | 24 ++++++++++++++++++------ src/handlers.rs | 9 ++++----- tests/route_tests.rs | 2 +- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/scripts/encryptor.py b/scripts/encryptor.py index 008ac51..2dac487 100644 --- a/scripts/encryptor.py +++ b/scripts/encryptor.py @@ -20,16 +20,28 @@ cipher = Cipher(algorithms.AES(key), mode) encryptor = cipher.encryptor() -padder = padding.PKCS7(128).padder() -payload_string = """{"public_key":"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzJN9ALFoUHE8SigFhtql -\\n+GPI6dIVHDCfAFXe6DU131yXoL14imBRBb5SevMou5WGiL7XBTdtlRaY8+dkNdFz\\nWEMhPoe++/GvV3u6Mq6UAJMjuiJj838NbJVl+83+NEP66htXpqidTIdr -7syaRU1T\\n0PfgvVYdNkwiWkTVtwveRchGtUwp2iZePMSF1+vtKKDvzXgZuwrKBhwBFXz6ApSZ\\n+eGkWhK1pW6TRTSENlySwb/DEg5PckzOzApLTTQqi4uu+sHU -D+McAtOP9pNILwst\\nG87LxNEO0roFqUaDIhRolgkF8jol2BUZmKChdy84XX+L6jpqDvPsxuTUpIghr0Jq\\nvQIDAQAB\\n-----END PUBLIC KEY-----","st -udent_id":"e223795","passwd":"pmcTCKox99NFsqp"}""" +payload = dict() +payload["public_key"] = """-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoNsLhsQzL+5HiGuaI4mu +K0TqiLEOFPOl8kd9pWR8eop0b7/N2ggDRXATIkV+XwzeQp+k9lGT1h2B2bDhxn51 +lBESb2rSqKKzTVf4SXoPxqvPwsi1bnmHcRG8tTr+ZWcJdblXabMUkKUJCrwKhvr8 +UpOi0tndcc7buVq4EWCIBUeG4SCFHeBu1Ue9Zus7BpwjSxF4jHH4M8ssl/ioN8+m +qz9LcDQe3kvVRMlVbaXjYnWyP0VjwRbQuwIjMsDVaTQUIVtPZY9el7LiIxCqZ4mO +cnnwlIZyGLN52uqDZ1cz7aSO18YIGcbCpxuOuPhSzrnZNvHJZFIkacd477fK+PKB +7QIDAQAB +-----END PUBLIC KEY-----""" +payload["student_id"] = "e223795" +payload["passwd"] = "pmcTCKox99NFsqp" + +import json +payload_string = json.dumps(payload) byte_guys = str.encode(payload_string) + +padder = padding.PKCS7(128).padder() padded_data = padder.update(byte_guys) +padded_data += padder.finalize() ct = encryptor.update(padded_data) + encryptor.finalize() diff --git a/src/handlers.rs b/src/handlers.rs index 2401c0d..ee0fbf0 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -151,7 +151,7 @@ pub async fn authenticate_user( let res_json = warp::reply::json(&GradeCoinResponse { res: ResponseType::Error, - message: "Given IV has invalid length".to_owned(), + message: "Given IV has invalid length, use a 128 bit key".to_owned(), }); return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); @@ -176,9 +176,8 @@ pub async fn authenticate_user( } }; - println!(">>>{:?}<<<", auth_packet); - - let auth_plaintext = match cipher.decrypt_vec(&auth_packet) { + let mut buf = auth_packet.to_vec(); + let auth_plaintext = match cipher.decrypt(&mut buf) { Ok(p) => p, Err(err) => { println!( @@ -195,7 +194,7 @@ pub async fn authenticate_user( } }; - let utf8_auth_plaintext = match String::from_utf8(auth_plaintext.clone()) { + let utf8_auth_plaintext = match String::from_utf8(auth_plaintext.to_vec()) { Ok(text) => text, Err(err) => { debug!( diff --git a/tests/route_tests.rs b/tests/route_tests.rs index 537b3d8..f3fbb0e 100644 --- a/tests/route_tests.rs +++ b/tests/route_tests.rs @@ -445,7 +445,7 @@ FQIDAQAB let res = warp::test::request() .method("POST") .json(&InitialAuthRequest { - c: "xsF0qqyokuvOZJ4CgnW4mzfLHaTZS3vLqr7y8LF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