def approveHost(hostName): from os.path import expanduser hostsFile = expanduser('~/.udsclient.hosts') try: with open(hostsFile, 'r') as f: approvedHosts = f.read().splitlines() except Exception: approvedHosts = [] hostName = hostName.lower() if hostName in approvedHosts: return True errorString = 'The server {} must be approved:\n'.format(hostName) errorString += 'Only approve UDS servers that you trust to avoid security issues.' approved = ui.question("ACCESS Warning", errorString) if approved: approvedHosts.append(hostName) logger.debug('Host was approved, saving to approvedHosts file') try: with open(hostsFile, 'w') as f: f.write('\n'.join(approvedHosts)) except Exception: logger.warning('Got exception writing to %s', hostsFile) return approved
def approveHost(host): from os.path import expanduser hostsFile = expanduser('~/.udsclient.hosts') try: with open(hostsFile, 'r') as f: approvedHosts = f.read().splitlines() except Exception: approvedHosts = [] host = host.lower() if host in approvedHosts: return True errorString = 'The server {} must be approved:\n'.format(host) errorString += 'Only approve UDS servers that you trust to avoid security issues.' approved = ui.question("ACCESS Warning", errorString) if approved: approvedHosts.append(host) logger.debug('Host was approved, saving to approvedHosts file') try: with open(hostsFile, 'w') as f: f.write('\n'.join(approvedHosts)) except Exception: logger.warn('Got exception writing to {}'.format(hostsFile)) return approved
def transportDataReceived(self, data): logger.debug('Transport data received') try: self.processError(data) params = None if self.serverVersion <= OLD_METHOD_VERSION: script = bz2.decompress(base64.b64decode(data['result'])) # This fixes uds 2.2 "write" string on binary streams on some transport script = script.replace(b'stdin.write("', b'stdin.write(b"') script = script.replace(b'version)', b'version.decode("utf-8"))') else: res = data['result'] # We have three elements on result: # * Script # * Signature # * Script data # We test that the Script has correct signature, and them execute it with the parameters #script, signature, params = res['script'].decode('base64').decode('bz2'), res['signature'], json.loads(res['params'].decode('base64').decode('bz2')) script, signature, params = bz2.decompress( base64.b64decode( res['script'])), res['signature'], json.loads( bz2.decompress(base64.b64decode(res['params']))) if tools.verifySignature(script, signature) is False: logger.error('Signature is invalid') raise Exception( 'Invalid UDS code signature. Please, report to administrator' ) self.stopAnim() if 'darwin' in sys.platform: self.showMinimized() QtCore.QTimer.singleShot(3000, self.endScript) self.hide() six.exec_(script.decode("utf-8"), globals(), { 'parent': self, 'sp': params }) except RetryException as e: self.ui.info.setText(six.text_type(e) + ', retrying access...') # Retry operation in ten seconds QtCore.QTimer.singleShot(10000, self.getTransportData) except Exception as e: #logger.exception('Got exception executing script:') self.showError(e)
def transportDataReceived(self, data): logger.debug('Transport data received') try: self.processError(data) params = None if self.serverVersion <= OLD_METHOD_VERSION: script = data['result'].decode('base64').decode('bz2') else: res = data['result'] # We have three elements on result: # * Script # * Signature # * Script data # We test that the Script has correct signature, and them execute it with the parameters script, signature, params = res['script'].decode( 'base64').decode('bz2'), res['signature'], json.loads( res['params'].decode('base64').decode('bz2')) if tools.verifySignature(script, signature) is False: raise Exception( 'Invalid UDS code signature. Please, report to administrator' ) self.stopAnim() if 'darwin' in sys.platform: self.showMinimized() QtCore.QTimer.singleShot(3000, self.endScript) self.hide() if self.serverVersion <= OLD_METHOD_VERSION: errorString = '<p>The server <b>{}</b> runs an old version of UDS:</p>'.format( host) errorString += '<p>To avoid security issues, you must approve old UDS Version access.</p>' if QtGui.QMessageBox.warning( None, 'ACCESS Warning', errorString, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) == QtGui.QMessageBox.No: raise Exception('Server not approved. Access denied.') six.exec_(script, globals(), {'parent': self, 'sp': params}) except RetryException as e: self.ui.info.setText(six.text_type(e) + ', retrying access...') # Retry operation in ten seconds QtCore.QTimer.singleShot(10000, self.getTransportData) except Exception as e: logger.exception('Got exception executing script:') self.showError(e)
def transportDataReceived(self, data): logger.debug('Transport data received') try: self.processError(data) params = None if self.serverVersion <= OLD_METHOD_VERSION: script = data['result'].decode('base64').decode('bz2') else: res = data['result'] # We have three elements on result: # * Script # * Signature # * Script data # We test that the Script has correct signature, and them execute it with the parameters script, signature, params = res['script'].decode('base64').decode('bz2'), res['signature'], json.loads(res['params'].decode('base64').decode('bz2')) if tools.verifySignature(script, signature) is False: logger.error('Signature is invalid') raise Exception('Invalid UDS code signature. Please, report to administrator') self.stopAnim() if 'darwin' in sys.platform: self.showMinimized() QtCore.QTimer.singleShot(3000, self.endScript) self.hide() # if self.serverVersion <= OLD_METHOD_VERSION: # errorString = '<p>The server <b>{}</b> runs an old version of UDS:</p>'.format(host) # errorString += '<p>To avoid security issues, you must approve old UDS Version access.</p>' # # if QtGui.QMessageBox.warning(None, 'ACCESS Warning', errorString, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) == QtGui.QMessageBox.No: # raise Exception('Server not approved. Access denied.') six.exec_(script, globals(), {'parent': self, 'sp': params}) except RetryException as e: self.ui.info.setText(six.text_type(e) + ', retrying access...') # Retry operation in ten seconds QtCore.QTimer.singleShot(10000, self.getTransportData) except Exception as e: #logger.exception('Got exception executing script:') self.showError(e)
#approved = settings.value(hostName, False).toBool() approved = bool(settings.value(hostName, False)) errorString = '<p>The server <b>{}</b> must be approved:</p>'.format(hostName) errorString += '<p>Only approve UDS servers that you trust to avoid security issues.</p>' if approved or QtWidgets.QMessageBox.warning(parentWindow, 'ACCESS Warning', errorString, QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No) == QtWidgets.QMessageBox.Yes: settings.setValue(hostName, True) approved = True settings.endGroup() return approved if __name__ == "__main__": logger.debug('Initializing connector') # Initialize app app = QtWidgets.QApplication(sys.argv) # Set several info for settings QtCore.QCoreApplication.setOrganizationName('Virtual Cable S.L.U.') QtCore.QCoreApplication.setApplicationName('UDS Connector') if 'darwin' not in sys.platform: logger.debug('Mac OS *NOT* Detected') app.setStyle('plastique') if six.PY3 is False: logger.debug('Fixing threaded execution of commands') import threading
parentWindow, "ACCESS Warning", errorString, QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, ) == QtWidgets.QMessageBox.Yes ): settings.setValue(hostName, True) approved = True settings.endGroup() return approved if __name__ == "__main__": logger.debug("Initializing connector") # Initialize app app = QtWidgets.QApplication(sys.argv) # Set several info for settings QtCore.QCoreApplication.setOrganizationName("Virtual Cable S.L.U.") QtCore.QCoreApplication.setApplicationName("UDS Connector") if "darwin" not in sys.platform: logger.debug("Mac OS *NOT* Detected") app.setStyle("plastique") if six.PY3 is False: logger.debug("Fixing threaded execution of commands") import threading
def getWithRetry(api, url, parameters=None): while True: try: return api.get(url, parameters) except RetryException as e: if ui.question( 'Service not available', 'Error {}.\nPlease, wait a minute and press "OK" to retry, or "CANCEL" to abort' .format(e)) is True: continue raise Exception('Cancelled by user') if __name__ == "__main__": logger.debug('Initializing connector') if six.PY3 is False: logger.debug('Fixing threaded execution of commands') import threading threading._DummyThread._Thread__stop = lambda x: 42 # type: ignore, pylint:disable=protected-access # First parameter must be url try: uri = sys.argv[1] if uri == '--test': sys.exit(0) logger.debug('URI: %s', uri) if uri[:6] != 'uds://' and uri[:7] != 'udss://':
def getWithRetry(rest, url, params=None): while True: try: res = rest.get(url, params) return res except RetryException as e: if ui.question( 'Service not available', 'Error {}.\nPlease, wait a minute and press "OK" to retry, or "CANCEL" to abort' .format(e)) is True: continue raise Exception('Cancelled by user') if __name__ == "__main__": logger.debug('Initializing connector') if six.PY3 is False: logger.debug('Fixing threaded execution of commands') import threading threading._DummyThread._Thread__stop = lambda x: 42 # First parameter must be url try: uri = sys.argv[1] if uri == '--test': sys.exit(0) logger.debug('URI: {}'.format(uri)) if uri[:6] != 'uds://' and uri[:7] != 'udss://':
return approved def getWithRetry(rest, url, params=None): while True: try: res = rest.get(url, params) return res except RetryException as e: if ui.question('Service not available', 'Error {}.\nPlease, wait a minute and press "OK" to retry, or "CANCEL" to abort'.format(e)) is True: continue raise Exception('Cancelled by user') if __name__ == "__main__": logger.debug('Initializing connector') if six.PY3 is False: logger.debug('Fixing threaded execution of commands') import threading threading._DummyThread._Thread__stop = lambda x: 42 # First parameter must be url try: uri = sys.argv[1] if uri == '--test': sys.exit(0) logger.debug('URI: {}'.format(uri)) if uri[:6] != 'uds://' and uri[:7] != 'udss://':
settings.beginGroup('endpoints') approved = settings.value(host, False).toBool() errorString = '<p>The server <b>{}</b> must be approved:</p>'.format(host) errorString += '<p>Only approve UDS servers that you trust to avoid security issues.</p>' if approved or QtGui.QMessageBox.warning(parentWindow, 'ACCESS Warning', errorString, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) == QtGui.QMessageBox.Yes: settings.setValue(host, True) approved = True settings.endGroup() return approved if __name__ == "__main__": logger.debug('Initializing connector') # Initialize app app = QtGui.QApplication(sys.argv) # Set several info for settings QtCore.QCoreApplication.setOrganizationName('Virtual Cable S.L.U.') QtCore.QCoreApplication.setApplicationName('UDS Connector') if 'darwin' not in sys.platform: logger.debug('Mac OS *NOT* Detected') app.setStyle('plastique') if six.PY3 is False: logger.debug('Fixing threaded execution of commands') import threading threading._DummyThread._Thread__stop = lambda x: 42