def __init__(self): Tkinter.Tk.__init__(self) self.kpconf = Conf() self._success = False self.setup_frame_1() self.title("Enter the passphrase for %s" % self.kpconf.backend.database_path)
def process(self): kpconf = Conf() new_client_id = kpconf.get_selected_ui().RequireAssociationDecision.require_client_name() if new_client_id: kpconf.backend.create_config_key(new_client_id, self.request_dict["Key"]) self.response_dict.update({"Id": new_client_id, "Success": True}) self.set_verifier(new_client_id)
def main(): # avoid: UnboundLocalError: local variable '__doc__' referenced before assignment doc_ = __doc__ kpconf = Conf() if has_gui_support(): doc_ += " --gui".ljust(28) + "Use QT (PySide) for a graphical interface" # handle arguments arguments = docopt.docopt(doc_) is_daemon = arguments["--daemon"] database_path = arguments["<database_path>"] host = arguments["--host"] port = arguments["--port"] assert port.isdigit() loglevel = arguments["--loglevel"] gui = arguments.get("--gui", False) if gui: ui = Conf.UI.GUI else: ui = Conf.UI.CLI kpconf.select_ui(ui) kpconf.set_loglevel(loglevel) if not has_gui_support(): log.debug("\nIt seems that you don't have GUI support installed. Install it with:\n" " $ pip install -e '.[GUI]'\n" "or\n" " $ pip install keepass_http[GUI]\n") # backend backend = backends.BaseBackend.get_by_filepath(database_path) kpconf.set_backend(backend) success = kpconf.get_selected_ui().RequireDatabasePassphraseUi.do(MAX_TRY_COUNT) if success is False: sys.exit("Wrong or no passphrase") # config daemon run_server = partial(app.run, debug=False, host=host, port=int(port)) if is_daemon: pid_file = os.path.join(kpconf.confdir, "process.pid") log.info("Server started as daemon on %s:%s" % (host, port)) daemon = daemonize.Daemonize(app=APP_NAME, pid=pid_file, action=run_server, keep_fds=get_logging_filehandlers_streams_to_keep()) daemon.start() else: log.info("Server started on %s:%s" % (host, port)) run_server()
def process(self): try: self.authenticate() except AuthenticationError as unused_e: return url = self.kpc.decrypt(self.request_dict['Url']) url = url.decode("utf-8") entries = Conf().backend.search_entries("url", url) self.response_dict.update({"Success": True, "Count": len(entries)})
def try_authenticate(self, *args): passphrase = self.ui.passphrase.text() try: Conf().backend.open_database(passphrase) except WrongPassword: statusbar = self.ui.statusBar() msg = "Wrong passphrase, try again please." statusbar.showMessage(msg) log.warning(msg) else: log.info("Passphrase %s accepted" % ("*" * len(passphrase))) self._exit(True)
def process(self): try: self.authenticate() except AuthenticationError as unused_e: return url = self.kpc.decrypt(self.request_dict['SubmitUrl']) login = self.kpc.decrypt(self.request_dict['Login']) password = self.kpc.decrypt(self.request_dict['Password']) Conf().backend.create_login(self.get_client_id(), login, password, url) self.response_dict.update({"Success": True})
def test_get_backend_by_mimetype(): Conf() assert isinstance(BaseBackend.get_by_filepath("foo.kdb"), python_keepass_backend.Backend) assert isinstance(BaseBackend.get_by_filepath("foo.kdbx"), libkeepass_backend.Backend) with pytest.raises(NoBackendError): BaseBackend.get_by_filepath("eggs.kdbfx") with pytest.raises(NoBackendError): BaseBackend.get_by_filepath("/tmp/foo.gif")
def main(): # avoid: UnboundLocalError: local variable '__doc__' referenced before assignment doc_ = __doc__ kpconf = Conf() if has_gui_support(): doc_ += " --gui Use TKinter for a graphical interface" # handle arguments arguments = docopt.docopt(doc_) is_daemon = arguments["--daemon"] database_path = arguments["<database_path>"] host = arguments["--host"] port = arguments["--port"] assert port.isdigit() loglevel = arguments["--loglevel"] gui = arguments.get("--gui", False) if gui: ui = Conf.UI.GUI else: ui = Conf.UI.CLI kpconf.select_ui(ui) kpconf.set_loglevel(loglevel) # backend backend = backends.BaseBackend.get_by_filepath(database_path) kpconf.set_backend(backend) success = kpconf.get_selected_ui().OpenDatabase.open(MAX_TRY_COUNT) if success is False: sys.exit("Wrong passphrase after %d attempts" % MAX_TRY_COUNT) # config daemon run_server = partial(app.run, debug=False, host=host, port=int(port)) if is_daemon: pid_file = os.path.join(kpconf.confdir, "process.pid") log.info("Server started as daemon on %s:%s" % (host, port)) daemon = daemonize.Daemonize( app=APP_NAME, pid=pid_file, action=run_server, keep_fds=get_logging_filehandlers_streams_to_keep()) daemon.start() else: log.info("Server started on %s:%s" % (host, port)) run_server()
def set_verifier(self, new_client_id=None): if new_client_id: client_id = new_client_id key = Conf().backend.get_key_for_client(client_id) if not key: raise AuthenticationError() else: client_id = self.get_client_id() key = self.kpc.get_key() nonce = AESCipher.generate_nonce() response_kpc = AESCipher(key, nonce) self.response_dict.update({"Nonce": nonce, "Verifier": response_kpc.encrypt(nonce)}) self.set_response_kpc = response_kpc
def process(self): try: self.authenticate() except AuthenticationError as unused_e: return url = str(self.kpc.decrypt(self.request_dict['Url'])) url = urlparse(url).netloc url = url.decode("utf-8") entries = [] for entry in Conf().backend.search_entries("url", url): json_entry = entry.to_json_dict(self.response_kpc) entries.append(json_entry) self.response_dict.update({"Success": True, "Id": self.get_client_id(), "Entries": entries})
def open(max_try_count): kpconf = Conf() try_count = 1 success = False while try_count <= max_try_count: passphrase = getpass.getpass("Please enter the passphrase for database %s: \n" % kpconf.backend.database_path) try: kpconf.backend.open_database(passphrase) except backends.WrongPassword: log.info("Wrong passphrase, please try again. (attempt [%s/%s]" % (try_count, max_try_count)) try_count += 1 else: success = True log.info("Passphrase accepted") break return success
def authenticate(self): client_id = self.get_client_id() log.info("Authenticate client %s" % client_id) key = Conf().backend.get_key_for_client(client_id) # FIXME: Fix unit tests # Special case when methods used in unit test are not mocked correctly. # <TestAES name='AESCipher().key' id='25131856'> is not None :S if key is None or not isinstance(key, basestring): raise AuthenticationError() nonce = self.request_dict['Nonce'] verifier = self.request_dict['Verifier'] kpc = AESCipher(key, nonce) # wrong saved key in database -> force associate if not kpc.is_valid(nonce, verifier): raise InvalidAuthentication() self.set_kpc = kpc self.set_verifier()