aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock47
-rw-r--r--Cargo.toml1
-rw-r--r--scripts/encryptor.py8
-rw-r--r--src/handlers.rs2
-rw-r--r--tests/route_tests.rs72
5 files changed, 93 insertions, 37 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 82a3df2..22990ad 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -41,6 +41,15 @@ dependencies = [
41] 41]
42 42
43[[package]] 43[[package]]
44name = "ansi_term"
45version = "0.12.1"
46source = "registry+https://github.com/rust-lang/crates.io-index"
47checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
48dependencies = [
49 "winapi 0.3.9",
50]
51
52[[package]]
44name = "anyhow" 53name = "anyhow"
45version = "1.0.40" 54version = "1.0.40"
46source = "registry+https://github.com/rust-lang/crates.io-index" 55source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -283,6 +292,16 @@ dependencies = [
283] 292]
284 293
285[[package]] 294[[package]]
295name = "ctor"
296version = "0.1.20"
297source = "registry+https://github.com/rust-lang/crates.io-index"
298checksum = "5e98e2ad1a782e33928b96fc3948e7c355e5af34ba4de7670fe8bac2a3b2006d"
299dependencies = [
300 "quote",
301 "syn",
302]
303
304[[package]]
286name = "derivative" 305name = "derivative"
287version = "2.2.0" 306version = "2.2.0"
288source = "registry+https://github.com/rust-lang/crates.io-index" 307source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -294,6 +313,12 @@ dependencies = [
294] 313]
295 314
296[[package]] 315[[package]]
316name = "diff"
317version = "0.1.12"
318source = "registry+https://github.com/rust-lang/crates.io-index"
319checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
320
321[[package]]
297name = "digest" 322name = "digest"
298version = "0.9.0" 323version = "0.9.0"
299source = "registry+https://github.com/rust-lang/crates.io-index" 324source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -457,6 +482,7 @@ dependencies = [
457 "log4rs", 482 "log4rs",
458 "md-5", 483 "md-5",
459 "parking_lot 0.10.2", 484 "parking_lot 0.10.2",
485 "pretty_assertions",
460 "rsa", 486 "rsa",
461 "serde", 487 "serde",
462 "serde_json", 488 "serde_json",
@@ -985,6 +1011,15 @@ dependencies = [
985] 1011]
986 1012
987[[package]] 1013[[package]]
1014name = "output_vt100"
1015version = "0.1.2"
1016source = "registry+https://github.com/rust-lang/crates.io-index"
1017checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9"
1018dependencies = [
1019 "winapi 0.3.9",
1020]
1021
1022[[package]]
988name = "parking_lot" 1023name = "parking_lot"
989version = "0.10.2" 1024version = "0.10.2"
990source = "registry+https://github.com/rust-lang/crates.io-index" 1025source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1115,6 +1150,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1115checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" 1150checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
1116 1151
1117[[package]] 1152[[package]]
1153name = "pretty_assertions"
1154version = "0.7.2"
1155source = "registry+https://github.com/rust-lang/crates.io-index"
1156checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b"
1157dependencies = [
1158 "ansi_term",
1159 "ctor",
1160 "diff",
1161 "output_vt100",
1162]
1163
1164[[package]]
1118name = "proc-macro2" 1165name = "proc-macro2"
1119version = "1.0.26" 1166version = "1.0.26"
1120source = "registry+https://github.com/rust-lang/crates.io-index" 1167source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 45fda30..77efd25 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -30,3 +30,4 @@ askama = "0.10.5"
30 30
31[dev-dependencies] 31[dev-dependencies]
32serde_test = "1.0.117" 32serde_test = "1.0.117"
33pretty_assertions = "0.7.2"
diff --git a/scripts/encryptor.py b/scripts/encryptor.py
index 2dac487..ed0c1d8 100644
--- a/scripts/encryptor.py
+++ b/scripts/encryptor.py
@@ -12,6 +12,9 @@ def hex2bin(hexStr):
12 return binascii.unhexlify(hexStr) 12 return binascii.unhexlify(hexStr)
13 13
14iv = hex2bin("6e657665726d696e647468656e66756b") 14iv = hex2bin("6e657665726d696e647468656e66756b")
15
16iv_ready = base64.b64encode(iv)
17
15key = hex2bin("6e6565726d666e646e6565726d666e64") 18key = hex2bin("6e6565726d666e646e6565726d666e64")
16 19
17mode = CBC(iv) 20mode = CBC(iv)
@@ -67,3 +70,8 @@ asy_cipher = PKCS1_OAEP.new(publickey, hashAlgo=Crypto.Hash.SHA256)
67ciphertext = asy_cipher.encrypt(key) 70ciphertext = asy_cipher.encrypt(key)
68 71
69key = base64.b64encode(ciphertext) 72key = base64.b64encode(ciphertext)
73
74print(f'key: {key}')
75print(f'c: {c}')
76print(f'iv: {iv_ready}')
77
diff --git a/src/handlers.rs b/src/handlers.rs
index 7204aa7..e831806 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -224,7 +224,7 @@ pub async fn authenticate_user(
224 Err(err) => { 224 Err(err) => {
225 println!( 225 println!(
226 "auth request (c) did not decrypt correctly {:?} {}", 226 "auth request (c) did not decrypt correctly {:?} {}",
227 &auth_packet, err 227 &buf, err
228 ); 228 );
229 229
230 let res_json = warp::reply::json(&GradeCoinResponse { 230 let res_json = warp::reply::json(&GradeCoinResponse {
diff --git a/tests/route_tests.rs b/tests/route_tests.rs
index cfa1af6..a449b0b 100644
--- a/tests/route_tests.rs
+++ b/tests/route_tests.rs
@@ -1,6 +1,7 @@
1#[cfg(test)] 1#[cfg(test)]
2mod tests { 2mod tests {
3 use gradecoin::schema::{Block, Db, InitialAuthRequest, MetuId, Transaction, User}; 3 use gradecoin::schema::{Block, Db, InitialAuthRequest, MetuId, Transaction, User};
4 use pretty_assertions::assert_eq;
4 5
5 use gradecoin::routes::consensus_routes; 6 use gradecoin::routes::consensus_routes;
6 use warp::http::StatusCode; 7 use warp::http::StatusCode;
@@ -24,7 +25,7 @@ FQIDAQAB
24-----END PUBLIC KEY-----" 25-----END PUBLIC KEY-----"
25 .to_owned(), 26 .to_owned(),
26 balance: 30, 27 balance: 30,
27 is_bot: false 28 is_bot: false,
28 }, 29 },
29 ); 30 );
30 31
@@ -34,45 +35,44 @@ FQIDAQAB
34 user_id: MetuId::new("e223715".to_owned(), "1H5QuOYI1b2r9ET".to_owned()).unwrap(), 35 user_id: MetuId::new("e223715".to_owned(), "1H5QuOYI1b2r9ET".to_owned()).unwrap(),
35 public_key: "NOT_USED_FOR_THIS_USER".to_owned(), 36 public_key: "NOT_USED_FOR_THIS_USER".to_owned(),
36 balance: 0, 37 balance: 0,
37 is_bot: false 38 is_bot: false,
38 }, 39 },
39 ); 40 );
40 41
41 /* 42 /*
42-----BEGIN RSA PRIVATE KEY----- 43 -----BEGIN RSA PRIVATE KEY-----
43MIIEpAIBAAKCAQEA5yWTMeFqr2nvOC9oR5Wq/nzcNlwCIaziojt7rJ4BBvuwkT0t 44 MIIEpAIBAAKCAQEA5yWTMeFqr2nvOC9oR5Wq/nzcNlwCIaziojt7rJ4BBvuwkT0t
44ERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXGekrGzvC8jHQMKHyNoWzUlpQJ9UMt 45 ERDz8AgvUsaewiB+Fz5OXTeb3WAB1FEXnBXGekrGzvC8jHQMKHyNoWzUlpQJ9UMt
45dQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2/ef6abkdj+XWg/slYtrFeOf3ktc1 46 dQIWPOCuMyLpc+rNPL3428U8UpldjbTHHyq2/ef6abkdj+XWg/slYtrFeOf3ktc1
46l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH8LFPX4bO9lJ9mAoMZFec6XVwumn/ 47 l50R4k8VO8L6kQuh2+YIjXGPLShRaqnUQPtH8LFPX4bO9lJ9mAoMZFec6XVwumn/
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+/kPwmQuTa5kSB9PgWsWzYjwNm4OX1j+mbL9lEDLf7tRVWQ 64 pMfDowx1+hBu7/7CF+/kPwmQuTa5kSB9PgWsWzYjwNm4OX1j+mbL9lEDLf7tRVWQ
64lydJyz7tmRYzWj6j4V/l/u90M3QgyiqTbCf73GG0AkjaRwHn3dG1gl9A0lZqDvK3 65 lydJyz7tmRYzWj6j4V/l/u90M3QgyiqTbCf73GG0AkjaRwHn3dG1gl9A0lZqDvK3
65iQXouwKBgQCrx6SCnEkhLISSZpzdDehtWmyCQJIwcdlRQlAmFLVn+TJHTXR7xUm2 66 iQXouwKBgQCrx6SCnEkhLISSZpzdDehtWmyCQJIwcdlRQlAmFLVn+TJHTXR7xUm2
66VpTrPTfaYWx83OQUn/OZqY5gIQ+jlfwqnVg+PDQQ/P09/4xygRCLvjL6NCSvtkj1 67 VpTrPTfaYWx83OQUn/OZqY5gIQ+jlfwqnVg+PDQQ/P09/4xygRCLvjL6NCSvtkj1
67MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg== 68 MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg==
68-----END RSA PRIVATE KEY----- 69 -----END RSA PRIVATE KEY-----
69*/ 70 */
70 71
71 db.pending_transactions.write().insert( 72 db.pending_transactions.write().insert(
72 "fingerprint_of_foo".to_owned(), 73 "fingerprint_of_foo".to_owned(),
73 Transaction { 74 Transaction {
74 source: "fingerprint_of_foo" 75 source: "fingerprint_of_foo".to_owned(),
75 .to_owned(),
76 target: "fingerprint_of_foo".to_owned(), 76 target: "fingerprint_of_foo".to_owned(),
77 amount: 2, 77 amount: 2,
78 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), 78 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30),
@@ -110,7 +110,7 @@ MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg==
110 110
111 assert_eq!(res.status(), StatusCode::OK); 111 assert_eq!(res.status(), StatusCode::OK);
112 112
113 let expected_json_body = r#"{"fingerprint_of_foo":{"by":"fingerprint_of_foo","source":"31415926535897932384626433832795028841971693993751058209749445923","target":"fingerprint_of_foo","amount":2,"timestamp":"2021-04-13T20:55:30"}}"#; 113 let expected_json_body = r#"{"fingerprint_of_foo":{"source":"fingerprint_of_foo","target":"fingerprint_of_foo","amount":2,"timestamp":"2021-04-13T20:55:30"}}"#;
114 114
115 assert_eq!(res.body(), expected_json_body); 115 assert_eq!(res.body(), expected_json_body);
116 } 116 }
@@ -231,9 +231,9 @@ MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg==
231 db.pending_transactions.write().insert( 231 db.pending_transactions.write().insert(
232 "fingerprint_of_some_guy".to_owned(), 232 "fingerprint_of_some_guy".to_owned(),
233 Transaction { 233 Transaction {
234 source: "fingerprint_of_some_guy" 234 source: "fingerprint_of_some_guy".to_owned(),
235 target: "31415926535897932384626433832795028841971693993751058209749445923"
235 .to_owned(), 236 .to_owned(),
236 target: "31415926535897932384626433832795028841971693993751058209749445923".to_owned(),
237 amount: 2, 237 amount: 2,
238 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30), 238 timestamp: chrono::NaiveDate::from_ymd(2021, 04, 13).and_hms(20, 55, 30),
239 }, 239 },
@@ -420,7 +420,7 @@ MRArEl4y68+jZLRu74TVG0lXi6ht6KhNHF6GiWKU9FHZ4B+btLicsg==
420 .json(&InitialAuthRequest { 420 .json(&InitialAuthRequest {
421 c: "D9OKSp4XD+niltqhoiTEyz3pTxGm5ZKYVNFPofW40M6Km7wE7FgIpfTkurBZ6tQsG/rYPRsd6C/Qo+o3HrgOYC8BDprwpnYb7UnJdL2pe44ZMEsPAmDAdwTP9WozY0lr+bjEjtTM1mVQnIdfknychFek/FNi3l8MrapeFTxFaTMGxWuS1+wEuAkcz4AR4+jooaXVAE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YVf8aLgd1l0HEiCyT+kWxvcR5hw42I7gqaoUcnr53Zm1mYK30/fvZ6lxsrb4FphldgQC5fx6nwEgjaLUeB4n0oZTSRLbrd9ZXCjUG4FNmM+sOklhIXyTYUj4VcBSwZuAvJZEFf2em68e7ySJs/ysz+TGu3eVeRc+voAvI9mGLxWnSEjWx64po7PO61uG6ikadHZH+wIw==".to_owned(),
422 iv: "bmV2ZXJtaW5kdGhlbmZ1aw==".to_owned(), 422 iv: "bmV2ZXJtaW5kdGhlbmZ1aw==".to_owned(),
423 key: "s4cn9BSmuForX6PxJAa55Es4t2puXuDtdII1lxEArqVlP+uYd5jDKofFtn9PCAoY7jyTgBIhQW7Ah5MGCcufWTaKHAjFVfSZ+qGwbGbBcklbNGH/F7cJ0Pe7kOCddUpIvLG6WH6+mnvyPs8PwDyagsx1Jc2PSSOYLAwkECvPbjiUjQiBixguTRNsU2eKaqzLimPE0w2ztvdA+IgCv94UPhjQfQrnMGK+Ppn3oK7IfKQJ7v2DLVNuz4d/BpwuqD+lYYAu4B4qn3daNR32a/mqAAlPg/RbPlH69N44Qh/NYux90FOY0XKxUskEwsAUw8dHFzzdKPcGx4C0s5e4KSLGkw==".to_owned(), 423 key: "Xd6/VSuFKqayNHspcFJSm+PAHNoTmcR4SsMijSyuyEh6PS5rdvO4W98AhxW4VBrRO1ljfEMeFq835NEDame511D2pim00Xv0HPIYSDW6pIJA1hy+Np/WyC7PCxvKy0hPzTmHMpFmM+aF43BknJdYlPUhY4cww/xScU6WxuKIsEQNORRhQds8CHOO0EGcOjHVvR2xqnOda1g/rI7mfNMATHj9ZRsB9GH6QG5WTUbo9/71cDAILF+28TG40jSKvY2KzO9vr668tgqoMV2vLnXQa1AD9ZWmdHHdjiXuiH3X0uXxHrfjH7HeXi/HOj/pgCX12jKsEsRwkBTGL4koObH6pQ==".to_owned(),
424 }) 424 })
425 .path("/register") 425 .path("/register")
426 .reply(&filter) 426 .reply(&filter)