flask - HMAC SHA1 Digest in python -
i'm using moves api fitness data. instead of querying api on regular basis use storyline notifications.
it works, request api i'm unable verify hmac sha1 signature provided in request.
the documentation says:
all notification requests signed base64 encoded hmac-sha1 signature. signature calculated hmac_sha1(<your client secret>,<request body>|<timestamp>|<nonce>), in other words client secret key , request body, timestamp , nonce concatenated message data. http headers not included in signature. headers x-moves-signature, x-moves-timestamp , x-moves-nonce contain signature, timestamp , nonce values. timestamp unix timestamp, seconds since jan 01 1970 00:00:00 gmt.
my implementation:
from hmac import new hmac_new hashlib import sha1 def check_signature(signature, timestamp, nonce, client_secret, request_body): msg = request_body + timestamp.encode('utf-8') + nonce.encode('utf-8') hmac = hmac_new(key=client_secret, msg=msg, digestmod=sha1) return hmac.digest().encode('base64') == signature
i request flask , call function likes this:
check_signature(headers['x-moves-signature'], headers['x-moves-timestamp'], headers['x-moves-nonce'], settings['client-secret'], request.data)
values:
client-secret= mnmuu6rdmkeg5fl0fm0ho2z14juhmvwantungz0vyxc446rtqp8j7etfag0tqa58 request-body = {"userid": 34511428141091768, "storylineupdates": [{"reason": "dataupload", "endtime": "20150429t121602z", "lastsegmenttype": "place", "lastsegmentstarttime": "20150429t101434z", "starttime": "20150429t101434z"}]} x-moves-nonce = eqvco4bnnbn+8hhiz7zcea== x-moves-signature = brmwycxglul01wbyxpfpdtijh2y= x-moves-timestamp = 1430309780 my-digest = pawr/3yij8nt8kukorgvjlpmqem= my-hexdigest = a5a591ff7ca227c353f0aba4a2b195265a6641e3 moves_signature = brmwycxglul01wbyxpfpdtijh2y=
i tried http://www.freeformatter.com/hmac-generator.html , received a5a591ff7ca227c353f0aba4a2b195265a6641e3
.
(the client secret not valid anymore).
as can see values digest , moves_signature not equal. sadly i'm unable digest equal 1 moves i'm unable locate problem. have idea on how fix this?
Comments
Post a Comment