Ejemplo n.º 1
0
	def set(self, protocol, user, server, password):
		if password != '':
			displayNameDict = {}
			(result, ids) = GnomeKeyring.list_item_ids_sync(self._defaultKeyring)
			for identity in ids:
				(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, identity)
				displayNameDict[item.get_display_name()] = identity

			attrs = GnomeKeyring.Attribute.list_new()
			GnomeKeyring.Attribute.list_append_string(attrs, 'application',	'Mailnag')
			GnomeKeyring.Attribute.list_append_string(attrs, 'protocol',	protocol)
			GnomeKeyring.Attribute.list_append_string(attrs, 'user',		user)
			GnomeKeyring.Attribute.list_append_string(attrs, 'server',		server)
			
			if self.KEYRING_ITEM_NAME % (protocol, user, server) in displayNameDict:
				(result, item) = GnomeKeyring.item_get_info_sync(self._defaultKeyring, \
					displayNameDict[self.KEYRING_ITEM_NAME % \
					(protocol, user, server)])
				
				if password != item.get_secret():
					GnomeKeyring.item_create_sync(self._defaultKeyring, \
						GnomeKeyring.ItemType.GENERIC_SECRET, \
						self.KEYRING_ITEM_NAME % (protocol, user, server), \
						attrs, password, True)
			else:
				GnomeKeyring.item_create_sync(self._defaultKeyring, \
					GnomeKeyring.ItemType.GENERIC_SECRET, \
					self.KEYRING_ITEM_NAME % (protocol, user, server), \
					attrs, password, True)
Ejemplo n.º 2
0
 def add_account(self, name, secret_code, image):
     """
         Add an account to accounts table
         :param name: (str) account name
         :param secret_code: (str) ASCII Secret code
         :param image: image path or icon name
         :return:
     """
     encrypted_secret = sha256(secret_code.encode('utf-8')).hexdigest()
     t = (
         name,
         encrypted_secret,
         image,
     )
     query = "INSERT INTO accounts (name, secret_code, image) VALUES (?, ?, ?)"
     try:
         GK.create_sync("TwoFactorAuth", None)
         attr = GK.Attribute.list_new()
         GK.Attribute.list_append_string(attr, 'id', encrypted_secret)
         GK.Attribute.list_append_string(attr, 'secret_code', secret_code)
         GK.item_create_sync("TwoFactorAuth", GK.ItemType.GENERIC_SECRET,
                             repr(encrypted_secret), attr, secret_code,
                             False)
         self.conn.execute(query, t)
         self.conn.commit()
     except Exception as e:
         logging.error("SQL: Couldn't add a new account : %s ", str(e))
Ejemplo n.º 3
0
 def do_store(self, id, username, password):
     GnomeKeyring.create_sync("liferea", None)
     attrs = GnomeKeyring.Attribute.list_new()
     GnomeKeyring.Attribute.list_append_string(attrs, "id", id)
     GnomeKeyring.Attribute.list_append_string(attrs, "user", username)
     GnomeKeyring.item_create_sync(
         "liferea", GnomeKeyring.ItemType.GENERIC_SECRET, repr(id), attrs, "@@@".join([username, password]), True
     )
Ejemplo n.º 4
0
 def set_credentials(self, user, pw):
     attrs = attributes({
             "user": user,
             "server": self._server,
             "protocol": self._protocol,
         })
     GnomeKeyring.item_create_sync(self._keyring,
             GnomeKeyring.ItemType.NETWORK_PASSWORD, self._name, attrs, pw, True)
Ejemplo n.º 5
0
 def do_store(self, id, username, password):
     GnomeKeyring.create_sync("liferea", None)
     attrs = GnomeKeyring.Attribute.list_new()
     GnomeKeyring.Attribute.list_append_string(attrs, 'id', id)
     GnomeKeyring.Attribute.list_append_string(attrs, 'user', username)
     GnomeKeyring.item_create_sync("liferea",
                                   GnomeKeyring.ItemType.GENERIC_SECRET,
                                   repr(id), attrs,
                                   '@@@'.join([username, password]), True)
