Beispiel #1
0
    def on_authenticate(self, data):
        core = Core.getInstance()

        # Check Public ID
        if not 'publicId' in data:
            util.socketError(self, 'Missing public key.')
            return
        publicId = data['publicId']
        if not util.validPublicId(publicId):
            util.socketError(self, 'Invalid public key.')
            return

        # Handle reconnection
        if publicId in core.clients:
            if not core.validIdPair(data):
                self.emit('authenticate', {'status': 'fail'})
                return
            client = core.clients[publicId]
            client.sockets['core'] = self
            self.socket.session['client'] = client
            self.emit('authenticate', {'status': 'success'})
            return

        # Distribute privateId
        secret = None
        if('privateId' in data
           and util.validPrivateId(data['privateId'])):
            secret = data['privateId']
        else:
            secret = util.randomKey(32)
        self.client = Client(publicId, secret)
        self.client.sockets['core'] = self
        core.clients[publicId] = self.client
        self.emit('authenticate', {'status': 'success'
                                 , 'privateId': secret})
Beispiel #2
0
 def validIdPair(self, data):
     if not 'publicId' in data:
         return False
     if not 'privateId' in data:
         return False
     if not util.validPublicId(data['publicId']):
         return False
     if not util.validPrivateId(data['privateId']):
         return False
     if not data['publicId'] in self.clients:
         return False
     client = self.clients[data['publicId']]
     return client.privateId == data['privateId']
Beispiel #3
0
 def authenticate(self, privateId):
     if not validPrivateId(privateId):
         return False
     return self.privateId == privateId