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

Commit fae3bd9

Browse files
authored
Merge pull request #2 from CSCfi/feature/sign-create-expire
Add signature expiration
2 parents feacb6b + f2027b2 commit fae3bd9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

swift_upload_runner/auth.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import hashlib
66
import typing
77
import hmac
8+
import time
89

910
import aiohttp.web
1011

1112
from swift_browser_ui._convenience import (
1213
initiate_os_session
1314
)
1415

15-
1616
AiohttpHandler = typing.Callable[
1717
[aiohttp.web.Request],
1818
typing.Coroutine[
@@ -70,8 +70,14 @@ async def test_signature(
7070
tokens: typing.List[bytes],
7171
signature: str,
7272
message: str,
73+
validity: str,
7374
) -> bool:
7475
"""Validate signature against the given tokens."""
76+
# Check signature expiration
77+
if int(validity) < time.time():
78+
raise aiohttp.web.HTTPUnauthorized(
79+
reason="Signature expired"
80+
)
7581
byte_message = message.encode("utf-8")
7682
for token in tokens:
7783
digest = hmac.new(
@@ -104,7 +110,8 @@ async def handle_validate_authentication(
104110
await test_signature(
105111
request.app["tokens"],
106112
signature,
107-
validity + path
113+
validity + path,
114+
validity
108115
)
109116

110117
return await handler(request)

0 commit comments

Comments
 (0)