Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
add type annotations for encryption & decryption function
Browse files Browse the repository at this point in the history
(yesterday's update was broken for new registrations)
replace @gimb.si with "" on login

Reviewed-by: Mitja <[email protected]>

probably not working if I review this shit
  • Loading branch information
mytja committed Dec 20, 2023
1 parent 923bf8b commit 0d9a6ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/endpoints/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
async def login(response: Response, username: str = Form(), password: str = Form(), force_lopolis: str = Form("false")):
username = username.replace("@gimb.org", "")
username = username.replace("@dijaki.gimb.org", "")
username = username.replace("@gimb.si", "")
username = username.replace("@dijaki.gimb.si", "")
username = username.replace(" ", "")

print(f"[LOGIN] Prijavljam uporabnika {username} v BežiApp.")
Expand Down
12 changes: 6 additions & 6 deletions src/endpoints/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ async def login(self):
def encrypt_key(password: str) -> bytes:
return hashlib.sha256(password.encode()).digest()

def encrypt(raw, password):
raw = pad(raw, AES.block_size)
iv = Random.new().read(AES.block_size)
def encrypt(raw: str, password: str):
raw = pad(raw.encode(), BLOCK_SIZE)
iv = Random.new().read(BLOCK_SIZE)
cipher = AES.new(encrypt_key(password), AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(raw))

def decrypt(enc, password):
def decrypt(enc: str, password: str):
enc = base64.b64decode(enc)
iv = enc[:AES.block_size]
iv = enc[:BLOCK_SIZE]
cipher = AES.new(encrypt_key(password), AES.MODE_CBC, iv)
return unpad(cipher.decrypt(enc[AES.block_size:]), AES.block_size).decode('utf-8')
return unpad(cipher.decrypt(enc[BLOCK_SIZE:]), BLOCK_SIZE).decode('utf-8')

"""
Legacy code. Not working due to
Expand Down

0 comments on commit 0d9a6ab

Please sign in to comment.