Example #1
0
 def connect(self, password):
     """
         Connect lastfm
         @param password as str/None
     """
     if self._goa:
         t = Thread(target=self._connect, args=('', '', True))
         t.daemon = True
         t.start()
     # Get username/password from GSettings/Secret
     elif Secret is not None and\
             Gio.NetworkMonitor.get_default().get_network_available():
         self._username = Lp().settings.get_value(
                                                'lastfm-login').get_string()
         if password is None:
             schema = Secret.Schema.new("org.gnome.Lollypop",
                                        Secret.SchemaFlags.NONE,
                                        SecretSchema)
             Secret.password_lookup(schema, SecretAttributes, None,
                                    self._on_password_lookup)
         else:
             t = Thread(target=self._connect, args=(self._username,
                                                    password, True))
             t.daemon = True
             t.start()
Example #2
0
def keyring_store(api_key, lab_id, collection):
    '''
    Stores your HTB API key and your HTB VPN lab identifier inside the gnomekeyring.

    Parameters:
        api_key             (string)                HTB API key.
        lab_id              (string)                HTB VPN lab identifier.
        collection          (Secret.Collection)     Keyring where the secrets are stored

    Returns:
        boolean             (boolean)               True or False.
    '''
    HTB = Secret.Schema.new("htb.api.Store", Secret.SchemaFlags.NONE,
                            {"name": Secret.SchemaAttributeType.STRING})

    collection_path = '/org/freedesktop/secrets/collection/' + collection.get_label(
    )
    result = Secret.password_store_sync(HTB, {"name": "htb_api_key"},
                                        collection_path, "HTB API Key",
                                        api_key, None)
    result2 = Secret.password_store_sync(HTB, {"name": "htb_vpn_lab"},
                                         collection_path, "HTB VPN LAB",
                                         lab_id, None)

    return result and result2
Example #3
0
 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)
Example #4
0
def set_account_password(email, password):
    attrs = {"email": email}
    if password:
        Secret.password_store_sync(_ACCOUNT_SCHEMA, attrs, Secret.COLLECTION_DEFAULT,
                                    "Pandora Account", password, None)
    else:
        Secret.password_clear_sync(_ACCOUNT_SCHEMA, attrs, None)
Example #5
0
 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,
         )
Example #6
0
 def store(self, key, secret):
     """store in libsecret"""
     super()._check_store(key, secret)
     Secret = self._Secret
     Secret.password_store_sync(self._secret_schema, {'key': key},
                                Secret.COLLECTION_DEFAULT,
                                "tpacheck: {}".format(key), secret, None)
    def insert(secret_id, provider, username, token):
        """
        Save a secret OTP token.

        :param secret_id: The secret ID associated to the OTP token
        :param provider: the provider name
        :param username: the username
        :param token: the secret OTP token.


        """
        schema = Keyring.get_default().schema

        data = {
            "id": str(secret_id),
            "name": str(username),
        }
        Secret.password_store_sync(
            schema,
            data,
            Secret.COLLECTION_DEFAULT,
            "{provider} OTP ({username})".format(
                provider=provider, username=username),
            token,
            None
        )
Example #8
0
 def delete_password(self, service, username):
     """Delete the stored password (only the first one)"""
     attributes = {
         "application": self.appid,
         "service": service,
         "username": username,
     }
     try:
         items = Secret.password_search_sync(self.schema, attributes,
                                             Secret.SearchFlags.UNLOCK,
                                             None)
     except GLib.Error as error:
         quark = GLib.quark_try_string('g-io-error-quark')
         if error.matches(quark, Gio.IOErrorEnum.FAILED):
             raise KeyringLocked('Failed to unlock the item!') from error
         raise
     for item in items:
         try:
             removed = Secret.password_clear_sync(self.schema,
                                                  item.get_attributes(),
                                                  None)
         except GLib.Error as error:
             quark = GLib.quark_try_string('secret-error')
             if error.matches(quark, Secret.Error.IS_LOCKED):
                 raise KeyringLocked(
                     'Failed to unlock the item!') from error
             raise
         return removed
     raise PasswordDeleteError("No such password!")
