diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-31 15:09:58 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-31 15:09:58 +0200 |
commit | 69f765b2476b77967588c0751be8afda7dc3adaf (patch) | |
tree | 086bc81759dc588d7845a15e43b61867fcac591f | |
parent | Merging false heads. fix for forced commit. (diff) | |
download | pyload-69f765b2476b77967588c0751be8afda7dc3adaf.tar.xz |
new socket encryption
-rw-r--r-- | config | 2 | ||||
-rw-r--r-- | module/remote/ClientHandler.py | 22 | ||||
-rw-r--r-- | module/remote/ClientSocket.py | 26 | ||||
-rw-r--r-- | module/remote/RequestHandler.py | 16 | ||||
-rw-r--r-- | module/remote/SocketServer.py | 10 | ||||
-rwxr-xr-x | pyMainGui.py | 44 | ||||
-rw-r--r-- | sockettest.py | 30 |
7 files changed, 90 insertions, 60 deletions
@@ -14,6 +14,6 @@ fullLog = True start = 0:00 end = 6:00 [remote] -remote_activated = False +remote_activated = True port = 7272 remotePassword = pwhere diff --git a/module/remote/ClientHandler.py b/module/remote/ClientHandler.py new file mode 100644 index 000000000..0037a874e --- /dev/null +++ b/module/remote/ClientHandler.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +authored by: RaNaN + +this module handels the incoming requests + +""" +import hashlib + +from Crypto.Cipher import Blowfish +from RequestHandler import RequestHandler + +class ClientHandler(RequestHandler): + def __init__(self, client): + self.client = client + key = hashlib.sha256("pwhere") + self.bf = Blowfish.new(key.hexdigest(), Blowfish.MODE_ECB) + + def proceed(self, data): + obj = self.decrypt(data) + return self.encrypt(obj)
\ No newline at end of file diff --git a/module/remote/ClientSocket.py b/module/remote/ClientSocket.py index 74f66f0be..30eaf20e0 100644 --- a/module/remote/ClientSocket.py +++ b/module/remote/ClientSocket.py @@ -8,23 +8,31 @@ socket for connecting to the core's server """ import asynchat import socket -from RequestHandler import RequestHandler + +from ClientHandler import ClientHandler class ClientSocket(asynchat.async_chat): def __init__(self, client): - asynchat.async_chat.__init__(self) - self.client = client + asynchat.async_chat.__init__(self) + self.client = client self.data = "" - self.handler = RequestHandler(None) - self.set_terminator("\n") + self.handler = ClientHandler(None) + self.set_terminator("\n") self.create_socket(socket.AF_INET, socket.SOCK_STREAM) def handle_connect(self): - print "connected" - + print "connected" + + def handle_close(self): + print "Disconnected from", self.getpeername() + self.close() + def collect_incoming_data(self, data): + print "data arrived" self.data += data def found_terminator(self): - pass - #process + obj = self.handler.proceed(data) + self.push(obj) + print "pushed" + data = "" diff --git a/module/remote/RequestHandler.py b/module/remote/RequestHandler.py index 212f65b1c..ec0bf0414 100644 --- a/module/remote/RequestHandler.py +++ b/module/remote/RequestHandler.py @@ -8,29 +8,27 @@ this module handels the incoming requests """ import base64 +import hashlib import random import string import cPickle -from Crypto.Cipher import AES -from Crypto.Hash import MD5 -from Crypto.Hash import SHA +from Crypto.Cipher import Blowfish from RequestObject import RequestObject class RequestHandler: def __init__(self, core): self.core = core - key = SHA.new("pwhere") #core.config['remotepassword'] - key = MD5.new(key.hexdigest()) - self.aes = AES.new(key.hexdigest(), AES.MODE_ECB) + key = hashlib.sha256("pwhere") #core.config['remotepassword'] + self.bf = Blowfish.new(key.hexdigest(), Blowfish.MODE_ECB) def proceed(self, data): obj = self.decrypt(data) if obj.command == "exec": func = getattr(self.core, obj.function) - obj.response = func(*obj.args) + obj.response = func( * obj.args) else: obj.response = "error happend" @@ -40,7 +38,7 @@ class RequestHandler: def decrypt(self, dec_str): try: dec_str = base64.standard_b64decode(dec_str) - dec_str = self.aes.decrypt(dec_str) + dec_str = self.bf.decrypt(dec_str) dec_str = dec_str[:-(int(dec_str[-1], 16) + 1)] obj = cPickle.loads(dec_str) @@ -60,7 +58,7 @@ class RequestHandler: p_str += hex(len(p_str)).replace("0x", "") enc_str += p_str - enc_str = self.aes.encrypt(enc_str) + enc_str = self.bf.encrypt(enc_str) enc_str = base64.standard_b64encode(enc_str) return enc_str diff --git a/module/remote/SocketServer.py b/module/remote/SocketServer.py index 5bd6ba3d0..817e956aa 100644 --- a/module/remote/SocketServer.py +++ b/module/remote/SocketServer.py @@ -45,16 +45,16 @@ class SecondaryServerSocket(asynchat.async_chat): def __init__(self, socket, pycore): print 'initing SSS' asynchat.async_chat.__init__(self, socket) - self.pycore = pycore - self.handler = RequestHandler(pycore) - self.set_terminator('\n') + self.pycore = pycore + self.handler = RequestHandler(pycore) + self.set_terminator('\n') self.data = "" def collect_incoming_data(self, data): self.data += data def found_terminator(self): - print "data arrived" rep = self.handler.proceed(self.data) - self.push(rep) + self.sendall(rep+"\n") + print "push" self.data = "" #having fun with the data def handle_close(self): diff --git a/pyMainGui.py b/pyMainGui.py index 98eaac6ea..c9d3fcf00 100755 --- a/pyMainGui.py +++ b/pyMainGui.py @@ -18,20 +18,22 @@ # ### +from os import sep +from os.path import abspath +from os.path import dirname + import wx import wx.lib.sized_controls as sized_control -from os import sep -from os.path import abspath, dirname from module.remote.ClientSocket import ClientSocket class Download_Dialog(sized_control.SizedDialog): def __init__(self, parent, id): sized_control.SizedDialog.__init__(self, parent, id, "Downloads hinzufügen", - style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) + style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) pane = self.GetContentsPane() - self.links = wx.TextCtrl(pane, -1, style=wx.TE_MULTILINE, size=(500,200)) + self.links = wx.TextCtrl(pane, -1, style=wx.TE_MULTILINE, size=(500, 200)) self.links.SetSizerProps(expand=True, proportion=1) self.SetButtonSizer(self.CreateStdDialogButtonSizer(wx.OK | wx.CANCEL)) @@ -47,10 +49,10 @@ class upper_panel(wx.Panel): download_liste.InsertColumn(0, 'Name', width=250) download_liste.InsertColumn(1, 'Status') download_liste.InsertColumn(2, 'Groesse') - download_liste.InsertColumn(3, 'Uebertragen',width=100) - download_liste.InsertColumn(4, 'Prozent',width=100) - download_liste.InsertColumn(5, 'Dauer',width=100) - download_liste.InsertColumn(7, 'Geschwindigkeit',width=150) + download_liste.InsertColumn(3, 'Uebertragen', width=100) + download_liste.InsertColumn(4, 'Prozent', width=100) + download_liste.InsertColumn(5, 'Dauer', width=100) + download_liste.InsertColumn(7, 'Geschwindigkeit', width=150) sizer.Add(download_liste, 1, wx.EXPAND) self.SetSizer(sizer) @@ -65,38 +67,38 @@ class lower_panel(wx.Panel): class pyload_main_gui(wx.Frame): def __init__(self, parent, id, title="pyLoad"): - wx.Frame.__init__(self,parent,id,title, size=(910,500)) + wx.Frame.__init__(self, parent, id, title, size=(910, 500)) app_path = dirname(abspath(__file__)) + sep # socket self.socket = ClientSocket(self) self.socket.connect(('localhost', 7272)) - self.socket.push("nonsense\n") + self.socket.sendall("nonsense\n") # Menubar menubar = wx.MenuBar() menu_file = wx.Menu() - submenu_exit = menu_file.Append(-1,'Schliessen','pyLoad beenden') + submenu_exit = menu_file.Append(-1, 'Schliessen', 'pyLoad beenden') menubar.Append(menu_file, '&Datei') self.SetMenuBar(menubar) # Toolbar toolbar = self.CreateToolBar() - toolbar.SetToolBitmapSize((32,32)) - add = toolbar.AddLabelTool(2,'',wx.Bitmap(app_path + '/icons/add.png')) - delete = toolbar.AddLabelTool(3,'',wx.Bitmap(app_path + '/icons/del.png')) - start = toolbar.AddLabelTool(4,'',wx.Bitmap(app_path + '/icons/start.png')) - pause = toolbar.AddLabelTool(5,'',wx.Bitmap(app_path + '/icons/pause.png')) - stop = toolbar.AddLabelTool(6,'',wx.Bitmap(app_path + '/icons/stop.png')) - up = toolbar.AddLabelTool(7,'',wx.Bitmap(app_path + '/icons/up.png')) - down = toolbar.AddLabelTool(8,'',wx.Bitmap(app_path + '/icons/down.png')) - config = toolbar.AddLabelTool(9,'',wx.Bitmap(app_path + '/icons/setup.png')) + toolbar.SetToolBitmapSize((32, 32)) + add = toolbar.AddLabelTool(2, '', wx.Bitmap(app_path + '/icons/add.png')) + delete = toolbar.AddLabelTool(3, '', wx.Bitmap(app_path + '/icons/del.png')) + start = toolbar.AddLabelTool(4, '', wx.Bitmap(app_path + '/icons/start.png')) + pause = toolbar.AddLabelTool(5, '', wx.Bitmap(app_path + '/icons/pause.png')) + stop = toolbar.AddLabelTool(6, '', wx.Bitmap(app_path + '/icons/stop.png')) + up = toolbar.AddLabelTool(7, '', wx.Bitmap(app_path + '/icons/up.png')) + down = toolbar.AddLabelTool(8, '', wx.Bitmap(app_path + '/icons/down.png')) + config = toolbar.AddLabelTool(9, '', wx.Bitmap(app_path + '/icons/setup.png')) toolbar.Realize() splitter = wx.SplitterWindow(self) panel_up = upper_panel(splitter) panel_down = lower_panel(splitter) - splitter.SplitHorizontally(panel_up,panel_down,300) + splitter.SplitHorizontally(panel_up, panel_down, 300) # Binds self.Bind(wx.EVT_MENU, self.exit_button_clicked, submenu_exit) diff --git a/sockettest.py b/sockettest.py index 882895b57..eab6608c2 100644 --- a/sockettest.py +++ b/sockettest.py @@ -7,31 +7,31 @@ script only for socket testing """ import base64 -import cPickle +import hashlib import random import string -from Crypto.Cipher import AES -from Crypto.Hash import SHA -from Crypto.Hash import MD5 -from module.remote.RequestObject import RequestObject +import cPickle +from Crypto.Cipher import Blowfish +from module.remote.RequestObject import RequestObject +from module.remote.ClientSocket import ClientSocket class Handler: def __init__(self): - key = SHA.new("pwhere") - key = MD5.new(key.hexdigest()) - self.aes = AES.new(key.hexdigest(), AES.MODE_ECB) + key = hashlib.sha256("pwhere") + print key.hexdigest() + self.bf = Blowfish.new(key.hexdigest(), Blowfish.MODE_ECB) def proceed(self, data): - return self.decrypt(self.encrypt(str(("lol","mehrlol","pff")))) + return self.decrypt(self.encrypt(str(("lol", "mehrlol", "pff")))) def decrypt(self, dec_str): try: dec_str = base64.standard_b64decode(dec_str) - dec_str = self.aes.decrypt(dec_str) + dec_str = self.bf.decrypt(dec_str) - dec_str = dec_str[:-(int(dec_str[-1],16)+1)] + dec_str = dec_str[:-(int(dec_str[-1], 16) + 1)] obj = cPickle.loads(dec_str) except: obj = None @@ -44,11 +44,11 @@ class Handler: p_str = "" for i in range(padding - 1): - p_str += random.choice(string.letters+string.digits) - p_str += hex(len(p_str)).replace("0x","") + 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 = self.bf.encrypt(enc_str) enc_str = base64.standard_b64encode(enc_str) return enc_str @@ -65,7 +65,7 @@ obj = RequestObject() obj.command = "exec" obj.function = "get_downloads" -sock.sendall(handler.encrypt(obj)+"\n") +sock.sendall(handler.encrypt(obj) + "\n") response = sock.recv(8192) |