From 99f9c5f918a6a9946015cf0e9f2e0054e28b3ab0 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Wed, 14 Apr 2021 18:41:19 +0300 Subject: [WIP] Address users by their fingerprint --- src/handlers.rs | 8 +++++--- 1 file 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; use rsa::{PaddingScheme, RSAPrivateKey}; use serde::Serialize; use serde_json; -use sha2; +use sha2::Sha256; use std::convert::Infallible; use std::fs; use warp::{http::StatusCode, reply}; @@ -152,6 +152,8 @@ pub async fn authenticate_user( return Ok(warp::reply::with_status(res_json, StatusCode::BAD_REQUEST)); } + let fingerprint = Sha256::digest(&request.public_key.as_bytes()); + let new_user = User { user_id: privileged_student_id, public_key: request.public_key, @@ -163,8 +165,8 @@ pub async fn authenticate_user( fs::write(format!("users/{}.guy", new_user.user_id), user_json).unwrap(); let mut userlist = RwLockUpgradableReadGuard::upgrade(userlist); - userlist.insert(provided_id, new_user); - // TODO: signature of the public key, please <11-04-21, yigit> // + + userlist.insert(format!("{:x}", fingerprint), new_user); let res_json = warp::reply::json(&GradeCoinResponse { res: ResponseType::Success, -- cgit v1.2.3-70-g09d2