Skip to content

Commit 94fcbd3

Browse files
committed
Add SHA384 support for signature authentication.
1 parent 8fc9de9 commit 94fcbd3

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 0.3.0 / 2023-27-03 ###
2+
- Change the way the `transloadit` client is initialized. Now it is possible to pass the `sha_384` boolean parameter to the `Transloadit` class to enable the `sha_384` hash algorithm for the signature. The default value is `True` and the `sha_384` algorithm is used. The `sha_384` algorithm is recommended for new integrations and it is required for the new Transloadit accounts. The `sha_1` algorithm is deprecated and it will be removed in the future. For compatibility reasons it is possible to use `sha_1` with the `sha_384` parameter set to `False`.
3+
- Added `sha_384` as hash algorithm for the signature authentication.
4+
15
### Unreleased
26
- Drop Python 3.6 from CI. It has been unsupported since December 2021 and github actions runner don't support anymore (https://github.com/actions/setup-python/issues/544)
37

transloadit/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Transloadit:
1616
- auth_secret (str): Transloadit auth secret.
1717
- service (Optional[str]): URL of the Transloadit API.
1818
- duration (int): How long in seconds for which a Transloadit request should be valid.
19+
- sha_384 (bool): Whether to use SHA-384 for signing requests. Defaults to True. If False, SHA-1 is used.
1920
- request (transloadit.request.Request): An instance of the Transloadit HTTP Request object.
2021
2122
:Constructor Args:
@@ -27,6 +28,8 @@ class Transloadit:
2728
- duration (Optional[int]):
2829
How long in seconds for which a Transloadit request should be valid. Defaults to 300
2930
if not specified.
31+
- sha_384 (Optional[bool]):
32+
Whether to use SHA-384 for signing requests. Defaults to True. If False, SHA-1 is used.
3033
"""
3134

3235
def __init__(
@@ -35,6 +38,7 @@ def __init__(
3538
auth_secret: str,
3639
service: str = "https://api2.transloadit.com",
3740
duration: int = 300,
41+
sha_384: bool = True,
3842
):
3943
if not service.startswith(("http://", "https://")):
4044
service = "https://" + service
@@ -43,6 +47,7 @@ def __init__(
4347
self.auth_key = auth_key
4448
self.auth_secret = auth_secret
4549
self.duration = duration
50+
self.sha_384 = sha_384
4651
self.request = request.Request(self)
4752

4853
def new_assembly(self, params: dict = None) -> assembly.Assembly:

transloadit/request.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,12 @@ def _to_payload(self, data):
123123
return {"params": json_data, "signature": self._sign_data(json_data)}
124124

125125
def _sign_data(self, message):
126-
return hmac.new(
127-
b(self.transloadit.auth_secret), message.encode("utf-8"), hashlib.sha1
128-
).hexdigest()
126+
if not self.transloadit.sha_384:
127+
return hmac.new(b(self.transloadit.auth_secret), message.encode("utf-8"), hashlib.sha1).hexdigest()
128+
129+
else:
130+
hash_string = hmac.new(b(self.transloadit.auth_secret), message.encode("utf-8"), hashlib.sha384).hexdigest()
131+
return f"sha384:{hash_string}"
129132

130133
def _get_full_url(self, url):
131134
if url.startswith(("http://", "https://")):

0 commit comments

Comments
 (0)