Ejemplo n.º 6
0
    def store_password(self,
                       entry,
                       password,
                       attributes=None,
                       entry_type=EntryType.GENERIC):
        """Create new entry in keyring with specified data"""
        assert self.is_available()

        # create a new keyring if it doesn't exist
        if not self.KEYRING_NAME in keyring.list_keyring_names_sync()[1]:
            dialog = PasswordDialog(self._application)
            dialog.set_title(_('New keyring'))
            dialog.set_label(
                _('We need to create a new keyring to safely '
                  'store your passwords. Choose the password you '
                  'want to use for it.'))

            response = dialog.get_response()

            if response[0] == Gtk.ResponseType.OK \
            and response[1] == response[2]:
                # create new keyring
                keyring.create_sync(self.KEYRING_NAME, response[1])
                self.__update_info()

            else:
                # wrong password
                raise KeyringCreateError('No keyring to store password to.')

        # if keyring is locked, try to unlock it
        if self.is_locked() and not self.__unlock_keyring():
            return False

        attribute_array = keyring.Attribute.list_new()
        for key in attributes:
            keyring.Attribute.list_append_string(attribute_array, key,
                                                 attributes[key])

        # store password to existing keyring
        keyring.item_create_sync(
            self.KEYRING_NAME,
            self.KEYRING_TYPE[entry_type],
            entry,
            attribute_array,
            password,
            True  # update if exists
        )

        return True
Ejemplo n.º 7
0
def get_keyring_password():
    GnomeKeyring.unlock_sync("login", None)
    attrs = GnomeKeyring.Attribute.list_new()
    GnomeKeyring.Attribute.list_append_string(attrs, "id", "resnet")
    result, value = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
    if result == GnomeKeyring.Result.OK:
        return value[0].secret
    elif result == GnomeKeyring.Result.NO_MATCH:
        # Password not found, prompt to add new one
        print("Password not found in keyring")
        password = getpass.getpass("OSU Login Password: "******"login", GnomeKeyring.ItemType.GENERIC_SECRET, "resnet", attrs, password, True)
        return password
    elif result != GnomeKeyring.Result.OK:
        return None
    def find_keyring_items(self):
        attrs = GnomeKeyring.Attribute.list_new()
        GnomeKeyring.Attribute.list_append_string(attrs, 'rhythmbox-plugin', 'pandora')
        result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)

        if (result is None or result is GnomeKeyring.Result.OK) and len(items) != 0: # Got list of search results
            self.__keyring_data['id'] = items[0].item_id
            result, item = GnomeKeyring.item_get_info_sync(None, self.__keyring_data['id'])
            if result is None or result is GnomeKeyring.Result.OK: # Item retrieved successfully
                self.__keyring_data['item'] = item
                self.fill_account_details()
            else:
                print("Couldn't retrieve keyring item: " + str(result))

        elif result == GnomeKeyring.Result.NO_MATCH or len(items) == 0: # No items were found, so we'll create one
            result, id = GnomeKeyring.item_create_sync(
                                None,
                                GnomeKeyring.ItemType.GENERIC_SECRET,
                                "Rhythmbox: Pandora account information",
                                attrs,
                                "", # Empty secret for now
                                True)
            if result is None or result is GnomeKeyring.Result.OK: # Item successfully created
                self.__keyring_data['id'] = id
                result, item = GnomeKeyring.item_get_info_sync(None, id)
                if result is None: # Item retrieved successfully
                    self.__keyring_data['item'] = item
                    self.fill_account_details()
                else:
                    print("Couldn't retrieve keyring item: " + str(result))
            else:
                print("Couldn't create keyring item: " + str(result))
        else: # Some other error occurred
            print("Couldn't access keyring: " + str(result))
