Skip to content

Commit

Permalink
Make sure that using this number generator is safe (#9)
Browse files Browse the repository at this point in the history
- Only use random number generators which are recommended by OWASP

https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html#secure-random-number-generation

Signed-off-by: Julian Strobl <[email protected]>
  • Loading branch information
jmastr authored Nov 9, 2023
1 parent 36203e3 commit 6ae89ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cid_resolver/app/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
import random
import secrets
from cid_resolver.app.verify_signature import validate_signature_data_string
from cid_resolver.config import (
AUTH_CHALLENGE_SIZE,
Expand All @@ -22,7 +22,7 @@ def does_pub_key_belong_to_valid_actor(pub_key: str) -> bool:
def create_challenge(pub_key: str) -> int:
cleanup_pending_challenges()
challenges[pub_key] = (
bytes([random.randint(0, 255) for _ in range(0, AUTH_CHALLENGE_SIZE)]),
bytes([secrets.randbelow(256) for _ in range(0, AUTH_CHALLENGE_SIZE)]),
time.time(),
)
return challenges[pub_key][0]
Expand Down

0 comments on commit 6ae89ce

Please sign in to comment.