diff options
author | Yigit Sever | 2021-04-14 18:41:19 +0300 |
---|---|---|
committer | Yigit Sever | 2021-04-14 19:12:51 +0300 |
commit | 452e3c0f15b820db05a348342c99a48283f1c7ad (patch) | |
tree | 2b0bd86c13a7f70ced4f33c532bd201fb5b4003e /src | |
parent | becef0cc197dc8527ec83e39f5a0084123c17bb2 (diff) | |
download | gradecoin-452e3c0f15b820db05a348342c99a48283f1c7ad.tar.gz gradecoin-452e3c0f15b820db05a348342c99a48283f1c7ad.tar.bz2 gradecoin-452e3c0f15b820db05a348342c99a48283f1c7ad.zip |
[WIP] Address users by their fingerprint
Diffstat (limited to 'src')
-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, |