diff options
author | Yigit Sever | 2021-04-14 18:41:19 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-14 19:12:51 +0300 |
commit | 99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0 (patch) | |
tree | acddaca634eed06c909c8d27c8c19fe11379d3ee | |
parent | bd4fafc54a23c1587eac662d14a88bcfadcfcb86 (diff) | |
download | gradecoin-99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0.tar.gz gradecoin-99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0.tar.bz2 gradecoin-99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0.zip |
[WIP] Address users by their fingerprint
-rw-r--r-- | src/handlers.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/handlers.rs b/src/handlers.rs index 5e957bb..cc4c6c3 100644 --- a/src/handlers.rs +++ b/src/handlers.rs | |||
@@ -12,7 +12,7 @@ use parking_lot::RwLockUpgradableReadGuard; | |||
12 | use rsa::{PaddingScheme, RSAPrivateKey}; | 12 | use rsa::{PaddingScheme, RSAPrivateKey}; |
13 | use serde::Serialize; | 13 | use serde::Serialize; |
14 | use serde_json; | 14 | use serde_json; |
15 | use sha2; | 15 | use sha2::Sha256; |
16 | use std::convert::Infallible; | 16 | use std::convert::Infallible; |
17 | use std::fs; | 17 | use std::fs; |
18 | use warp::{http::StatusCode, reply}; | 18 | use warp::{http::StatusCode, reply}; |
@@ -152,6 +152,8 @@ pub async fn authenticate_user( | |||
152 | return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); | 152 | return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); |
153 | } | 153 | } |
154 | 154 | ||
155 | let fingerprint = Sha256::digest(&request.public_key.as_bytes()); | ||
156 | |||
155 | let new_user = User { | 157 | let new_user = User { |
156 | user_id: privileged_student_id, | 158 | user_id: privileged_student_id, |
157 | public_key: request.public_key, | 159 | public_key: request.public_key, |
@@ -163,8 +165,8 @@ pub async fn authenticate_user( | |||
163 | fs::write(format!("users/{}.guy", new_user.user_id), user_json).unwrap(); | 165 | fs::write(format!("users/{}.guy", new_user.user_id), user_json).unwrap(); |
164 | 166 | ||
165 | let mut userlist = RwLockUpgradableReadGuard::upgrade(userlist); | 167 | let mut userlist = RwLockUpgradableReadGuard::upgrade(userlist); |
166 | userlist.insert(provided_id, new_user); | 168 | |
167 | // TODO: signature of the public key, please <11-04-21, yigit> // | 169 | userlist.insert(format!("{:x}", fingerprint), new_user); |
168 | 170 | ||
169 | let res_json = warp::reply::json(&GradeCoinResponse { | 171 | let res_json = warp::reply::json(&GradeCoinResponse { |
170 | res: ResponseType::Success, | 172 | res: ResponseType::Success, |