def on_password_clear_finish(source, result, data): try: password_removed = Secret.password_clear_finish(result) if password_removed: logging.debug('Cleared password for: {}'.format(old_email)) else: logging.debug( 'No password found to clear for: {}'.format(old_email)) except GLib.Error as e: logging.error( 'Failed to clear password for: {}, Error: {}'.format( old_email, e)) if callback: callback(False) else: Secret.password_store( self._account_schema, {'email': new_email}, self._current_collection, 'Pandora Account', password, None, on_password_store_finish, None, )
def store_sync(self, login, password, uid, token, keyB, callback): """ Store Mozilla Sync password @param login as str @param password as str @param uid as str @param token as str @param keyB as str @param callback as function """ try: self.__wait_for_secret(self.store_sync, login, password, uid, token, keyB, callback) schema_string = "org.gnome.Eolie.sync" SecretSchema = { "sync": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, "uid": Secret.SchemaAttributeType.STRING, "token": Secret.SchemaAttributeType.STRING, "keyB": Secret.SchemaAttributeType.STRING } schema = Secret.Schema.new("org.gnome.Eolie", Secret.SchemaFlags.NONE, SecretSchema) SecretAttributes = { "sync": "mozilla", "login": login, "uid": uid, "token": token, "keyB": keyB } Secret.password_store(schema, SecretAttributes, Secret.COLLECTION_DEFAULT, schema_string, password, None, callback) except Exception as e: debug("PasswordsHelper::store_sync(): %s" % e)
def store(self, user_form_name, user_form_value, pass_form_name, pass_form_value, uri, form_uri, uuid, callback, *args): """ Store password @param user_form_name as str @param user_form_value as str @param pass_form_name as str @param pass_form_value as str @param uri as str @param form_uri as str @param uuid as str @param callback as function """ try: self.__wait_for_secret(self.store, user_form_name, user_form_value, pass_form_name, pass_form_value, uri, form_uri, uuid, callback, *args) parsed = urlparse(uri) parsed_form_uri = urlparse(form_uri) schema_string = "org.gnome.Eolie: %s@%s" % (user_form_value, parsed.netloc) SecretSchema = { "type": Secret.SchemaAttributeType.STRING, "uuid": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, "hostname": Secret.SchemaAttributeType.STRING, "formSubmitURL": Secret.SchemaAttributeType.STRING, "userform": Secret.SchemaAttributeType.STRING, "passform": Secret.SchemaAttributeType.STRING, } SecretAttributes = { "type": "eolie web login", "uuid": uuid, "login": user_form_value, "hostname": "%s://%s" % (parsed.scheme, parsed.netloc), "formSubmitURL": "%s://%s" % (parsed_form_uri.scheme, parsed_form_uri.netloc), "userform": user_form_name, "passform": pass_form_name } schema = Secret.Schema.new("org.gnome.Eolie", Secret.SchemaFlags.NONE, SecretSchema) Secret.password_store(schema, SecretAttributes, Secret.COLLECTION_DEFAULT, schema_string, pass_form_value, None, callback) except Exception as e: debug("PasswordsHelper::store(): %s" % e)
def set_account_password(self, old_email: str, new_email: str, password: str) -> Awaitable[bool]: future = asyncio.Future() # type: asyncio.Future def on_password_store_finish(source, result, data): try: success = Secret.password_store_finish(result) except GLib.Error as e: future.set_exception(e) future.set_result(success) def on_password_clear_finish(source, result, data): try: password_removed = Secret.password_clear_finish(result) if password_removed: logging.debug('Cleared password for: {}'.format(old_email)) else: logging.debug( 'No password found to clear for: {}'.format(old_email)) except GLib.Error as e: future.set_exception(e) else: Secret.password_store( self._account_schema, {'email': new_email}, self._current_collection, 'Pandora Account', password, None, on_password_store_finish, None, ) if old_email and old_email != new_email: Secret.password_clear( self._account_schema, {'email': old_email}, None, on_password_clear_finish, None, ) else: Secret.password_store( self._account_schema, {'email': new_email}, self._current_collection, 'Pandora Account', password, None, on_password_store_finish, None, ) return future
def set_credentials(self, username, password): def stored(source, result, data): if not Secret.password_store_finish(result): logger.error('Could not store password into keyring') attrs = {'app': 'trifle', 'user': username} Secret.password_store(SCHEMA, attrs, None, 'Trifle password', password, None, stored, None) super(SecretKeyring, self).set_credentials(username, password) return True
def set_account_password(self, old_email, new_email, password, callback): def on_password_store_finish(source, result, data): try: success = Secret.password_store_finish(result) except GLib.Error as e: logging.error('Failed to store password, Error: {}'.format(e)) success = False if callback: callback(success) def on_password_clear_finish(source, result, data): try: password_removed = Secret.password_clear_finish(result) if password_removed: logging.debug('Cleared password for: {}'.format(old_email)) else: logging.debug('No password found to clear for: {}'.format(old_email)) except GLib.Error as e: logging.error('Failed to clear password for: {}, Error: {}'.format(old_email, e)) if callback: callback(False) else: Secret.password_store( self._account_schema, {'email': new_email}, self._current_collection, 'Pandora Account', password, None, on_password_store_finish, None, ) if old_email and old_email != new_email: Secret.password_clear( self._account_schema, {'email': old_email}, None, on_password_clear_finish, None, ) else: Secret.password_store( self._account_schema, {'email': new_email}, self._current_collection, 'Pandora Account', password, None, on_password_store_finish, None, )
def __connect_mozilla_sync(self, login, password, label, image): """ Connect to mozilla sync @param login as str @param password as str @param label as Gtk.Label @param image as Gtk.Image @thread safe """ from eolie.mozilla_sync import MozillaSync from gi.repository import Secret import base64 try: self.__client = MozillaSync() session = self.__client.login(login, password) bid_assertion, key = self.__client.get_browserid_assertion(session) schema_string = "org.gnome.Eolie.sync" keyB = base64.b64encode(session.keys[1]).decode("utf-8") SecretSchema = { "sync": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, "uid": Secret.SchemaAttributeType.STRING, "token": Secret.SchemaAttributeType.STRING, "keyB": Secret.SchemaAttributeType.STRING } SecretAttributes = { "sync": "mozilla", "login": login, "uid": session.uid, "token": session.token, "keyB": keyB } schema = Secret.Schema.new("org.gnome.Eolie", Secret.SchemaFlags.NONE, SecretSchema) Secret.password_store(schema, SecretAttributes, Secret.COLLECTION_DEFAULT, schema_string, password, None, self.__on_password_stored) GLib.idle_add(label.set_text, _("Sync started")) GLib.idle_add(image.set_from_icon_name, "network-transmit-receive-symbolic", Gtk.IconSize.MENU) except Exception as e: if str(e) == "Unverified account": GLib.idle_add( label.set_text, _("You've received an email" " to validate synchronization")) GLib.idle_add(image.set_from_icon_name, "mail-unread-symbolic", Gtk.IconSize.MENU) else: GLib.idle_add(label.set_text, str(e)) GLib.idle_add(image.set_from_icon_name, "computer-fail-symbolic", Gtk.IconSize.MENU)
def set_token(self, token, username, email, uuid): self._settings.set_string("user-uuid", uuid) Secret.password_store( Secret.Schema.new( "nl.g4d.Girens", Secret.SchemaFlags.NONE, { 'username': Secret.SchemaAttributeType.STRING, 'email': Secret.SchemaAttributeType.STRING, 'uuid': Secret.SchemaAttributeType.STRING }), { 'username': username, 'email': email, 'uuid': uuid }, Secret.COLLECTION_DEFAULT, 'Girens token', token, None, None)
def store(self, user_form_name, user_form_value, pass_form_name, pass_form_value, hostname_uri, form_uri, uuid, callback, *args): """ Store password @param user_form_name as str @param user_form_value as str @param pass_form_name as str @param pass_form_value as str @param hostname_uri as str @param form_uri as str @param uuid as str @param callback as function """ # seems to happen, thanks firefox if form_uri is None: return try: self.__wait_for_secret(self.store, user_form_name, user_form_value, pass_form_name, pass_form_value, hostname_uri, form_uri, uuid, callback, *args) schema_string = "org.gnome.Eolie: %s > %s" % (user_form_value, hostname_uri) SecretSchema = { "type": Secret.SchemaAttributeType.STRING, "uuid": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, "hostname": Secret.SchemaAttributeType.STRING, "formSubmitURL": Secret.SchemaAttributeType.STRING, "userform": Secret.SchemaAttributeType.STRING, "passform": Secret.SchemaAttributeType.STRING, } SecretAttributes = { "type": "eolie web login", "uuid": uuid, "login": user_form_value, "hostname": hostname_uri, "formSubmitURL": form_uri, "userform": user_form_name, "passform": pass_form_name } schema = Secret.Schema.new("org.gnome.Eolie", Secret.SchemaFlags.NONE, SecretSchema) Secret.password_store(schema, SecretAttributes, Secret.COLLECTION_DEFAULT, schema_string, pass_form_value, None, callback) except Exception as e: Logger.debug("PasswordsHelper::store(): %s", e)
def set_smtp_password(server, username, password): schema = Secret.get_schema(Secret.SchemaType.COMPAT_NETWORK) attrs = dict(user=username, server=server, protocol='smtp') label = '{user}@{server}'.format_map(attrs) def callback(source, result): if not Secret.password_store_finish(result): log.error(_("Failed to store SMTP password in the keyring.")) else: log.debug("SMTP password stored in the keyring.") log.debug("Storing the SMTP password for %s in the keyring.", label) Secret.password_store(schema, attrs, collection=Secret.COLLECTION_DEFAULT, label=label, password=password, cancellable=None, callback=callback)
def set_server_token(self, token, server_url, server_uuid, name): self._settings.set_string("server-url", self._server._baseurl) self._settings.set_string("server-uuid", self._server.machineIdentifier) Secret.password_store( Secret.Schema.new( "nl.g4d.Girens", Secret.SchemaFlags.NONE, { 'name': Secret.SchemaAttributeType.STRING, 'url': Secret.SchemaAttributeType.STRING, 'uuid': Secret.SchemaAttributeType.STRING }), { 'name': name, 'url': server_url, 'uuid': server_uuid }, Secret.COLLECTION_DEFAULT, 'Girens server token', token, None, None)
def testAsynchronous(self): attributes = { "number": "888", "string": "eight", "even": "true" } password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None) self.assertEqual(None, password); loop = GLib.MainLoop(None) def on_result_ready(source, result, unused): loop.quit() stored = Secret.password_store_finish(result) self.assertEquals(True, stored) Secret.password_store(STORE_SCHEMA, attributes, None, "The number eight", "888", None, on_result_ready, None) loop.run() password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None) self.assertEqual("888", password)
def testAsynchronous(self): attributes = { "number": "888", "string": "eight", "even": "true" } password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None) self.assertEqual(None, password); loop = GLib.MainLoop(None, False) def on_result_ready(source, result, unused): loop.quit() stored = Secret.password_store_finish(result) self.assertEquals(True, stored) Secret.password_store(STORE_SCHEMA, attributes, None, "The number eight", "888", None, on_result_ready, None) loop.run() password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None) self.assertEqual("888", password)
def save_to_keyring(self, uri, username, password): schema = Secret.get_schema(Secret.SchemaType.COMPAT_NETWORK) attrs = dict(server=uri.get_host(), protocol=uri.get_scheme(), port=str(uri.get_port()), user=username) label = '{user}@{server}:{port}'.format_map(attrs) def password_stored_callback(source, result): if not Secret.password_store_finish(result): log.error(_("Failed to store HTTP password in the keyring.")) else: log.debug("HTTP password stored in the keyring.") log.debug("Storing the HTTP password for %s in the keyring.", label) Secret.password_store( schema, attrs, collection=Secret.COLLECTION_DEFAULT, label=label, password=password, cancellable=None, callback=password_stored_callback, )
def store(self, login, password, uri, uuid, callback): """ Store password @param login as str @param password as str @param uri as str @param uuid as str @param callback as function """ try: self.__wait_for_secret(self.store, login, password, uri, callback) parsed = urlparse(uri) schema_string = "org.gnome.Eolie: %s@%s" % (login, parsed.netloc) SecretSchema = { "type": Secret.SchemaAttributeType.STRING, "uuid": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, "hostname": Secret.SchemaAttributeType.STRING, "formSubmitURL": Secret.SchemaAttributeType.STRING } SecretAttributes = { "type": "eolie web login", "uuid": uuid, "login": login, "hostname": parsed.netloc, "formSubmitURL": "%s://%s%s" % (parsed.scheme, parsed.netloc, parsed.path) } schema = Secret.Schema.new("org.gnome.Eolie", Secret.SchemaFlags.NONE, SecretSchema) Secret.password_store(schema, SecretAttributes, Secret.COLLECTION_DEFAULT, schema_string, password, None, callback) except Exception as e: debug("PasswordsHelper::store(): %s" % e)
def store(self, service, login, password, callback, *args): """ Store password @param service as str @param login as str @param password as str @param callback as function """ try: self.__wait_for_secret(self.store, service, login, password, callback, *args) schema_string = f'{SECRET_SCHEMA_NAME}: {service}@{login}' SecretSchema = { "service": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, } attributes = { "service": service, "login": login } schema = Secret.Schema.new(SECRET_SCHEMA_NAME, Secret.SchemaFlags.NONE, SecretSchema) Secret.password_store(schema, attributes, Secret.COLLECTION_DEFAULT, schema_string, password, None, callback, *args) except Exception as e: logger.debug("SecretAccountHelper::store(): %s", e)
def store(self, service, login, password, callback, *args): """ Store password @param service as str @param login as str @param password as str @param callback as function """ try: self.__wait_for_secret(self.store, service, login, password, callback, *args) schema_string = "org.gnome.Lollypop: %s@%s" % (service, login) SecretSchema = { "service": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, } SecretAttributes = {"service": service, "login": login} schema = Secret.Schema.new("org.gnome.Lollypop", Secret.SchemaFlags.NONE, SecretSchema) Secret.password_store(schema, SecretAttributes, Secret.COLLECTION_DEFAULT, schema_string, password, None, callback, *args) except Exception as e: Logger.debug("PasswordsHelper::store(): %s" % e)
def _on_save_clicked(self, button): """ Save username and password @param button as Gtk.Button """ try: schema_string = "org.gnome.Eolie: %s@%s" % (self.__username, self.__netloc) if self.__secret_item is None: SecretSchema = { "type": Secret.SchemaAttributeType.STRING, "uri": Secret.SchemaAttributeType.STRING, "login": Secret.SchemaAttributeType.STRING, } SecretAttributes = { "type": "eolie web login", "uri": self.__netloc, "login": self.__username } schema = Secret.Schema.new("org.gnome.Eolie", Secret.SchemaFlags.NONE, SecretSchema) Secret.password_store(schema, SecretAttributes, Secret.COLLECTION_DEFAULT, schema_string, self.__password, None, None) else: value = Secret.Value.new(self.__password, len(self.__password), "") self.__secret_item.set_secret(value, None, None) self.__secret_item.set_label(schema_string, None, None) self.destroy() except Exception as e: print("PasswordPopover::_on_save_clicked()", e)
def store_refresh_token(self, token): Secret.password_store(self.SECRET_SCHEMA, {}, None, "refresh_token", token, None, None, None)
def storeUser(self, username, password, callback=None): Secret.password_store(self.SCHEMA, self.KEY, Secret.COLLECTION_DEFAULT, "MHGUI", json.dumps([username, password]), None, self._finishStore, callback)