Ejemplo n.º 9
0
    def test_item_create_info(self):
        '''item_create_sync(),  item_get_info_sync(), list_item_ids_sync()'''

        self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
                GnomeKeyring.Result.OK)
        self.assertEqual(GnomeKeyring.get_info_sync(TEST_KEYRING)[0], GnomeKeyring.Result.OK)

        attrs = GnomeKeyring.Attribute.list_new()
        GnomeKeyring.Attribute.list_append_string(attrs, 'context', 'testsuite')
        GnomeKeyring.Attribute.list_append_uint32(attrs, 'answer', 42)

        (result, id) = GnomeKeyring.item_create_sync(TEST_KEYRING,
                GnomeKeyring.ItemType.GENERIC_SECRET, 'my_password', attrs,
                'my_secret', False)
        self.assertEqual(result, GnomeKeyring.Result.OK)

        # now query for it
        (result, info) = GnomeKeyring.item_get_info_sync(TEST_KEYRING, id)
        self.assertEqual(result, GnomeKeyring.Result.OK)
        self.assertEqual(info.get_display_name(), 'my_password')
        self.assertEqual(info.get_secret(), 'my_secret')

        # list_item_ids_sync()
        (result, items) = GnomeKeyring.list_item_ids_sync(TEST_KEYRING)
        self.assertEqual(result, GnomeKeyring.Result.OK)
        self.assertEqual(items, [id])
Ejemplo n.º 10
0
	def set(self, key, secret):
		if secret == '':
			return
		
		attrs = self._get_attrs(key)
		
		existing_secret = ''
		result, items = GnomeKeyring.find_items_sync(GnomeKeyring.ItemType.GENERIC_SECRET, attrs)
		
		if result == GnomeKeyring.Result.OK:
			existing_secret = items[0].secret
		
		if existing_secret != secret:
			GnomeKeyring.item_create_sync(self._defaultKeyring, \
					GnomeKeyring.ItemType.GENERIC_SECRET, key, \
					attrs, secret, True)
Ejemplo n.º 11
0
    def test_item_create_info(self):
        '''item_create_sync(),  item_get_info_sync(), list_item_ids_sync()'''

        self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
                         GnomeKeyring.Result.OK)
        self.assertEqual(
            GnomeKeyring.get_info_sync(TEST_KEYRING)[0],
            GnomeKeyring.Result.OK)

        attrs = GnomeKeyring.Attribute.list_new()
        GnomeKeyring.Attribute.list_append_string(attrs, 'context',
                                                  'testsuite')
        GnomeKeyring.Attribute.list_append_uint32(attrs, 'answer', 42)

        (result, id) = GnomeKeyring.item_create_sync(
            TEST_KEYRING, GnomeKeyring.ItemType.GENERIC_SECRET, 'my_password',
            attrs, 'my_secret', False)
        self.assertEqual(result, GnomeKeyring.Result.OK)

        # now query for it
        (result, info) = GnomeKeyring.item_get_info_sync(TEST_KEYRING, id)
        self.assertEqual(result, GnomeKeyring.Result.OK)
        self.assertEqual(info.get_display_name(), 'my_password')
        self.assertEqual(info.get_secret(), 'my_secret')

        # list_item_ids_sync()
        (result, items) = GnomeKeyring.list_item_ids_sync(TEST_KEYRING)
        self.assertEqual(result, GnomeKeyring.Result.OK)
        self.assertEqual(items, [id])
Ejemplo n.º 12
0
    def set(self, key, secret):
        if secret == '':
            return

        attrs = self._get_attrs(key)

        existing_secret = ''
        result, items = GnomeKeyring.find_items_sync(
            GnomeKeyring.ItemType.GENERIC_SECRET, attrs)

        if result == GnomeKeyring.Result.OK:
            existing_secret = items[0].secret

        if existing_secret != secret:
            GnomeKeyring.item_create_sync(self._defaultKeyring, \
              GnomeKeyring.ItemType.GENERIC_SECRET, key, \
              attrs, secret, True)
Ejemplo n.º 13
0
 def _set_value_to_gnomekeyring(self, name, value):
     """Store a value in the keyring."""
     attributes = GnomeKeyring.Attribute.list_new()
     GnomeKeyring.Attribute.list_append_string(attributes, "id", str(name))
     keyring = GnomeKeyring.get_default_keyring_sync()[1]
     value = GnomeKeyring.item_create_sync(
         keyring, GnomeKeyring.ItemType.GENERIC_SECRET, "%s preferences" % (com.APP), attributes, str(value), True
     )
     return value[1]
	def createEncriptedFolder(self,epath,password):
		attributes = GnomeKeyring.Attribute.list_new()
		GnomeKeyring.Attribute.list_append_string(attributes, 'appid', APPID)
		GnomeKeyring.Attribute.list_append_string(attributes, 'encfs-path', str(epath))
		result = GnomeKeyring.item_create_sync (self.keyring, \
		GnomeKeyring.ItemType.GENERIC_SECRET, \
		'Encrypted folder %s'%(epath),attributes, password,True)[0]
		if result == GnomeKeyring.Result.OK:
			return True
		return False
