Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Add signature expiration #2

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions swift_upload_runner/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import hashlib
import typing
import hmac
import time

import aiohttp.web

from swift_browser_ui._convenience import (
initiate_os_session
)


AiohttpHandler = typing.Callable[
[aiohttp.web.Request],
typing.Coroutine[
Expand Down Expand Up @@ -70,8 +70,14 @@ async def test_signature(
tokens: typing.List[bytes],
signature: str,
message: str,
validity: str,
) -> bool:
"""Validate signature against the given tokens."""
# Check signature expiration
if int(validity) < time.time():
raise aiohttp.web.HTTPUnauthorized(
reason="Signature expired"
)
byte_message = message.encode("utf-8")
for token in tokens:
digest = hmac.new(
Expand Down Expand Up @@ -104,7 +110,8 @@ async def handle_validate_authentication(
await test_signature(
request.app["tokens"],
signature,
validity + path
validity + path,
validity
)

return await handler(request)