Skip to content

Commit f658bfc

Browse files
author
Yakov Gnusin
committed
Removed HMAC authentication.
Added new authentication mechanism.
1 parent adb1bfa commit f658bfc

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

fr8/hub.py

+6-26
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import base64
21
import json
3-
import hashlib
4-
import hmac
5-
import time
6-
import urllib
72
import urllib2
8-
import uuid
93

104
import data
115

@@ -24,36 +18,22 @@ def __init__(self, hub_url, terminal_id, terminal_secret, container_id, user_id)
2418

2519
def get_payload(self):
2620
payload_url = self.hub_url + 'api/v1/containers/payload?id=' + self.container_id
27-
hmac_header = Hub.generate_hmac_header(
28-
urllib.quote(payload_url, safe=''),
29-
self.terminal_id,
21+
auth_header = Hub.generate_authentication_header(
3022
self.terminal_secret,
3123
self.user_id
3224
)
3325

3426
headers = {
35-
"Authorization": "hmac " + hmac_header
27+
"Authorization": "FR8-TOKEN " + auth_header
3628
}
3729
request = urllib2.Request(payload_url, headers=headers)
3830
contents = urllib2.urlopen(request).read()
3931
return data.PayloadDTO.from_fr8_json(json.loads(contents))
4032

4133
@staticmethod
42-
def generate_hmac_header(url, terminal_id, terminal_secret, user_id, content = bytearray()):
43-
timestamp = str(int(time.time()))
44-
nonce = uuid.uuid4()
34+
def generate_authentication_header(terminal_secret, user_id):
35+
result = 'key=' + terminal_secret
36+
if user_id:
37+
result += ', user=' + user_id
4538

46-
m = hashlib.md5()
47-
m.update(content)
48-
md5_digest = m.digest()
49-
md5_base64 = base64.b64encode(md5_digest)
50-
51-
raw = terminal_id + url + timestamp + str(nonce) + md5_base64 + user_id
52-
key_bytes = bytearray(str(terminal_secret))
53-
message_bytes = bytearray(raw, 'utf-8')
54-
55-
hmac_digest = hmac.new(key_bytes, message_bytes, hashlib.sha512).digest()
56-
hmac_base64 = base64.b64encode(hmac_digest)
57-
58-
result = terminal_id + ":" + hmac_base64 + ":" + str(nonce) + ":" + timestamp + ":" + user_id
5939
return result

0 commit comments

Comments
 (0)