Ejemplo n.º 15
0
    def set_password(self, name, password, userid=""):
        attrs = GnomeKeyring.Attribute.list_new()
        GnomeKeyring.Attribute.list_append_string(attrs, "backend", name)
        result, password_id = GnomeKeyring.item_create_sync(
            self.keyring, GnomeKeyring.ItemType.GENERIC_SECRET, name, attrs,
            password, True)

        if result != GnomeKeyring.Result.OK:
            raise Exception(f"Can't create a new password, error={result}")

        return password_id
Ejemplo n.º 16
0
def set_secrets(krname, to_write, overwrite_all):
    item_ids = verify(gk.list_item_ids_sync(krname),
                      'list pre-existing items in keyring=%s' % krname)

    if overwrite_all:
        # Remove existing items from the keyring, leaving the container intact.
        for i in item_ids:
            verify(gk.item_delete_sync(krname, i),
                   'delete pre-existing item from keyring=%s' % krname)
        item_ids = []

    existing_items = {}
    for i in item_ids:
        item = verify(get_item(krname, i),
                      'access pre-existing item in keyring=%s' % krname)
        existing_items[item.get_display_name()] = i

    try:
        typ = gk.ItemType.GENERIC_SECRET
    except AttributeError:
        typ = gk.ITEM_GENERIC_SECRET

    # Write out new items.
    for i in to_write:
        needle = encode_label(i[DICT_ATTRIBUTES])
        secret = i[DICT_SECRET]
        label = pretty_print_label(needle)
        if needle in existing_items:
            # Matched an existing item; update it in-place.
            info = gk.ItemInfo()
            info.set_type(typ)
            info.set_display_name(needle)
            info.set_secret(secret)
            verify(gk.item_set_info_sync(krname, existing_items[needle], info),
                   'edit item (%s) in keyring=%s' % (label, krname))
        else:
            #
            # No existing item was present. Create a new one.
            #
            # XXX: We must pass update_if_exists=False because if we did not,
            # every item would collide with every other. In other words, we
            # would only be able to store a single item in the keyring, as we
            # are forced to use the same identifying attributes for every item
            # we create. This is because the only GLib.Array we can create is
            # the empty Array(). Awful.
            #
            item_id = verify(
                gk.item_create_sync(krname,
                                    typ,
                                    display_name=needle,
                                    attributes=Array(),
                                    secret=secret,
                                    update_if_exists=False),
                'create new item (%s) in keyring=%s' % (label, krname))
Ejemplo n.º 17
0
def put_in_keyring(acctid, name, value):
  """Store a value in the keyring."""
  id = "%s/%s" % (acctid, name)
  attributes = GnomeKeyring.Attribute.list_new()
  GnomeKeyring.Attribute.list_append_string(attributes, 'id', str(id))
  keyring = GnomeKeyring.get_default_keyring_sync()[1]
  value = GnomeKeyring.item_create_sync(
    keyring, GnomeKeyring.ItemType.GENERIC_SECRET,
    "Gwibber preference: %s" % id,
    attributes, str(value), True)
  return value[1]
Ejemplo n.º 18
0
    def set_password(self, name, password, userid=""):
        attrs = GnomeKeyring.Attribute.list_new()
        GnomeKeyring.Attribute.list_append_string(attrs, "backend", name)
        result, password_id = GnomeKeyring.item_create_sync(
            self.keyring, GnomeKeyring.ItemType.GENERIC_SECRET, name, attrs, password, True
        )

        if result != GnomeKeyring.Result.OK:
            raise Exception("Can't create a new password, error=%s" % result)

        return password_id
