From 2ee3d42e7d7b7a298559c33df94b4439dcb0bc8a Mon Sep 17 00:00:00 2001 From: bravo68web Date: Thu, 12 Sep 2024 10:50:09 +0000 Subject: [PATCH] chore: minor bug fixes --- .gitignore | 3 ++- crates/attendance/src/libs/jwt.rs | 2 +- crates/http/src/libs/jwt.rs | 4 ++-- gen-keys.sh | 27 ++++++++++++++++++++++++--- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c986bdb..b31c974 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target .env dump.rdb -keys \ No newline at end of file +keys +.keys \ No newline at end of file diff --git a/crates/attendance/src/libs/jwt.rs b/crates/attendance/src/libs/jwt.rs index 2166ee4..43ec923 100644 --- a/crates/attendance/src/libs/jwt.rs +++ b/crates/attendance/src/libs/jwt.rs @@ -3,7 +3,7 @@ use jwtk::{self}; use chrono::Duration; pub fn read_private_key() -> jwtk::ecdsa::EcdsaPrivateKey{ - let private_key_content = fs::read_to_string("../../keys/private.pem").unwrap(); + let private_key_content = fs::read_to_string("keys/private.pem").unwrap(); let private_key = jwtk::ecdsa::EcdsaPrivateKey::from_pem( private_key_content.as_bytes(), ).unwrap(); diff --git a/crates/http/src/libs/jwt.rs b/crates/http/src/libs/jwt.rs index a275e6b..8642818 100644 --- a/crates/http/src/libs/jwt.rs +++ b/crates/http/src/libs/jwt.rs @@ -4,7 +4,7 @@ use jwtk::{self, PublicKeyToJwk}; use chrono::Duration; pub fn read_private_key() -> jwtk::ecdsa::EcdsaPrivateKey{ - let private_key_content = fs::read_to_string("../../keys/private.pem").unwrap(); + let private_key_content = fs::read_to_string("keys/private.pem").unwrap(); let private_key = jwtk::ecdsa::EcdsaPrivateKey::from_pem( private_key_content.as_bytes(), ).unwrap(); @@ -12,7 +12,7 @@ pub fn read_private_key() -> jwtk::ecdsa::EcdsaPrivateKey{ } pub fn read_public_key() -> jwtk::ecdsa::EcdsaPublicKey { - let private_key_content = fs::read_to_string("../../keys/public.pem").unwrap(); + let private_key_content = fs::read_to_string("keys/public.pem").unwrap(); let public_key = jwtk::ecdsa::EcdsaPublicKey::from_pem( private_key_content.as_bytes(), ).unwrap(); diff --git a/gen-keys.sh b/gen-keys.sh index ca4d729..421e27a 100755 --- a/gen-keys.sh +++ b/gen-keys.sh @@ -6,10 +6,22 @@ while getopts "f" opt; do case $opt in f) echo "Force mode enabled" - rm -rf keys + rm -rf .keys + rm -rf crates/attendance/keys + rm -rf crates/http/keys mkdir keys openssl ecparam -name secp521r1 -genkey -noout -out keys/private.pem openssl ec -in keys/private.pem -pubout -out keys/public.pem + + mkdir -p crates/attendance/keys + mkdir -p crates/http/keys + + cp keys/private.pem crates/attendance/keys/private.pem + cp keys/public.pem crates/attendance/keys/public.pem + cp keys/private.pem crates/http/keys/private.pem + cp keys/public.pem crates/http/keys/public.pem + rm -rf keys + touch .keys echo "Keys generated successfully !!" exit 0 ;; @@ -19,13 +31,22 @@ while getopts "f" opt; do esac done -if [ -d "keys" ]; then +if [ -f ".keys" ]; then echo "Keys already exist !!" echo "Please remove the keys directory to generate new keys" exit 1 else - mkdir keys + mkdir -p keys openssl ecparam -name secp521r1 -genkey -noout -out keys/private.pem openssl ec -in private.pem -pubout -out keys/public.pem + mkdir -p crates/attendance/keys + mkdir -p crates/http/keys + + cp keys/private.pem crates/attendance/keys/private.pem + cp keys/public.pem crates/attendance/keys/public.pem + cp keys/private.pem crates/http/keys/private.pem + cp keys/public.pem crates/http/keys/public.pem + rm -rf keys + touch .keys echo "Keys generated successfully !!" fi \ No newline at end of file