Skip to content

Commit

Permalink
Simplify token implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
evilaliv3 committed Jan 14, 2025
1 parent 368aeda commit 4416780
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions backend/globaleaks/utils/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ def serialize(self):
'complexity': 4
}

def validate(self, token_answer):
def validate(self, answer):
try:
key, answer = token_answer.split(b":")

if not sha256(key + answer).endswith(b'00'):
if not sha256(self.id + answer).endswith(b'00'):
raise errors.InternalServerError("TokenFailure: Invalid Token")
except:
raise errors.InternalServerError("TokenFailure: Invalid token")
Expand All @@ -49,11 +47,11 @@ def get(self, key):

return ret

def validate(self, token_answer):
def validate(self, answer):
try:
key, answer = token_answer.split(b":")
key, answer = answer.split(b":")
token = self.pop(key)
token.validate(token_answer)
token.validate(answer)
except:
raise errors.InternalServerError("TokenFailure: Invalid token")

Expand Down

0 comments on commit 4416780

Please sign in to comment.