Ejemplo n.º 19
0
def import_keyrings(from_file):
    with open(from_file, "r") as f:
        keyrings = json.loads(f.read())

    for keyring_name, keyring_items in list(keyrings.items()):
        try:
            existing_ids = GnomeKeyring.list_item_ids_sync(keyring_name)
        except GnomeKeyring.NoSuchKeyringError:
            sys.stderr.write(
                "No keyring '%s' found. Please create this keyring first" %
                keyring_name)
            sys.exit(1)

        existing_items = [get_item(keyring_name, id) for id in existing_ids]
        existing_items = [i for i in existing_items if i is not None]

        for item in keyring_items:
            if any(items_roughly_equal(item, i) for i in existing_items):
                print("Skipping %s because it already exists" %
                      item['display_name'])
            else:
                nearly = [
                    i for i in existing_items
                    if items_roughly_equal(i, item, ignore_secret=True)
                ]
                if nearly:
                    print("Existing secrets found for '%s'" %
                          item['display_name'])
                    for i in nearly:
                        print(" " + i['secret'])

                    print("So skipping value from '%s':" % from_file)
                    print(" " + item['secret'])
                else:
                    schema = item['attributes']['xdg:schema']
                    item_type = None
                    if schema == 'org.freedesktop.Secret.Generic':
                        item_type = GnomeKeyring.ITEM_GENERIC_SECRET
                    elif schema == 'org.gnome.keyring.Note':
                        item_type = GnomeKeyring.ITEM_NOTE
                    elif schema == 'org.gnome.keyring.NetworkPassword':
                        item_type == GnomeKeyring.ITEM_NETWORK_PASSWORD

                    if item_type is not None:
                        item_id = GnomeKeyring.item_create_sync(
                            keyring_name, item_type, item['display_name'],
                            fix_attributes(item['attributes']), item['secret'],
                            False)
                        print("Copying secret %s" % item['display_name'])
                    else:
                        print(
                            "Can't handle secret '%s' of type '%s', skipping" %
                            (item['display_name'], schema))
 def _create_keyring_item_info(self, secret):
     result, item_id = GnomeKeyring.item_create_sync(
                             GnomeCredentialStore.KEYRING_NAME,
                             GnomeKeyring.ItemType.GENERIC_SECRET,
                             repr(GnomeCredentialStore.ITEM_ATTR_ID),
                             self.item_attrs,
                             secret,
                             True)
     if result != GnomeKeyring.Result.OK:
         logger.debug("Failed to create keyring item: %s" % result)
         return None
     logger.debug("Successfully created keyring item info with item id: %s " % item_id)
     return item_id
Ejemplo n.º 21
0
 def add_account(self, name, secret_code, image):
     """
         Add an account to accounts table
         :param name: (str) account name
         :param secret_code: (str) ASCII Secret code
         :param image: image path or icon name
         :return:
     """
     encrypted_secret = sha256(secret_code.encode('utf-8')).hexdigest()
     t = (name, encrypted_secret, image,)
     query = "INSERT INTO accounts (name, secret_code, image) VALUES (?, ?, ?)"
     try:
         GK.create_sync("TwoFactorAuth", None)
         attr = GK.Attribute.list_new()
         GK.Attribute.list_append_string(attr, 'id', encrypted_secret)
         GK.Attribute.list_append_string(attr, 'secret_code', secret_code)
         GK.item_create_sync("TwoFactorAuth", GK.ItemType.GENERIC_SECRET, repr(encrypted_secret), attr,
                             secret_code, False)
         self.conn.execute(query, t)
         self.conn.commit()
     except Exception as e:
         logging.error("SQL: Couldn't add a new account : %s ", str(e))
