コード例 #1
0
 def save(self, username, password):
     encoded_credentials = self._encode_credentials(username, password)
 
     item_id = self._find_keyring_item_id()
     if not item_id:
         item_id = self._create_keyring_item_info(encoded_credentials)
     else:
         item_info = self._get_keyring_item_info(item_id)
         item_info.set_secret(encoded_credentials)
         GnomeKeyring.item_set_info_sync(
             GnomeCredentialStore.KEYRING_NAME,
             item_id,
             item_info)
     logger.debug("Successfully saved new credentials to item_id: %s" % item_id)
     return True
コード例 #2
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))
コード例 #3
0
ファイル: keyring.py プロジェクト: tjol/sunflower
	def change_secret(self, entry_id, secret):
		"""Change secret for selected entry"""
		if not self.keyring_exists():
			raise InvalidKeyringError('Keyring does not exist!')

		result = False

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

		# get entry information
		info = keyring.item_get_info_sync(self.KEYRING_NAME, entry_id)[1]

		if info is not None:
			info.set_secret(secret)
			keyring.item_set_info_sync(self.KEYRING_NAME, entry_id, info)
			result = True

		return result
コード例 #4
0
    def close_button_pressed(self, dialog, response):
        if response != Gtk.ResponseType.CLOSE:
            return
        username = self.__builder.get_object("username").get_text()
        password = self.__builder.get_object("password").get_text()
        # TODO: Verify Account
        if self.__keyring_data['item']:
            self.__keyring_data['item'].set_secret('\n'.join((username, password)))
        GnomeKeyring.item_set_info_sync(None, self.__keyring_data['id'], self.__keyring_data['item'])

        enable_icon = self.__builder.get_object("enable_icon")
        enabled =enable_icon.get_active()
        self.gconf.set_bool(GCONF_KEYS['icon'], enabled)
        print("Setting to ")
        print(enabled)

        dialog.hide()

        if self.callback:
            #gconf transaction is asynch
            self.callback(enabled)
コード例 #5
0
ファイル: keyring.py プロジェクト: tjol/sunflower
	def rename_entry(self, entry, new_name):
		"""Rename entry"""
		if not self.keyring_exists():
			raise InvalidKeyringError('Keyring does not exist!')

		result = False

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

		# get entry information
		entry_id = self.__get_entry_id(entry)
		info = keyring.item_get_info_sync(self.KEYRING_NAME, entry_id)[1]

		if info is not None:
			info.set_display_name(new_name)
			keyring.item_set_info_sync(self.KEYRING_NAME, entry_id, info)
			result = True

		return result
コード例 #6
0
def main(args):
    cache_file = os.path.join(BaseDirectory.save_cache_path('password_reset'),
                              'old-passwords.gpg')
    old_password = getpass.getpass("Enter the password we are looking for: ")
    new_password = getpass.getpass("Enter the new password: "******"Failed to fetch keyrings")

        return 1

    update_count = 0

    for keyring in keyrings:
        result, items = GnomeKeyring.list_item_ids_sync(keyring)

        # Read contents of the keyring
        if result != GnomeKeyring.Result.OK:
            print("Failed to fetch keyring items from {}".format(keyring))

            continue

        # Iterate over all keys
        for itemid in items:
            result, info = GnomeKeyring.item_get_info_full_sync(
                keyring,
                itemid,
                GnomeKeyring.ItemInfoFlags.SECRET)

            if result != GnomeKeyring.Result.OK:
                print("Failed to get item {} from keyring {}".format(
                    itemid,
                    keyring))

                continue

            if check_password(info, passwords, new_password=new_password):
                result = GnomeKeyring.item_set_info_sync(keyring, itemid, info)

                if result != GnomeKeyring.Result.OK:
                    print("Failed to save item {} in keyring {}".format(
                        info.get_display_name(), keyring))
                else:
                    update_count += 1

    print("Updated {} keys".format(update_count))