How to use the keyring.errors.PasswordSetError function in keyring

To help you get started, we’ve selected a few keyring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 21dotco / two1-python / two1 / lib / machine_auth.py View on Github external
def saveto_keyring(self):
        """ Saves the private key in the keyring (available on the system).

        Raises:
            ValueError: If the private is not set.

        Returns:
            bool: True if the key was saved successfully, False otherwise.
        """
        if self.private_key:
            auth_key_b58 = self.private_key.to_b58check()
            try:
                keyring.set_password(
                    "twentyone", "mining_auth_key", auth_key_b58)
                return True
            except keyring.errors.PasswordSetError:
                return False
        else:
            raise ValueError("Private key is not set.")
github ipop-project / Controllers / controller / modules / Signal.py View on Github external
transport.ca_certs = overlay_descr["TrustStore"]
            transport.certfile = overlay_descr["CertDirectory"] + overlay_descr["CertFile"]
            transport.keyfile = overlay_descr["CertDirectory"] + overlay_descr["Keyfile"]
            transport.use_tls = True
        elif auth_method == "PASSWORD":
            if user is None:
                raise RuntimeError("No username is provided in IPOP configuration file.")
            if pswd is None and keyring_installed is True:
                pswd = keyring.get_password("ipop", overlay_descr["Username"])
            if pswd is None:
                print("{0} XMPP Password: ".format(user))
                pswd = str(input())
                if keyring_installed is True:
                    try:
                        keyring.set_password("ipop", user, pswd)
                    except keyring.errors.PasswordSetError as err:
                        cm_mod.sig_log("Failed to store password in keyring. {0}".format(str(err)),
                                       "LOG_ERROR")
            transport = XmppTransport(user, pswd, sasl_mech="PLAIN")
            transport.use_tls = True
            del pswd
        else:
            raise RuntimeError("Invalid authentication method specified in configuration: {0}"
                               .format(auth_method))
        # pylint: disable=protected-access
        transport._host = host
        transport._port = port
        transport._overlay_id = overlay_id
        transport._sig = cm_mod
        transport._node_id = cm_mod._cm_config["NodeId"]
        transport._presence_publisher = presence_publisher
        transport._jid_cache = jid_cache
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Gnome.py View on Github external
"""Set password for the username of the service
        """
        service = self._safe_string(service)
        username = self._safe_string(username)
        password = self._safe_string(password)
        attrs = GnomeKeyring.Attribute.list_new()
        GnomeKeyring.Attribute.list_append_string(attrs, 'username', username)
        GnomeKeyring.Attribute.list_append_string(attrs, 'service', service)
        GnomeKeyring.Attribute.list_append_string(attrs, 'application', 'python-keyring')
        result = GnomeKeyring.item_create_sync(
            self.keyring_name, GnomeKeyring.ItemType.NETWORK_PASSWORD,
            "Password for '%s' on '%s'" % (username, service),
            attrs, password, True)[0]
        if result == GnomeKeyring.Result.CANCELLED:
            # The user pressed "Cancel" when prompted to unlock their keyring.
            raise PasswordSetError("Cancelled by user")
        elif result != GnomeKeyring.Result.OK:
            raise PasswordSetError(result.value_name)
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
conflicting_pwd = self._get_entry(keyring_dict, service, username)
            if conflicting_pwd == password:
                # if someone else updated it to the same value then we are done
                self._keyring_dict = keyring_working_copy
                return
            elif conflicting_pwd is None or conflicting_pwd == existing_pwd:
                # if doesn't already exist or is unchanged then update it
                new_service_entries = keyring_dict.get(service, {})
                new_service_entries[username] = password
                keyring_dict[service] = new_service_entries
                save_result = self._save_keyring(keyring_dict)
                if save_result == self.OK:
                    self._keyring_dict = keyring_dict
                    return
                else:
                    raise errors.PasswordSetError(
                        'Failed write after conflict detected')
            else:
                raise errors.PasswordSetError(
                    'Conflict detected, service:%s and username:%s was '\
                    'set to a different value by someone else' %(service,
                                                                 username))

        raise errors.PasswordSetError('Could not save keyring')
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
self._keyring_dict = keyring_working_copy
                return
            elif conflicting_pwd is None or conflicting_pwd == existing_pwd:
                # if doesn't already exist or is unchanged then update it
                new_service_entries = keyring_dict.get(service, {})
                new_service_entries[username] = password
                keyring_dict[service] = new_service_entries
                save_result = self._save_keyring(keyring_dict)
                if save_result == self.OK:
                    self._keyring_dict = keyring_dict
                    return
                else:
                    raise errors.PasswordSetError(
                        'Failed write after conflict detected')
            else:
                raise errors.PasswordSetError(
                    'Conflict detected, service:%s and username:%s was '\
                    'set to a different value by someone else' %(service,
                                                                 username))

        raise errors.PasswordSetError('Could not save keyring')
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / Google.py View on Github external
new_service_entries[username] = password
                keyring_dict[service] = new_service_entries
                save_result = self._save_keyring(keyring_dict)
                if save_result == self.OK:
                    self._keyring_dict = keyring_dict
                    return
                else:
                    raise errors.PasswordSetError(
                        'Failed write after conflict detected')
            else:
                raise errors.PasswordSetError(
                    'Conflict detected, service:%s and username:%s was '\
                    'set to a different value by someone else' %(service,
                                                                 username))

        raise errors.PasswordSetError('Could not save keyring')
github 21dotco / two1-python / two1 / server / machine_auth.py View on Github external
def saveto_keyring(self):
        """ Saves the private key in the keyring (available on the system).

        Raises:
            ValueError: If the private is not set.

        Returns:
            bool: True if the key was saved successfully, False otherwise.
        """
        if self.private_key:
            auth_key_b58 = self.private_key.to_b58check()
            try:
                keyring.set_password(
                    "twentyone", "mining_auth_key", auth_key_b58)
                return True
            except keyring.errors.PasswordSetError:
                return False
        else:
            raise ValueError("Private key is not set.")
github nficano / alexa-find-my-iphone / src / site-packages / keyrings / alt / kwallet.py View on Github external
def set_password(self, service, username, password):
        """Set password for the username of the service
        """
        wallet = open_kwallet()
        if wallet is None:
            # the user pressed "cancel" when prompted to unlock their keyring.
            raise PasswordSetError("Cancelled by user")
        wallet.writePassword(username+'@'+service, password)
github thrawn01 / hubble / hubble / keys.py View on Github external
def set_password(env, variable, password):
    # Try to store the password
    try:
        # If no variable, the we are setting a global
        if variable is None:
            variable = env
            env = '__global__'
        key = '%s:%s' % (env, variable)
        keyring.set_password('hubble', key, password)
        print("\n-- Successfully stored credentials for variable '%s' in"
              " environment [%s] under keyring 'hubble'" %
              (variable, env))
    except keyring.errors.PasswordSetError as e:
        raise RuntimeError("Unable to store credentials for variable '%s' in"
                           " environment [%s] under the hubble service - %s" %
                           (env, variable, str(e)))