aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYigit Sever2021-04-10 16:56:00 +0300
committerYigit Sever2021-04-10 16:56:00 +0300
commit001a9ac21c29af53d31e9710d12e37d565880207 (patch)
tree7e0bbbc0b828694950ffaff6f6b51f63a62f46c7
parenta3bc90d6755acbe3670dfcf23f35acdaf9b00ffc (diff)
downloadgradecoin-001a9ac21c29af53d31e9710d12e37d565880207.tar.gz
gradecoin-001a9ac21c29af53d31e9710d12e37d565880207.tar.bz2
gradecoin-001a9ac21c29af53d31e9710d12e37d565880207.zip
giving up with style
-rw-r--r--.gitignore1
-rw-r--r--secrets/gradecoin_rsa27
-rw-r--r--secrets/gradecoin_rsa.pub9
-rw-r--r--src/auth.rs2
-rw-r--r--src/custom_filters.rs2
-rw-r--r--src/handlers.rs9
-rw-r--r--src/routes.rs11
-rw-r--r--src/schema.rs4
8 files changed, 50 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index ca9689c..53d254d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
1/target 1/target
2/secrets
3tags.lock 2tags.lock
4tags.temp 3tags.temp
diff --git a/secrets/gradecoin_rsa b/secrets/gradecoin_rsa
new file mode 100644
index 0000000..f00685c
--- /dev/null
+++ b/secrets/gradecoin_rsa
@@ -0,0 +1,27 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIEpAIBAAKCAQEA4nU0G4WjkmcQUx0hq6LQuV5Q+ACmUFL/OjoYMDwC/O/6pCd1
3UZgCfgHN2xEffDPznzcTn8OiFRxr4oWyBinyrUpnY4mhy0SQUwoeCw7YkcHAyhCj
4NT74aR/ohX0MCj0qRRdbt5ZQXM/GC3HJuXE1ptSuhFgQxziItamn8maoJ6JUSVEX
5VO1NOrrjoM3r7Q+BK2B+sX4/bLZ+VG5g1q2nEbFdTHS6pHqtZNHQndTmEKwRfh0R
6YtzEzOXuO6e1gQY42Tujkof40dhGCIU7TeIGGHwdFxy1niLkXwtHNjV7lnIO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f2NzmLkLxuKaxldvaxPTfjMkgeO1LFMlNExYBhkuH
247uQpUQKBgQCKX6qMNh2gSdgG7qyxfTFZ4y5EGOBoKe/dE+IcVF3Vnh6DZVbCAbBL
255EdFWZSrCnDjA4xiKW55mwp95Ud9EZsZAb13L8V9t82eK+UDBoWlb7VRNYpda/x1
265/i4qQJ28x2UNJDStpYFpnp4Ba1lvXjKngIbDPkjU+hbBJ+BNGAIeg==
27-----END RSA PRIVATE KEY-----
diff --git a/secrets/gradecoin_rsa.pub b/secrets/gradecoin_rsa.pub
new file mode 100644
index 0000000..697f313
--- /dev/null
+++ b/secrets/gradecoin_rsa.pub
@@ -0,0 +1,9 @@
1-----BEGIN PUBLIC KEY-----
2MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4nU0G4WjkmcQUx0hq6LQ
3uV5Q+ACmUFL/OjoYMDwC/O/6pCd1UZgCfgHN2xEffDPznzcTn8OiFRxr4oWyBiny
4rUpnY4mhy0SQUwoeCw7YkcHAyhCjNT74aR/ohX0MCj0qRRdbt5ZQXM/GC3HJuXE1
5ptSuhFgQxziItamn8maoJ6JUSVEXVO1NOrrjoM3r7Q+BK2B+sX4/bLZ+VG5g1q2n
6EbFdTHS6pHqtZNHQndTmEKwRfh0RYtzEzOXuO6e1gQY42Tujkof40dhGCIU7TeIG
7GHwdFxy1niLkXwtHNjV7lnIOkTbx6+sSPamRfQAlZqUWM2Lf5o+7h3qWP3ENB138
8sQIDAQAB
9-----END PUBLIC KEY-----
diff --git a/src/auth.rs b/src/auth.rs
index 65d639b..51b2e6a 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -90,7 +90,7 @@ async fn authorize(
90 let decoded = decode::<Claims>( 90 let decoded = decode::<Claims>(
91 &jwt, 91 &jwt,
92 // TODO: what key are we using here? pass db/pw store here to get the claimant's public key <10-04-21, yigit> // 92 // TODO: what key are we using here? pass db/pw store here to get the claimant's public key <10-04-21, yigit> //
93 &DecodingKey::from_rsa_pem(PUBLIC_KEY_PEM.as_bytes()).unwrap(), 93 &DecodingKey::from_rsa_pem(db.users.read().get(&source).unwrap().pubkey.as_bytes()).unwrap(),
94 &Validation::new(Algorithm::HS512), 94 &Validation::new(Algorithm::HS512),
95 ) 95 )
96 .map_err(|_| reject::custom(Error::JWTTokenError)) 96 .map_err(|_| reject::custom(Error::JWTTokenError))
diff --git a/src/custom_filters.rs b/src/custom_filters.rs
index 8c36d02..1d65c69 100644
--- a/src/custom_filters.rs
+++ b/src/custom_filters.rs
@@ -12,7 +12,7 @@ pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clo
12 12
13// Accept only json encoded Transaction body and reject big payloads 13// Accept only json encoded Transaction body and reject big payloads
14pub fn transaction_json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone { 14pub fn transaction_json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone {
15 warp::body::content_length_limit(1024 * 32).and(warp::body::json()) 15 warp::body::content_length_limit(1024 * 32).and(warp::filters::body::json())
16} 16}
17 17
18// Accept only json encoded Transaction body and reject big payloads 18// Accept only json encoded Transaction body and reject big payloads
diff --git a/src/handlers.rs b/src/handlers.rs
index 0bcbd49..a9c0315 100644
--- a/src/handlers.rs
+++ b/src/handlers.rs
@@ -1,10 +1,11 @@
1use crate::auth::Pubkey;
1/// API handlers, the ends of each filter chain 2/// API handlers, the ends of each filter chain
2use log::debug; // this is more useful than debug! learn how to use this 3use log::debug; // this is more useful than debug! learn how to use this
3use parking_lot::RwLockUpgradableReadGuard; 4use parking_lot::RwLockUpgradableReadGuard;
4use std::convert::Infallible; 5use std::convert::Infallible;
5use warp::{http::StatusCode, reply}; 6use warp::filters::BoxedFilter;
6use warp::reject::Rejection; 7use warp::reject::Rejection;
7use crate::auth::Pubkey; 8use warp::{http::StatusCode, reply};
8 9
9use crate::schema::{Block, Db, Transaction}; 10use crate::schema::{Block, Db, Transaction};
10 11
@@ -63,11 +64,10 @@ pub async fn propose_transaction(
63/// POST /transaction, authenticated 64/// POST /transaction, authenticated
64/// The transaction arrived in this method has been authored by the public key in the source 65/// The transaction arrived in this method has been authored by the public key in the source
65pub async fn propose_authenticated_transaction( 66pub async fn propose_authenticated_transaction(
66 pubkey: Pubkey, 67 pubkey: BoxedFilter<(Pubkey,)>,
67 new_transaction: Transaction, 68 new_transaction: Transaction,
68 db: Db, 69 db: Db,
69) -> Result<impl warp::Reply, warp::Rejection> { 70) -> Result<impl warp::Reply, warp::Rejection> {
70
71 // auth logic 71 // auth logic
72 debug!("new transaction request {:?}", new_transaction); 72 debug!("new transaction request {:?}", new_transaction);
73 73
@@ -79,7 +79,6 @@ pub async fn propose_authenticated_transaction(
79 Ok(StatusCode::CREATED) 79 Ok(StatusCode::CREATED)
80} 80}
81 81
82
83/// POST /block 82/// POST /block
84/// Proposes a new block for the next round 83/// Proposes a new block for the next round
85/// Can reject the block 84/// Can reject the block
diff --git a/src/routes.rs b/src/routes.rs
index 871fd9c..b389919 100644
--- a/src/routes.rs
+++ b/src/routes.rs
@@ -8,7 +8,8 @@ use crate::schema::{Db, Transaction};
8/// Root, all routes combined 8/// Root, all routes combined
9pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone { 9pub fn consensus_routes(db: Db) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
10 transaction_list(db.clone()) 10 transaction_list(db.clone())
11 .or(transaction_propose(db.clone())) 11 // .or(transaction_propose(db.clone()))
12 .or(authenticated_transaction_propose(db.clone()))
12 .or(block_propose(db.clone())) 13 .or(block_propose(db.clone()))
13 .or(block_list(db.clone())) 14 .or(block_list(db.clone()))
14} 15}
@@ -51,16 +52,16 @@ pub fn authenticated_transaction_propose(
51 // // header/jwt logic to propose_transaction but that doesn't feel right either 52 // // header/jwt logic to propose_transaction but that doesn't feel right either
52 // // good luck <10-04-21, yigit> // 53 // // good luck <10-04-21, yigit> //
53 54
55 let db1 = db.clone();
54 warp::path("transaction") 56 warp::path("transaction")
55 .and(warp::path::end()) 57 .and(warp::path::end())
56 .and(warp::post()) 58 .and(warp::post())
57 .and(custom_filters::transaction_json_body()) // returns transaction 59 .and(custom_filters::transaction_json_body()) // returns transaction
58 .map(|t: Transaction| { 60 .map(move |t: Transaction| {
59 // what do these do? 61 with_auth(db1.clone(), t).boxed()
60 with_auth(db.clone(), t)
61 }) 62 })
62 .and(custom_filters::transaction_json_body()) // returns transaction 63 .and(custom_filters::transaction_json_body()) // returns transaction
63 .and(custom_filters::with_db(db)) // wraps db 64 .and(custom_filters::with_db(db.clone())) // wraps db
64 .and_then(handlers::propose_authenticated_transaction) // uses db, transaction and authenticated 65 .and_then(handlers::propose_authenticated_transaction) // uses db, transaction and authenticated
65} 66}
66 67
diff --git a/src/schema.rs b/src/schema.rs
index f680bbf..46d49cd 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -72,8 +72,8 @@ pub struct Block {
72 72
73#[derive(Serialize, Deserialize, Debug)] 73#[derive(Serialize, Deserialize, Debug)]
74pub struct User { 74pub struct User {
75 username: String, 75 pub username: String,
76 token: String 76 pub pubkey: String
77} 77}
78 78
79// TODO: write schema tests using the original repo <09-04-21, yigit> // 79// TODO: write schema tests using the original repo <09-04-21, yigit> //