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
        )
Esempio n. 2
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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
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
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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()
Esempio n. 10
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)
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
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)
Esempio n. 14
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())
Esempio n. 15
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
Esempio n. 16
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
                     )
Esempio n. 17
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")
Esempio n. 18
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)
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)
Esempio n. 20
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")
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
            )
Esempio n. 22
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, _current_collection,
                               "Pandora Account", password, None)
    return True
Esempio n. 23
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
Esempio n. 24
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())
Esempio n. 25
0
    def set_password(self, pass_name, password):
        log.debug(f"set_password {pass_name}")
        result = Secret.password_store_sync(self._SECRET_SCHEMA,
                                            {"id": pass_name},
                                            Secret.COLLECTION_DEFAULT,
                                            str(pass_name), password, None)

        if not result:
            raise Exception(f"Can't create a new password: {result}")

        return pass_name
Esempio n. 26
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)
Esempio n. 27
0
 def _update_lastfm_settings(self, sync=False):
     """
         Update lastfm settings
         @param sync as bool
     """
     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())
Esempio n. 28
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)
Esempio n. 29
0
    def insert(self, token_id: str, provider: str, username: str, token: str):
        """
        Save a secret OTP token.

        :param token_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 = self.schema

        data = {
            "id": str(token_id),
            "name": str(username),
        }
        Secret.password_store_sync(
            schema, data, Secret.COLLECTION_DEFAULT,
            "{provider} OTP ({username})".format(provider=provider,
                                                 username=username), token,
            None)
Esempio n. 30
0
	def update(self, username, password):
		secret = '\n'.join((username, password))
		if secret == self.secret:
			print ("Account details not changed")
			return
		self.secret = secret
		if Secret is None:
			print ("Account details were not saved because libsecret was not found")
			return
		result = Secret.password_store_sync(MAGNATUNE_SCHEMA,
							self.keyring_attributes,
							Secret.COLLECTION_DEFAULT,
							"Rhythmbox: Magnatune account information",
							secret, None)
		if not result:
			print ("Couldn't create keyring item!")
Esempio n. 31
0
 def update(self, username, password):
     secret = '\n'.join((username, password))
     if secret == self.secret:
         print("Account details not changed")
         return
     self.secret = secret
     if Secret is None:
         print(
             "Account details were not saved because libsecret was not found"
         )
         return
     result = Secret.password_store_sync(
         MAGNATUNE_SCHEMA, self.keyring_attributes,
         Secret.COLLECTION_DEFAULT,
         "Rhythmbox: Magnatune account information", secret, None)
     if not result:
         print("Couldn't create keyring item!")
Esempio n. 32
0
 def set_password(self, service, username, password):
     """Set password for the username of the service"""
     attributes = {
         "application": self.appid,
         "service": service,
         "username": username,
     }
     label = "Password for '{}' on '{}'".format(username, service)
     try:
         stored = Secret.password_store_sync(self.schema, attributes,
                                             self.collection, label,
                                             password, 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 collection!") from error
         quark = GLib.quark_try_string('g-io-error-quark')
         if error.matches(quark, Gio.IOErrorEnum.FAILED):
             raise KeyringLocked(
                 "Failed to unlock the collection!") from error
         raise
     if not stored:
         raise PasswordSetError("Failed to store password!")
Esempio n. 33
0
def main(username,password):
    Secret.password_store_sync(RDP_SCHEMA, attributes, Secret.COLLECTION_DEFAULT,
                               "RDP username", "{{\"username\":\"{}\",\"password\":\"{}\"}}".format(username,password), None)
Esempio n. 34
0
def secret_password_store(attributes, label, password):
    Secret.password_store_sync(GENOTP_SCHEMA, attributes,
                               Secret.COLLECTION_DEFAULT, label, password,
                               None)
Esempio n. 35
0
def set_pw(account, field, password):
    schema, attributes, label = stuff(account, field)
    Secret.password_store_sync(schema, attributes, Secret.COLLECTION_DEFAULT,
                               label, password, None)
Esempio n. 36
0
 def save(self, data):
     """Store data. Returns a boolean of whether operation was successful."""
     return Secret.password_store_sync(self._schema, self._attributes,
                                       self._collection, self._label, data,
                                       None)
Esempio n. 37
0
    def _store_secret(self, ex_schema, kwargs, label, password):

        Secret.password_store_sync(ex_schema, kwargs, self._collection, label,
                                   password, None)
Esempio n. 38
0
    def on_settings_apply_btn_clicked(self, buttton):

        initial_remote = self.get_setting(self.SETTING.REMOTE)

        if self.url_radio_btn.get_active():
            url = self.remote_addr_entry.get_text().strip()
            self.set_setting(self.SETTING.REMOTE_TYPE, "url")
        elif self.zip_radio_btn.get_active():
            url = self.source_file_chooser.get_filename()
            self.set_setting(self.SETTING.REMOTE_TYPE, "zip")
        elif self.dir_radio_btn.get_active():
            url = self.source_folder_chooser.get_filename()
            self.set_setting(self.SETTING.REMOTE_TYPE, "dir")

            #make sure there is no dir inside
            all_files = [f for f in os.listdir(url)]
            is_dir = [os.path.isdir(os.path.join(url, x)) for x in all_files]
            assert (any(is_dir) == False)

        else:
            return False

        if (url != '') or (url is not None):
            self.set_setting(self.SETTING.REMOTE, url)
            folder_name = urlparse(url).netloc
            if folder_name == '':
                folder_name = "configs"
            self.set_setting(self.SETTING.REMOTE_SAVEPATH,
                             path.join(self.EOVPN_CONFIG_DIR, folder_name))
        else:
            self.set_setting(self.SETTING.REMOTE, None)

        if self.req_auth.get_active():
            self.set_setting(self.SETTING.REQ_AUTH, True)

            username = self.auth_user.get_text()
            self.set_setting(self.SETTING.AUTH_USER, username)

            password = self.auth_pass.get_text()
            self.set_setting(self.SETTING.AUTH_PASS, password)

            auth_file = os.path.join(self.EOVPN_CONFIG_DIR, "auth.txt")
            if self.get_setting(self.SETTING.MANAGER) == "networkmanager":
                if os.path.isfile(auth_file):
                    os.remove(auth_file)
                self.set_setting(self.SETTING.AUTH_PASS, None)

                attributes = {"username": username}
                result = Secret.password_store_sync(self.EOVPN_SECRET_SCHEMA,
                                                    attributes,
                                                    Secret.COLLECTION_DEFAULT,
                                                    "password", password, None)
                if result:
                    logger.info("password stored to keyring!")

            else:
                self.set_setting(self.SETTING.AUTH_PASS, password)
                f = open(auth_file, "w+")
                f.write("{}\n{}".format(username, password))
                f.close()

        if initial_remote is None:
            ThreadManager().create(self._download_and_load_configs, (), True)

        if initial_remote is not None:
            set_ca_automatic(self)

        #show settings saved notfication
        self.inapp_notification_label.set_text(
            gettext.gettext("Settings Saved."))
        self.undo_reset_btn.hide()
        self.setting_saved_reveal.set_reveal_child(True)