comparison server/ts.py @ 334:3b821541657d

hmac
author Matt Johnston <matt@ucc.asn.au>
date Tue, 12 Jun 2012 00:35:23 +0800
parents 298e502fdcd4
children 048143905092
comparison
equal deleted inserted replaced
333:298e502fdcd4 334:3b821541657d
14 # for wrt 14 # for wrt
15 sys.path.append('/root/python') 15 sys.path.append('/root/python')
16 import httplib 16 import httplib
17 import time 17 import time
18 import traceback 18 import traceback
19 import binascii
20 import hmac
21
22 import config
19 23
20 from utils import monotonic_time, retry, readline, crc16 24 from utils import monotonic_time, retry, readline, crc16
21 25
22 lightblue = None 26 lightblue = None
23 try: 27 try:
103 if off != 'Off': 107 if off != 'Off':
104 print>>sys.stderr, "Bad response to btoff '%s'\n" % l 108 print>>sys.stderr, "Bad response to btoff '%s'\n" % l
105 109
106 return int(next_wake) 110 return int(next_wake)
107 111
112 def send_results(lines):
113 enc_lines = binascii.b2a_base64('\n'.join(lines))
114 hmac.new(config.HMAC_KEY, enc_lines).hexdigest()
115
116 url_data = urllib.url_encode( ('lines', enc_lines), ('hmac', mac) )
117 con = urllib2.urlopen(config.UPDATE_URL, url_data)
118
119
108 def do_comms(sock): 120 def do_comms(sock):
109 print "do_comms" 121 print "do_comms"
110 d = None 122 d = None
111 # serial could be unreliable, try a few times 123 # serial could be unreliable, try a few times
112 for i in range(FETCH_TRIES): 124 for i in range(FETCH_TRIES):