diff options
Diffstat (limited to 'module/remote/RequestHandler.py')
| -rw-r--r-- | module/remote/RequestHandler.py | 63 | 
1 files changed, 38 insertions, 25 deletions
| diff --git a/module/remote/RequestHandler.py b/module/remote/RequestHandler.py index c72f6eaaa..09ad5b548 100644 --- a/module/remote/RequestHandler.py +++ b/module/remote/RequestHandler.py @@ -8,44 +8,57 @@ this module handels the incoming requests  """  import base64 -import cPickle  import random  import string + +import cPickle  from Crypto.Cipher import AES +from Crypto.Hash import MD5  from Crypto.Hash import SHA +from RequestObject import RequestObject -class RequestHandler(): +class RequestHandler:      def __init__(self, core): -	self.core = core -	key = SHA.new(core.config['remotepassword']) -	self.aes = AES.new(key.hexdigest()[:32], AES.MODE_ECB) +        self.core = core +        key = SHA.new(core.config['remotepassword']) +        key = MD5.new(key.hexdigest()) +        self.aes = AES.new(key.hexdigest(), AES.MODE_ECB)      def proceed(self, data): -	return self.encrypt({'befehl' : None , 'args':[1,2,3], 'test': 'lol'}) +        obj = self.decrypt(data) -    def decrypt(self, dec_str): -	dec_str = base64.standard_b64decode(dec_str) -	dec_str = self.aes.decrypt(dec_str) +        if obj.command == "exec": +            func = getattr(self.core, obj.function) +            obj.response = func() +        else: +            obj.response = "antwort" +         +        return self.encrypt(obj) -	dec_str = dec_str[:-(int(dec_str[-1],16)+1)] -	obj = cPickle.loads(dec_str) -	return obj + +    def decrypt(self, dec_str): +        dec_str = base64.standard_b64decode(dec_str) +        dec_str = self.aes.decrypt(dec_str) +         +        dec_str = dec_str[:-(int(dec_str[-1], 16) + 1)] +        obj = cPickle.loads(dec_str) +        return obj      def encrypt(self, obj): -	enc_str = cPickle.dumps(obj, 1) -	padding = len(enc_str) % 16 -	padding = 16 - padding -	 -	p_str = "" -	for i in range(padding - 1): -		p_str += random.choice(string.letters+string.digits) -	p_str += hex(len(p_str)).replace("0x","") -	enc_str += p_str - -	enc_str = self.aes.encrypt(enc_str) -	enc_str = base64.standard_b64encode(enc_str) -	return enc_str +        enc_str = cPickle.dumps(obj, 1) +        padding = len(enc_str) % 16 +        padding = 16 - padding + +        p_str = "" +        for i in range(padding - 1): +            p_str += random.choice(string.letters + string.digits) +        p_str += hex(len(p_str)).replace("0x", "") +        enc_str += p_str + +        enc_str = self.aes.encrypt(enc_str) +        enc_str = base64.standard_b64encode(enc_str) +        return enc_str | 