Example #9
0
 def _update_lastfm_settings(self, sync=False):
     """
         Update lastfm settings
         @param sync as bool
     """
     try:
         if Lp().lastfm is not None and Secret is not None:
             schema = Secret.Schema.new("org.gnome.Lollypop",
                                        Secret.SchemaFlags.NONE,
                                        SecretSchema)
             Secret.password_store_sync(schema, SecretAttributes,
                                        Secret.COLLECTION_DEFAULT,
                                        "org.gnome.Lollypop"
                                        ".lastfm.login %s" %
                                        self.__login.get_text(),
                                        self.__password.get_text(),
                                        None)
             Lp().settings.set_value('lastfm-login',
                                     GLib.Variant('s',
                                                  self.__login.get_text()))
             if sync:
                 Lp().lastfm.connect_sync(self.__password.get_text())
             else:
                 Lp().lastfm.connect(self.__password.get_text())
     except Exception as e:
         print("Settings::_update_lastfm_settings(): %s" % e)
def erase():
    attributes = get_attributes()

    if 'password' in attributes:
        del attributes['password']

    Secret.password_clear_sync(GIT_CREDENTIALS_SCHEMA, attributes, None)
Example #11
0
 def connect(self, password):
     """
         Connect lastfm
         @param password as str/None
     """
     if self.__goa is not None:
         t = Thread(target=self.__connect, args=('', '', True))
         t.daemon = True
         t.start()
     # Get username/password from GSettings/Secret
     elif Secret is not None and\
             get_network_available():
         self.__username = Lp().settings.get_value(
                                                'lastfm-login').get_string()
         if password is None:
             schema = Secret.Schema.new("org.gnome.Lollypop",
                                        Secret.SchemaFlags.NONE,
                                        SecretSchema)
             Secret.password_lookup(schema, SecretAttributes, None,
                                    self.__on_password_lookup)
         else:
             t = Thread(target=self.__connect, args=(self.__username,
                                                     password, True))
             t.daemon = True
             t.start()
Example #12
0
 def _update_lastfm_settings(self, sync=False):
     """
         Update lastfm settings
         @param sync as bool
     """
     try:
         if Lp().lastfm is not None and Secret is not None:
             schema = Secret.Schema.new("org.gnome.Lollypop",
                                        Secret.SchemaFlags.NONE,
                                        SecretSchema)
             Secret.password_store_sync(schema, SecretAttributes,
                                        Secret.COLLECTION_DEFAULT,
                                        "org.gnome.Lollypop"
                                        ".lastfm.login %s" %
                                        self.__login.get_text(),
                                        self.__password.get_text(),
                                        None)
             Lp().settings.set_value("lastfm-login",
                                     GLib.Variant("s",
                                                  self.__login.get_text()))
             if sync:
                 Lp().lastfm.connect_sync(self.__password.get_text())
             else:
                 Lp().lastfm.connect(self.__password.get_text())
     except Exception as e:
         print("Settings::_update_lastfm_settings(): %s" % e)
Example #13
0
 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)
Example #14
0
def set_account_password(email, password):
    attrs = {"email": email}
    if password:
        Secret.password_store_sync(_ACCOUNT_SCHEMA, attrs,
                                   Secret.COLLECTION_DEFAULT,
                                   "Pandora Account", password, None)
    else:
        Secret.password_clear_sync(_ACCOUNT_SCHEMA, attrs, None)
Example #15
0
	def testSynchronous(self):
		attributes = { "number": "1", "string": "one", "even": "false" }

		password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual("111", password)

		deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual(True, deleted)
Example #16
0
	def testSyncNotFound(self):
		attributes = { "number": "11", "string": "one", "even": "true" }

		password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual(None, password)

		deleted = Secret.password_remove_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual(False, deleted)
Example #17
0
 def set_password(self, password: str):
     schema = self.password_schema
     # Clear old password
     self.remove_password()
     # Store the new one
     Secret.password_store_sync(schema, {}, Secret.COLLECTION_DEFAULT,
                                "Authenticator password", password, None)
     self.set_password_state(True)
Example #18
0
 def set_password_state(self, state: bool):
     schema = self.password_state_schema
     if not state:
         Secret.password_clear_sync(schema, {}, None)
     else:
         Secret.password_store_sync(schema, {}, Secret.COLLECTION_DEFAULT,
                                    "Authenticator state", "true", None)
     self.props.can_be_locked = state and self.has_password()
Example #19
0
    def testSynchronous(self):
        attributes = {"number": "1", "string": "one", "even": "false"}

        password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
        self.assertEqual("111", password)

        deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
        self.assertEqual(True, deleted)
Example #20
0
    def testSyncNotFound(self):
        attributes = {"number": "11", "string": "one", "even": "true"}

        password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
        self.assertEqual(None, password)

        deleted = Secret.password_clear_sync(STORE_SCHEMA, attributes, None)
        self.assertEqual(False, deleted)