def import_keyrings(from_file):
    with open(from_file, "r") as f:
        keyrings = json.loads(f)

    for keyring_name, keyring_items in list(keyrings.items()):
        try:
            existing_ids = GnomeKeyring.list_item_ids_sync(keyring_name)
        except GnomeKeyring.NoSuchKeyringError:
            sys.stderr.write("No keyring '%s' found. Please create this keyring first" % keyring_name)
            sys.exit(1)

        existing_items = [get_item(keyring_name, id) for id in existing_ids]
        existing_items = [i for i in existing_items if i is not None]

        for item in keyring_items:
            if any(items_roughly_equal(item, i) for i in existing_items):
                print("Skipping %s because it already exists" % item['display_name'])
            else:
                nearly = [i for i in existing_items if items_roughly_equal(i, item, ignore_secret=True)]
                if nearly:
                    print("Existing secrets found for '%s'" % item['display_name'])
                    for i in nearly:
                        print(" " + i['secret'])

                    print("So skipping value from '%s':" % from_file)
                    print(" " + item['secret'])
                else:
                    schema = item['attributes']['xdg:schema']
                    item_type = None
                    if schema ==  'org.freedesktop.Secret.Generic':
                        item_type = GnomeKeyring.ITEM_GENERIC_SECRET
                    elif schema == 'org.gnome.keyring.Note':
                        item_type = GnomeKeyring.ITEM_NOTE
                    elif schema == 'org.gnome.keyring.NetworkPassword':
                        item_type == GnomeKeyring.ITEM_NETWORK_PASSWORD

                    if item_type is not None:
                        item_id = GnomeKeyring.item_create_sync(keyring_name,
                                                                item_type,
                                                                item['display_name'],
                                                                fix_attributes(item['attributes']),
                                                                item['secret'],
                                                                False)
                        print("Copying secret %s" % item['display_name'])
                    else:
                        print("Can't handle secret '%s' of type '%s', skipping" % (item['display_name'], schema))
Ejemplo n.º 23
0
    def store_credentials(self, acc, credentials):
        self.lock.acquire()
        try:
            logger.debug("Storing credentials with gnome keyring for account %s" % (acc.get_name()))
            #Remove the old info and create a new item with the new info
            self.remove_credentials(acc)

            attrs = gk.Attribute.list_new()
            gk.Attribute.list_append_string(attrs, 'account_name', acc.get_name())
            gk.Attribute.list_append_string(attrs, 'username', credentials.username)
            
            (result, id) = gk.item_create_sync(self._KEYRING_NAME, \
                 gk.ItemType.NETWORK_PASSWORD, acc.get_name(), attrs, credentials.password, True)
            if result != gk.Result.OK:
                raise Exception("Gnome Keyring return the error code: %i" % result)
            logger.debug("credentials stored with id: %i" % (id))
        finally:
            self.lock.release()
Ejemplo n.º 24
0
 def set_password(self, service, username, password):
     """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)
Ejemplo n.º 25
0
    def set_password(self, service, username, password):
        """Set password for the username of the service
        """
        from gi.repository import GnomeKeyring

        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, 'domain', service)
        result = GnomeKeyring.item_create_sync(
            self.KEYRING_NAME, GnomeKeyring.ItemType.GENERIC_SECRET,
            "%s (%s)" % (service, username),

            attrs, password, True)[0]
        if result == GnomeKeyring.Result.CANCELLED:
            # The user pressed "Cancel" when prompted to unlock their keyring.
            raise PasswordSetError("Cancelled by user")
Ejemplo n.º 26
0
 def set_password(self, service, username, password):
     """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)
Ejemplo n.º 27
0
def store_credentials(name, username, password):
    # See
    # https://bitbucket.org/kang/python-keyring-lib/src/8aadf61db38c70a5fe76fbe013df25fa62c03a8d/keyring/backends/Gnome.py?at=default # noqa
    attrs = GnomeKeyring.Attribute.list_new()
    GnomeKeyring.Attribute.list_append_string(attrs, "username", username)
    GnomeKeyring.Attribute.list_append_string(attrs, "password", password)
    GnomeKeyring.Attribute.list_append_string(attrs, "application", "Lutris")
    result = GnomeKeyring.item_create_sync(
        KEYRING_NAME,
        GnomeKeyring.ItemType.NETWORK_PASSWORD,
        "%s credentials for %s" % (name, username),
        attrs,
        password,
        True,
    )[0]
    if result == GnomeKeyring.Result.CANCELLED:
        # XXX
        return False
    elif result != GnomeKeyring.Result.OK:
        # XXX
        return False
