aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYigit Sever2021-04-16 14:41:35 +0300
committerYigit Sever2021-04-16 14:41:35 +0300
commit45d98cdbf95580ea7e21d17a0518993fe23914a0 (patch)
treeb48baf4608325dd536d07cb5fd68684f9f047586
parent109ae1f771ec5e8a5a9510c3b09fad579dab5ed7 (diff)
downloadgradecoin-45d98cdbf95580ea7e21d17a0518993fe23914a0.tar.gz
gradecoin-45d98cdbf95580ea7e21d17a0518993fe23914a0.tar.bz2
gradecoin-45d98cdbf95580ea7e21d17a0518993fe23914a0.zip
Passing auth test
-rw-r--r--scripts/encryptor.py24
-rw-r--r--src/handlers.rs9
-rw-r--r--tests/route_tests.rs2
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)
20 20
21encryptor = cipher.encryptor() 21encryptor = cipher.encryptor()
22 22
23padder = padding.PKCS7(128).padder()
24 23
25payload_string = """{"public_key":"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzJN9ALFoUHE8SigFhtql 24payload = dict()
26\\n+GPI6dIVHDCfAFXe6DU131yXoL14imBRBb5SevMou5WGiL7XBTdtlRaY8+dkNdFz\\nWEMhPoe++/GvV3u6Mq6UAJMjuiJj838NbJVl+83+NEP66htXpqidTIdr 25payload["public_key"] = """-----BEGIN PUBLIC KEY-----
277syaRU1T\\n0PfgvVYdNkwiWkTVtwveRchGtUwp2iZePMSF1+vtKKDvzXgZuwrKBhwBFXz6ApSZ\\n+eGkWhK1pW6TRTSENlySwb/DEg5PckzOzApLTTQqi4uu+sHU 26MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoNsLhsQzL+5HiGuaI4mu
28D+McAtOP9pNILwst\\nG87LxNEO0roFqUaDIhRolgkF8jol2BUZmKChdy84XX+L6jpqDvPsxuTUpIghr0Jq\\nvQIDAQAB\\n-----END PUBLIC KEY-----","st 27K0TqiLEOFPOl8kd9pWR8eop0b7/N2ggDRXATIkV+XwzeQp+k9lGT1h2B2bDhxn51
29udent_id":"e223795","passwd":"pmcTCKox99NFsqp"}""" 28lBESb2rSqKKzTVf4SXoPxqvPwsi1bnmHcRG8tTr+ZWcJdblXabMUkKUJCrwKhvr8
29UpOi0tndcc7buVq4EWCIBUeG4SCFHeBu1Ue9Zus7BpwjSxF4jHH4M8ssl/ioN8+m
30qz9LcDQe3kvVRMlVbaXjYnWyP0VjwRbQuwIjMsDVaTQUIVtPZY9el7LiIxCqZ4mO
31cnnwlIZyGLN52uqDZ1cz7aSO18YIGcbCpxuOuPhSzrnZNvHJZFIkacd477fK+PKB
327QIDAQAB
33-----END PUBLIC KEY-----"""
34payload["student_id"] = "e223795"
35payload["passwd"] = "pmcTCKox99NFsqp"
36
37import json
38payload_string = json.dumps(payload)
30 39
31byte_guys = str.encode(payload_string) 40byte_guys = str.encode(payload_string)
41
42padder = padding.PKCS7(128).padder()
32padded_data = padder.update(byte_guys) 43padded_data = padder.update(byte_guys)
44padded_data += padder.finalize()
33 45
34ct = encryptor.update(padded_data) + encryptor.finalize() 46ct = encryptor.update(padded_data) + encryptor.finalize()
35 47
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(
151 151
152 let res_json = warp::reply::json(&GradeCoinResponse { 152 let res_json = warp::reply::json(&GradeCoinResponse {
153 res: ResponseType::Error, 153 res: ResponseType::Error,
154 message: "Given IV has invalid length".to_owned(), 154 message: "Given IV has invalid length, use a 128 bit key".to_owned(),
155 }); 155 });
156 156
157 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); 157 return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST));
@@ -176,9 +176,8 @@ pub async fn authenticate_user(
176 } 176 }
177 }; 177 };
178 178
179 println!(">>>{:?}<<<", auth_packet); 179 let mut buf = auth_packet.to_vec();
180 180 let auth_plaintext = match cipher.decrypt(&mut buf) {
181 let auth_plaintext = match cipher.decrypt_vec(&auth_packet) {
182 Ok(p) => p, 181 Ok(p) => p,
183 Err(err) => { 182 Err(err) => {
184 println!( 183 println!(
@@ -195,7 +194,7 @@ pub async fn authenticate_user(
195 } 194 }
196 }; 195 };
197 196
198 let utf8_auth_plaintext = match String::from_utf8(auth_plaintext.clone()) { 197 let utf8_auth_plaintext = match String::from_utf8(auth_plaintext.to_vec()) {
199 Ok(text) => text, 198 Ok(text) => text,
200 Err(err) => { 199 Err(err) => {
201 debug!( 200 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
445 let res = warp::test::request() 445 let res = warp::test::request()
446 .method("POST") 446 .method("POST")
447 .json(&InitialAuthRequest { 447 .json(&InitialAuthRequest {
448 c: "xsF0qqyokuvOZJ4CgnW4mzfLHaTZS3vLqr7y8LFx6pdKo0XKXBJ4+Ojx8Uz6CYrQZLPy39O485BZNtYtLzcfF/03MePBNgSRM6ccVuh6hJ8UUAjv9nf93gZlnGceMP0bLKEaYRHTsgyW+s0y0ki7/CfYn3vveLDd4NVkkgFUAebcmMuAJJt0OAzSLgsQ/kww6hOOsIcIlBNlLIi0dopCUxE5h7aPqV4WyrxA/PSvE8hM8LcfYiATTa7PyinfkjCRu7hzItM/N3+h/zubI+6ht8lY4V/19WB24HnMZJdP1odAPuKbSDiyZoMvq+P7jHfWnbJxJJI7hEYlbB45MNMnFenVhzwEtIqHu6JEGhi7umDoh2zUDAXzofERkd3qNgPtV6L3hxmDX94Y8FIJ9ZdDj/EG06PXj9P3kg0Gt4t+hi+J8h+RtV+g+Pwza1kFCLA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