Example #21
0
    def get_refresh_token(self, callback, user_data=None):
        def secret_callback(source_object, result, user_data):
            print("looked up in secret")
            self._token_cache = Secret.password_lookup_finish(result)
            print("lookup finish")
            callback(self._token_cache, user_data)

        Secret.password_lookup(self.SECRET_SCHEMA, {}, None, secret_callback,
                               user_data)
        print("lookup in secret")
Example #22
0
    def setTokens(self, user, access_token, refresh_token):
        attributes = {
            "user": user,
            "scope": self.scope,
        }

        Secret.password_store_sync(
            self.TOKEN_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
            "Mail access to %s for %s" % (self.scope, user),
            self.encodeTokens(access_token, refresh_token), None)
Example #23
0
 def store_password(self, scheme, host, username, password):
     """Return the password of username@root."""
     template = dict(zip(self.category, (scheme, host, username)))
     self.clear_password(scheme, host, username)
     try:
         Secret.password_store_sync(self.schema, template,
                                    Secret.COLLECTION_DEFAULT, host,
                                    password, None)
     except Secret.SECRET_ERROR_PROTOCOL:
         pass
Example #24
0
 def add_session(self, session):
     sessions = self.get_sessions()
     if not sessions:
         sessions = session
     else:
         sessions += f'][{session}'
     Secret.password_store_sync(SESSION_SCHEMA, {'name': 'session'},
                                Secret.COLLECTION_DEFAULT, 'session',
                                sessions, None)
     print(self.get_sessions())
Example #25
0
 def insert(id_, secret_code):
     """
     Insert a secret code to Keyring database
     :param id_: the encrypted id
     :param secret_code: the secret code
     """
     schema = Keyring.get_default().schema
     Secret.password_store_sync(schema, {
         "id": str(id_),
     }, Secret.COLLECTION_DEFAULT, "", secret_code, None)
Example #26
0
 def store_password(self, scheme, host, username, password):
     """Return the password of username@root."""
     template = dict(zip(self.category, (scheme, host, username)))
     self.clear_password(scheme, host, username)
     try:
         Secret.password_store_sync(
             self.schema, template, Secret.COLLECTION_DEFAULT, host,
             password, None)
     except Secret.SECRET_ERROR_PROTOCOL:
         pass
Example #27
0
    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 erase():
    attributes = get_attributes()

    if 'password' in attributes:
        del attributes['password']

    Secret.password_clear_sync(
            GIT_CREDENTIALS_SCHEMA,
            attributes,
            None
            )
Example #29
0
def get_password(attributes):
    password = Secret.password_lookup_sync(SCHEMA, attributes, None)
    if password is None:
        from getpass import getpass
        password = getpass(
            'Password for \'{user}\' @ <{url}>:'.format(**attributes))
    Secret.password_store_sync(
        SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
        'WebDesk for \'{user}\' @ <{url}?'.format(**attributes), password,
        None)
    return password
Example #30
0
    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
Example #31
0
    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,
            )
Example #32
0
	def testValueGet(self):
		Secret.password_store_sync(EXAMPLE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
		                           'the label', 'the password', None)

		service = SecretUnstable.Service.get_sync(SecretUnstable.ServiceFlags.NONE, None)
		items = service.search_sync(EXAMPLE_SCHEMA, { 'even': 'true' },
		                                   SecretUnstable.SearchFlags.ALL | SecretUnstable.SearchFlags.LOAD_SECRETS,
		                                   None)

		item = items[0]
		item_secret = item.get_secret()
		self.assertEqual(item_secret.get(), "the password")
Example #33
0
def set_password(label, password, username, notes=None, url=None):
    attributes = {}
    if username is not None:
        attributes[SCHEMA_USERNAME_KEY] = username
    if notes is not None:
        attributes[SCHEMA_NOTES_KEY] = notes
    if url is not None:
        attributes[SCHEMA_URL_KEY] = url

    Secret.password_store_sync(EXAMPLE_SCHEMA, attributes,
                               Secret.COLLECTION_DEFAULT, label, password,
                               None)
Example #34
0
 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)
Example #35
0
    def setTokens(self, user, access_token, refresh_token):
        attributes = {
                         "user": user,
                         "scope": self.scope,
                     }

        Secret.password_store_sync(self.TOKEN_SCHEMA, attributes,
                          Secret.COLLECTION_DEFAULT,
                          "Mail access to %s for %s" % (self.scope, user),
                          self.encodeTokens(access_token, refresh_token),
                          None
                     )
