# HG changeset patch # User BarthaM@N3SIM1218.D03.arc.local # Date 1405687509 -3600 # Node ID 2e0b94e12bfc407e0903ded890b9326f75e90aa1 # Parent 59ebaa44c12cefb87e8989034f3342150831f411 Addded http proxy server support. diff -r 59ebaa44c12c -r 2e0b94e12bfc OpenSecurity/bin/opensecurity_tray.pyw --- a/OpenSecurity/bin/opensecurity_tray.pyw Thu Jul 17 10:20:10 2014 +0100 +++ b/OpenSecurity/bin/opensecurity_tray.pyw Fri Jul 18 13:45:09 2014 +0100 @@ -39,6 +39,8 @@ import urllib import urllib2 import webbrowser +import _winreg +import re from PyQt4 import QtCore from PyQt4 import QtGui @@ -105,6 +107,27 @@ d = AboutDialog() d.exec_() + def getProxySettings(self): + aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER) + aKey = _winreg.OpenKey(aReg, r"Software\Microsoft\Windows\CurrentVersion\Internet Settings") + subCount, valueCount, lastModified = _winreg.QueryInfoKey(aKey) + reg_entries = dict() + for i in range(valueCount): + try: + n,v,t = _winreg.EnumValue(aKey,i) + reg_entries[n] = v + except EnvironmentError: + break + _winreg.CloseKey(aKey) + + if 'ProxyEnable' in reg_entries.keys() and reg_entries['ProxyEnable'] == 1: + proxy_search = re.search(r"(?<=http=)(?P.*?)(?=;)", reg_entries['ProxyServer']) + if proxy_search: + proxies = proxy_search.groupdict() + if 'ProxyServer' in proxies.keys(): # found http proxy + return {'ProxyServer': proxies['ProxyServer']} + return {'ProxyServer': reg_entries['ProxyServer']} + return None def clicked_browser(self): """wish for safe internet browsing""" @@ -114,16 +137,22 @@ return try: - # get a proper browsing VM Cygwin.start_X11() # TODO: HARDCODED ADDRESS OF OPENSECURITYD - browsing_vm = urllib2.urlopen('http://127.0.0.1:8080/browsing').readline() - print('Called http://127.0.0.1:8080/browsing got: ' + str(browsing_vm)) - + proxy_support = urllib2.ProxyHandler({}) + opener = urllib2.build_opener(proxy_support) + urllib2.install_opener(opener) + + req_data = "" + proxy = self.getProxySettings() + if proxy: + req_data = '?' + urllib.urlencode(proxy) + req = 'http://127.0.0.1:8080/browsing'+ req_data + browsing_vm = urllib2.urlopen(req).readline() + print('Called '+ req + ' got: ' + str(browsing_vm)) except: - QtGui.QApplication.instance().processEvents() QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error') @@ -218,6 +247,8 @@ self._menu_format.clear() for m in machines: + if u'SecurityDVM0' in m: + continue a = self._menu_format.addAction(m + '\\\\' + machines[m]) a.setIcon(self._icon_network) a.triggered.connect(self.format_drive) diff -r 59ebaa44c12c -r 2e0b94e12bfc OpenSecurity/bin/opensecurityd.pyw --- a/OpenSecurity/bin/opensecurityd.pyw Thu Jul 17 10:20:10 2014 +0100 +++ b/OpenSecurity/bin/opensecurityd.pyw Fri Jul 18 13:45:09 2014 +0100 @@ -97,10 +97,14 @@ """ def GET(self): + args = web.input() log_call(web.ctx.environ) global gvm_mgr try: - result = gvm_mgr.handleBrowsingRequest() + proxy = None + if 'ProxyServer' in args: + proxy = args['ProxyServer'] + result = gvm_mgr.handleBrowsingRequest(proxy) return result except: raise web.internalerror() diff -r 59ebaa44c12c -r 2e0b94e12bfc OpenSecurity/bin/test_vmmanager.pyw --- a/OpenSecurity/bin/test_vmmanager.pyw Thu Jul 17 10:20:10 2014 +0100 +++ b/OpenSecurity/bin/test_vmmanager.pyw Fri Jul 18 13:45:09 2014 +0100 @@ -35,10 +35,12 @@ import unittest import os +import re import os.path import sys import cygwin import vmmanager +import _winreg gvm_mgr = None class TestVMManager(unittest.TestCase): @@ -57,11 +59,43 @@ template = vmmanager.VMManager.getTemplateUUID() self.assertIsNotNone(template, "returned no UUID for template") - #@unittest.skip("skipping (requires running vmmanager)") + @unittest.skip("skipping") def testUpdateTemplate(self): gvm_mgr.updateTemplate() pass + def setKey(self, key, name, value): + _, reg_type = _winreg.QueryValueEx(key, name) + _winreg.SetValueEx(key, name, 0, reg_type, value) + + @unittest.skip("skipping") + def testGetProxySettings(self): + #sudo echo "http_proxy=http://80.122.169.38:8080/" >> /etc/environment + aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER) + aKey = _winreg.OpenKey(aReg, r"Software\Microsoft\Windows\CurrentVersion\Internet Settings") + subCount, valueCount, lastModified = _winreg.QueryInfoKey(aKey) + proxy = dict() + for i in range(valueCount): + try: + n,v,t = _winreg.EnumValue(aKey,i) + proxy[n] = v + except EnvironmentError: + break + _winreg.CloseKey(aKey) + print proxy + if 'ProxyEnable' in proxy.keys() and proxy['ProxyEnable'] == 1: + print proxy['ProxyServer'] + return proxy['ProxyServer'] + else: + return "" + + def testMatchProxy(self): + #http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080 + #212.17.86.109:8080 + text = 'http=212.17.86.109:8080;https=212.17.86.109:8080;ftp=212.17.86.109:8080' + print re.search(r"(?<=http=)(?P.*?)(?=;)", text).groupdict() + print re.search(r"(?<=http=)(.*?)(?=;)", text) + #@classmethod #def tearOffClass(self): # gvm_mgr.stop() diff -r 59ebaa44c12c -r 2e0b94e12bfc OpenSecurity/bin/ui/format_drive_dialog.py --- a/OpenSecurity/bin/ui/format_drive_dialog.py Thu Jul 17 10:20:10 2014 +0100 +++ b/OpenSecurity/bin/ui/format_drive_dialog.py Fri Jul 18 13:45:09 2014 +0100 @@ -35,13 +35,15 @@ import base64 import sys +import urllib +import urllib2 + from PyQt4 import QtCore from PyQt4 import QtGui from ui_FormatDriveDialog import Ui_FormatDriveDialog from about_dialog import AboutDialog - # ------------------------------------------------------------ # code @@ -61,7 +63,7 @@
This is irreversible.

