SSL/conceptual aspects of sharing a object via pyt

2019-08-14 04:24发布

问题:

Hello fellow inhabitants of the stackspace! I want to learn/elaborate on serving objects by remote shared object method

class ContainerFS():
    #contains stuffs, has its methods
    def sync(self):
         pass
    def dump(self):
         stuff()

class DataManager(BaseManager):
    def get_data(self):
        pass


class DataProcess(Process):
    def __init__(self, serverobj, authkey, public=False, port=11111):
        Process.__init__(self)
        self.authkey = authkey
        self.Obj = serverobj
        self.daemon = True
        self.port = port
        self.addr = '127.0.0.1'
        if public:
            self.addr = '0.0.0.0'

    def run(self):
        DataManager.register('get_data',
                             callable=lambda: self.Obj)
        manager = DataManager(
            address=(self.addr, self.port),
            authkey=self.authkey)

        srv = datamgr.get_server()
        srv.serve_forever()

The class ContainerFS is given as argument for serverobj. It then serves data to clients over a socket.

the client works like this so far:

class DataClient(object):
    def __init__(self):
        pass

    def create(self, authkey):
        try:
            DataManager.register('get_data')
            self.m = DataManager(address=('127.0.0.1', 11111), authkey=authkey)
            return True
        except:
            return False

    def connect(self):
        try:
            self.m.connect()
            q = self.m.get_data()
            return q
        except:
            return False

Given that one can share a arbitrary python object and access its methods that way, there might be ALOT of interesting stuff coming from the fertile grounds of SO. So if you have some good ideas, please mix them in.

I tried subclassing SocketServer and have it handle SSL that way, but I was not able to make it happen. How can I have lazy SSL with this thing? If SSL is no option could using ssh port forwarding socks magic be a sufficient alternative?

Can I assert that a method call of the serverobj is valid somehow. If yes where should I go to: DataProcess, DataManager or the serverobj?

Still doing this stuff without really understanding it. For instance, how could I use this DataManager sitting their empty?

I feel exposing a python object that way is really not secure. So I should refrain from crafting my own homebaked 'security'. I like to assert False on my thoughts for testing by elaboration. Thats where I hope on you coming in.

If I am unclear or seem to be making no point, plz indicate it. I am still new to everything..