Skip to content

Commit

Permalink
chore: minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BRAVO68WEB committed Sep 12, 2024
1 parent cbeb782 commit 2ee3d42
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
.env
dump.rdb
keys
keys
.keys
2 changes: 1 addition & 1 deletion crates/attendance/src/libs/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions crates/http/src/libs/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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();
private_key
}

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();
Expand Down
27 changes: 24 additions & 3 deletions gen-keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -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

0 comments on commit 2ee3d42

Please sign in to comment.