Ejemplo n.º 28
0
    def update(self, username, password):
        secret = '\n'.join((username, password))
        if self.keyring_item is not None:
            if secret == self.keyring_item.get_secret():
                print "account details not changed"
                return

        (result, id) = GnomeKeyring.item_create_sync(None,
                                 GnomeKeyring.ItemType.GENERIC_SECRET,
                                 "Rhythmbox: Vkontakte account information",
                                 self.keyring_attributes,
                                 secret,
                                 True)
        if result == GnomeKeyring.Result.OK:
            if self.keyring_item is None:
                (result, item) = GnomeKeyring.item_get_info_sync(None, id)
                if result == GnomeKeyring.Result.OK:
                    self.keyring_item = item
                else:
                    print "couldn't fetch keyring item: " + GnomeKeyring.result_to_message(result)
        else:
            print "couldn't create keyring item: " + GnomeKeyring.result_to_message(result)
Ejemplo n.º 29
0
    def store_credentials(self, acc, credentials):
        self.lock.acquire()
        try:
            logger.debug(
                "Storing credentials with gnome keyring for account %s" %
                (acc.get_name()))
            #Remove the old info and create a new item with the new info
            self.remove_credentials(acc)

            attrs = gk.Attribute.list_new()
            gk.Attribute.list_append_string(attrs, 'account_name',
                                            acc.get_name())
            gk.Attribute.list_append_string(attrs, 'username',
                                            credentials.username)

            (result, id) = gk.item_create_sync(self._KEYRING_NAME, \
                 gk.ItemType.NETWORK_PASSWORD, acc.get_name(), attrs, credentials.password, True)
            if result != gk.Result.OK:
                raise Exception("Gnome Keyring return the error code: %i" %
                                result)
            logger.debug("credentials stored with id: %i" % (id))
        finally:
            self.lock.release()
Ejemplo n.º 30
0
        raise (GnomeKeyringLocked())

    def get(self, key):
        return self._get_value_from_gnomekeyring("%s %s" % (com.APP, key))

    def set(self, key, value):
        return self._set_value_to_gnomekeyring("%s %s" % (com.APP, key), value)

    def get_password(self):
        return self.get("password")

    def set_password(self, password):
        return self.set("password", password)


if __name__ == "__main__":
    attributes = GnomeKeyring.Attribute.list_new()
    GnomeKeyring.Attribute.list_append_string(attributes, "id", str("test"))
    keyring = GnomeKeyring.get_default_keyring_sync()[1]
    value = GnomeKeyring.item_create_sync(
        keyring, GnomeKeyring.ItemType.GENERIC_SECRET, "%s preferences" % (com.APP), attributes, str("test"), True
    )

    gk = MyGnomeKeyring()
    print gk.set_password("prueba")
    print gk.get("ril_password")
    print gk.set_password("prueba")
    print gk.set("ril_password", "alfa")
    print gk.get_password()
    print gk.get("ril_password")
Ejemplo n.º 31
0
 def gkr_store(self, id, secret):
     GnomeKeyring.create_sync(KEYRING_NAME, None)
     attrs = GnomeKeyring.Attribute.list_new()
     GnomeKeyring.Attribute.list_append_string(attrs, 'id', id)
     GnomeKeyring.item_create_sync(KEYRING_NAME, GnomeKeyring.ItemType.GENERIC_SECRET, id, attrs, secret, True)
Ejemplo n.º 32
0
def insert_master_key(master_key):
    GnomeKeyring.item_create_sync(KEYRING, GnomeKeyring.ItemType.GENERIC_SECRET, 'gpwg:masterkey', GLib.Array(), master_key, 1)
Ejemplo n.º 33
0
def insert_master_key(master_key):
    GnomeKeyring.item_create_sync(KEYRING,
                                  GnomeKeyring.ItemType.GENERIC_SECRET,
                                  'gpwg:masterkey', GLib.Array(), master_key,
                                  1)
Ejemplo n.º 34
0
    def saveLoginDetails(self, user, password):
        atts = gk.Attribute.list_new()
        gk.Attribute.list_append_string(atts, "useWith", "Gusic")
        gk.Attribute.list_append_string(atts, "user", user)

        key = gk.item_create_sync("Gusic", 0, user, atts, password, True)