Example #36
0
	def testSynchronous(self):
		attributes = { "number": "9", "string": "nine", "even": "false" }

		password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual(None, password)

		stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
		                                    "The number nine", "999", None)
		self.assertEqual(True, stored);

		password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual("999", password)
Example #37
0
	def testAsyncNotFound(self):
		loop = GLib.MainLoop(None)

		def on_result_ready(source, result, unused):
			loop.quit()
			password = Secret.password_lookup_finish(result)
			self.assertEquals(None, password)

		Secret.password_lookup (STORE_SCHEMA, { "number": "7", "string": "five" },
		                        None, on_result_ready, None)

		loop.run()
Example #38
0
	def testSynchronous(self):
		attributes = { "number": "9", "string": "nine", "even": "false" }

		password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual(None, password)

		stored = Secret.password_store_sync(STORE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
		                                    "The number nine", "999", None)
		self.assertEqual(True, stored);

		password = Secret.password_lookup_sync(STORE_SCHEMA, attributes, None)
		self.assertEqual("999", password)
	def testAsynchronous(self):
		loop = GLib.MainLoop(None)

		def on_result_ready(source, result, unused):
			loop.quit()
			password = Secret.password_lookup_finish(result)
			self.assertEquals("222", password)

		Secret.password_lookup (STORE_SCHEMA, { "number": "2", "string": "two" },
		                        None, on_result_ready, None)

		loop.run()
Example #40
0
	def testAsynchronous(self):
		loop = GLib.MainLoop(None, False)

		def on_result_ready(source, result, unused):
			loop.quit()
			deleted = Secret.password_remove_finish(result)
			self.assertEquals(True, deleted)

		Secret.password_remove(STORE_SCHEMA, { "number": "2", "string": "two" },
		                       None, on_result_ready, None)

		loop.run()
Example #41
0
	def testAsyncNotFound(self):
		loop = GLib.MainLoop(None, False)

		def on_result_ready(source, result, unused):
			loop.quit()
			password = Secret.password_lookup_finish(result)
			self.assertEquals(None, password)

		Secret.password_lookup (STORE_SCHEMA, { "number": "7", "string": "five" },
		                        None, on_result_ready, None)

		loop.run()
def store():

    attributes = get_attributes()
    if 'password' in attributes:
        password = attributes['password']
        del attributes['password']
    else:
        sys.exit(1)
    Secret.password_store_sync(
        GIT_CREDENTIALS_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
        "%s://%s@%s" %
        (attributes['protocol'], attributes['username'], attributes['host']),
        password, None)
Example #43
0
    def testAsynchronous(self):
        loop = GLib.MainLoop(None, False)

        def on_result_ready(source, result, unused):
            loop.quit()
            password = Secret.password_lookup_finish(result)
            self.assertEquals("222", password)

        Secret.password_lookup(STORE_SCHEMA, {
            "number": "2",
            "string": "two"
        }, None, on_result_ready, None)

        loop.run()
Example #44
0
    def testAsynchronous(self):
        loop = GLib.MainLoop(None)

        def on_result_ready(source, result, unused):
            loop.quit()
            deleted = Secret.password_clear_finish(result)
            self.assertEquals(True, deleted)

        Secret.password_clear(STORE_SCHEMA, {
            "number": "2",
            "string": "two"
        }, None, on_result_ready, None)

        loop.run()
Example #45
0
 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)
Example #46
0
def set_account_password(email, password, previous_email=None):
    if previous_email and previous_email != email:
        if not _clear_account_password(previous_email):
            logging.warning('Failed to clear previous account')

    if not password:
        return _clear_account_password(email)

    attrs = {"email": email}
    if password == get_account_password(email):
        logging.debug('Password unchanged')
        return False

    Secret.password_store_sync(_ACCOUNT_SCHEMA, attrs, Secret.COLLECTION_DEFAULT,
                                "Pandora Account", password, None)
    return True
Example #47
0
 def on_password_lookup_finish(source, result, data):
     try:
         password = Secret.password_lookup_finish(result) or ''
     except GLib.Error as e:
         password = ''
         logging.error('Failed to lookup password, Error: {}'.format(e))
     callback(password)
