コード例 #1
0
 def _processPOSTRequest(self, content):
     try:
         o = self._getJSONContent(content)
     except Exception as ex:
         self._logRefused('BAD REQUEST, %s' % ex)
         self._sendHTTPResponse(400, '400 : Bad Request (%s)' % ex)
         return
     try:
         uid = IoTSocketStruct.UIDToBin128(o['UID'])
         timeout = int(o.get('Timeout', self._maxSecWaitResponse))
         fmt, data = IoTSocketStruct.EncodeJSONPayload(
             o['Payload'], o['Format'])
         if uid and timeout > 0 and fmt is not None and data is not None:
             if timeout > self._maxSecWaitResponse:
                 timeout = self._maxSecWaitResponse
             exp = time() + timeout
             self._trackingNbr = self._router.AddCentralHTTPRequest(
                 self, exp)
             strUID = ('{%s}' % IoTSocketStruct.UIDFromBin128(uid))
             self._log('REQUEST TO %s RECEIVED (#%s)' %
                       (strUID, self._trackingNbr))
             if not self._router.RouteRequest(
                     fromUID=None,
                     toUID=uid,
                     trackingNbr=self._trackingNbr,
                     dataFormat=fmt,
                     formatOpt=IoTSocketStruct.PLDATA_FMT_OPT_NONE,
                     data=data):
                 self._router.RemoveCentralHTTPRequest(self)
                 self.SendResponseErrNoDest()
             return
     except:
         pass
     self._logRefused('BAD REQUEST, INCORRECT JSON DATA')
     self._sendHTTPResponse(400, '400 : Bad Request (incorrect json data)')
コード例 #2
0
 def _processPOSTACL(self, content):
     try:
         o = self._getJSONContent(content)
     except Exception as ex:
         self._logRefused('BAD REQUEST, %s' % ex)
         self._sendHTTPResponse(400, '400 : Bad Request (%s)' % ex)
         return
     try:
         acl = []
         ok = True
         for ac in o:
             groupID = IoTSocketStruct.GroupNameToBin128(ac['GroupName'])
             uid = IoTSocketStruct.UIDToBin128(ac['UID'])
             authKey = unhexlify(ac['AuthKey'])
             if groupID and uid and authKey and len(authKey) == 16:
                 acl.append((groupID, uid, authKey))
             else:
                 ok = False
                 break
         if ok:
             self._router.ClearACL()
             for ac in acl:
                 self._router.AddACLAccess(*ac)
             self._router.SaveACL()
             self._log('%s ACL SETUP RECEIVED' % len(acl))
             self._sendHTTPResponse(200)
             return
     except:
         pass
     self._logRefused('BAD REQUEST, INCORRECT JSON DATA')
     self._sendHTTPResponse(400, '400 : Bad Request (incorrect json data)')
コード例 #3
0
 def _onChallengeRecv(self, xAsyncTCPClient, data, arg) :
     #uid = IoTSocketStruct.CENTRAL_EMPTY_UID
     #key = b'\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA\xBB\xCC\xDD\xEE\xFF'
     uid     = IoTSocketStruct.UIDToBin128("ObjTest")
     authKey = b'CCCCCCCCDDDDDDDD'
     hmac256 = hmac.new(authKey, data, hashlib.sha256).digest()
     self._send(uid + hmac256)
     self._recv(1, self._onAuthValidationRecv)
コード例 #4
0
 def LoadACL(self):
     try:
         with open(self._aclFilename, 'r') as file:
             o = json.load(file)
         acl = {}
         for strUID in o:
             uid = IoTSocketStruct.UIDToBin128(strUID)
             groupID = IoTSocketStruct.GroupNameToBin128(
                 o[strUID]["GroupName"])
             authKey = unhexlify(o[strUID]["AuthKey"])
             if not uid or not groupID or len(authKey) != 16 or \
                not groupID in self._groups :
                 return False
             acl[uid] = (groupID, authKey)
         with self._lock:
             self._acl = acl
         return True
     except:
         return False