comparison py/uploader.py @ 536:3a27b1a09d2e

sha256 hash
author Matt Johnston <matt@ucc.asn.au>
date Tue, 19 May 2015 23:58:51 +0800
parents 9b1d71310c83
children 0a1b642e3086 ffe25107d520
comparison
equal deleted inserted replaced
535:3a514fbb88eb 536:3a27b1a09d2e
46 def send(self, tosend): 46 def send(self, tosend):
47 js = json.dumps(tosend) 47 js = json.dumps(tosend)
48 if self.server.test_mode(): 48 if self.server.test_mode():
49 D("Would upload %s to %s" % (js, config.UPDATE_URL)) 49 D("Would upload %s to %s" % (js, config.UPDATE_URL))
50 return 50 return
51 js_enc = binascii.b2a_base64(zlib.compress(js.encode())) 51 js_enc = binascii.b2a_base64(zlib.compress(js.encode())).strip()
52 mac = hmac.new(config.HMAC_KEY.encode(), js_enc, hashlib.sha1).hexdigest() 52 mac = hmac.new(config.HMAC_KEY.encode(), js_enc, hashlib.sha256).hexdigest()
53 send_data = {'data': js_enc, 'hmac': mac} 53 send_data = {'data': js_enc.decode(), 'hmac': mac}
54 r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60) 54 r = yield from asyncio.wait_for(aiohttp.request('post', config.UPDATE_URL, data=send_data), 60)
55 result = yield from asyncio.wait_for(r.text(), 60) 55 result = yield from asyncio.wait_for(r.text(), 60)
56 if result != 'OK': 56 if result != 'OK':
57 raise Exception("Server returned %s" % result) 57 raise Exception("Server returned %s" % result)
58 58