def store():

    attributes = get_attributes()
    if 'password' in attributes:
        password = attributes['password']
        del attributes['password']
    else:
        sys.exit(1)
    Secret.password_store_sync(
            GIT_CREDENTIALS_SCHEMA,
            attributes,
            Secret.COLLECTION_DEFAULT,
            "%s://%s@%s" %(attributes['protocol'], attributes['username'], attributes['host'] ),
            password,
            None
            )
Example #49
0
    def get_account_password(self, email, callback):
        def on_password_lookup_finish(source, result, data):
            try:
                password = Secret.password_lookup_finish(result) or ''
            except GLib.Error as e:
                password = ''
                logging.error('Failed to lookup password, Error: {}'.format(e))
            callback(password)

        Secret.password_lookup(
            self._account_schema,
            {'email': email},
            None,
            on_password_lookup_finish,
            None,
        )
Example #50
0
 def _update_lastfm_settings(self, sync=False):
     if Lp.lastfm is not None and Secret is not None:
         schema = Secret.Schema.new("org.gnome.Lollypop",
                                    Secret.SchemaFlags.NONE,
                                    SecretSchema)
         Secret.password_store_sync(schema, SecretAttributes,
                                    Secret.COLLECTION_DEFAULT,
                                    "org.gnome.Lollypop.lastfm.login %s" %
                                    self._login.get_text(),
                                    self._password.get_text(),
                                    None)
         Lp.settings.set_value('lastfm-login',
                               GLib.Variant('s', self._login.get_text()))
         if sync:
             Lp.lastfm.connect_sync(self._password.get_text())
         else:
             Lp.lastfm.connect(self._password.get_text())
Example #51
0
 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)
Example #52
0
 def find_password(self, scheme, host, username):
     """Return the password of username@root."""
     template = dict(zip(self.category, (scheme, host, username)))
     try:
         password = Secret.password_lookup_sync(self.schema, template, None)
     except Secret.SECRET_ERROR_PROTOCOL:
         return
     return password
Example #53
0
 def connect(self, password):
     """
         Connect lastfm
         @param password as str/None
     """
     if Secret is None or\
             not Gio.NetworkMonitor.get_default().get_network_available():
         return
     self._username = Lp.settings.get_value('lastfm-login').get_string()
     if password is None:
         schema = Secret.Schema.new("org.gnome.Lollypop",
                                    Secret.SchemaFlags.NONE,
                                    SecretSchema)
         Secret.password_lookup(schema, SecretAttributes, None,
                                self._on_password_lookup)
     else:
         start_new_thread(self._connect, (self._username, password))
    def clear():
        """
           Clear all existing accounts.

           :return bool: Either the token was removed successfully or not
       """
        schema = Keyring.get_default().schema
        success = Secret.password_clear_sync(schema, {}, None)
        return success
    def remove(secret_id):
        """
        Remove a specific secret OTP token.

        :param secret_id: the secret ID associated to the OTP token
        :return bool: Either the token was removed successfully or not
        """
        schema = Keyring.get_default().schema
        success = Secret.password_clear_sync(
            schema, {"id": str(secret_id)}, None)
        return success
Example #56
0
 def _on_password_lookup(self, source, result):
     """
         Set password entry
         @param source as GObject.Object
         @param result Gio.AsyncResult
     """
     password = None
     if result is not None:
         password = Secret.password_lookup_finish(result)
     if password is not None:
         self._password.set_text(password)
Example #57
0
	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 get_by_id(secret_id):
        """
        Return the OTP token based on a secret ID.

        :param secret_id: the secret ID associated to an OTP token
        :type secret_id: str
        :return: the secret OTP token.
        """
        schema = Keyring.get_default().schema
        password = Secret.password_lookup_sync(
            schema, {"id": str(secret_id)}, None)
        return password
Example #59
0
    def getTokens(self, user):
        attributes = {
                         "user": user,
                         "scope": self.scope,
                     }

        password = Secret.password_lookup_sync(self.TOKEN_SCHEMA,
                                               attributes, None)

        if password:
            return self.decodeTokens(password)
        else:
            return (None, None)
Example #60
0
 def _on_password_lookup(self, source, result):
     """
         Init self object
         @param source as GObject.Object
         @param result Gio.AsyncResult
     """
     try:
         password = Secret.password_lookup_finish(result)
         self._password = password
         if Gio.NetworkMonitor.get_default().get_network_available():
             start_new_thread(self._connect, (self._username, password))
     except Exception as e:
         print("Lastfm::_on_password_lookup(): %s" % e)