-Please provide an approbitate password and keyfile to proceed: +Please provide an appropriate password or keyfile to proceed: """ % ip # setup the user interface @@ -104,10 +106,10 @@ """Ok button has been clicked.""" - init_data = {} + init_data = dict() # pick the password - init_data['password'] = self.ui.edtPassword.text() + init_data['password'] = str(self.ui.edtPassword.text()) if len(init_data['password']) == 0: QtGui.QMessageBox.critical(self, 'Format error', 'Please specify a password.') return @@ -128,17 +130,19 @@ keyfile_content_base64 = base64.b64encode(keyfile_content) init_data['keyfile'] = keyfile_content_base64 + res = "" try: - req = urllib2.Request('http://' + ip + ':58081/init', urllib.urlencode(init_data)) + req_data = urllib.urlencode(init_data) + req = urllib2.Request('http://' + ip + ':58081/init', req_data) res = urllib2.urlopen(req) except: - print('EXCEPTION') + print('EXCEPTION ' + res) pass self.accept() - def set_user_text(user_text): + def set_user_text(self, user_text): """Set a text to explain which password we need.""" self.ui.lblText.setText(user_text) diff -r 59ebaa44c12c -r 2e0b94e12bfc OpenSecurity/bin/vmmanager.pyw --- a/OpenSecurity/bin/vmmanager.pyw Thu Jul 17 10:20:10 2014 +0100 +++ b/OpenSecurity/bin/vmmanager.pyw Fri Jul 18 13:45:09 2014 +0100 @@ -674,9 +674,9 @@ return network_drives # handles browsing request - def handleBrowsingRequest(self): + def handleBrowsingRequest(self, proxy): showTrayMessage('Starting Secure Browsing...', 7000) - handler = BrowsingHandler(self) + handler = BrowsingHandler(self, proxy) handler.start() return 'ok' @@ -723,14 +723,21 @@ #handles browsing session creation class BrowsingHandler(threading.Thread): vmm = None - def __init__(self, vmmanager): - threading.Thread.__init__(self) - self.vmm = vmmanager + proxy = None + def __init__(self, vmmanager, proxy): + threading.Thread.__init__(self) + self.vmm = vmmanager + self.proxy = proxy def run(self): #browser = '\\\"/usr/bin/chromium; pidof dbus-launch | xargs kill\\\"' - browser = '\\\"/usr/bin/chromium\\\"' + #browser = '\\\"/usr/bin/chromium\\\"' + try: + if self.proxy: + browser = '\\\"export http_proxy='+self.proxy+'; /usr/bin/chromium\\\"' + else: + browser = '\\\"/usr/bin/chromium\\\"' self.vmm.browsingManager.started.wait() result = Cygwin.checkResult(Cygwin.sshExecuteX11(browser, self.vmm.browsingManager.ip_addr, 'osecuser', Cygwin.cygPath(self.vmm.getMachineFolder()) + '/' + self.vmm.browsingManager.vm_name + '/dvm_key')) self.vmm.backupFile('/home/osecuser/.config/chromium', self.vmm.browsingManager.appDataDir + '/OpenSecurity/') @@ -899,7 +906,7 @@ new_sdvm = self.vmm.newSDVM() self.vmm.storageAttach(new_sdvm) self.vmm.startVM(new_sdvm) - new_ip = self.vmm.waitStartup(new_sdvm) + new_ip = self.vmm.waitStartup(new_sdvm, timeout_ms=30000) if new_ip == None: logger.error("Error getting IP address of SDVM. Cleaning up.") self.vmm.poweroffVM(new_sdvm)