예제 #1
0
파일: keyring.py 프로젝트: tjol/sunflower
	def keyring_exists(self):
		"""Check if keyring exists"""
		result = False

		if self.is_available():
			result = self.KEYRING_NAME in keyring.list_keyring_names_sync()[1]

		return result
예제 #2
0
파일: KeyRing.py 프로젝트: subutux/gusic
    def __init__(self):
        self.loginDetails = False
        if gk.is_available() is True:
            if "Gusic" in gk.list_keyring_names_sync()[1]:
                self.keyring = gk.list_item_ids_sync("Gusic")[1]

                self.loginDetails = self._get_first_key("Gusic")

            else:
                gk.create_sync("Gusic", "Gusic")
예제 #3
0
def get_gnome_keyrings():
    keyrings = {}
    for keyring_name in chk(GnomeKeyring.list_keyring_names_sync()):
        keyring_items = []
        keyrings[keyring_name] = keyring_items
        for id in chk(GnomeKeyring.list_item_ids_sync(keyring_name)):
            item = get_item(keyring_name, id)
            if item is not None:
                keyring_items.append(item)

    return keyrings
예제 #4
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
 def __init__(self):
     self._protocol = "network"
     self._key = gk.ItemType.NETWORK_PASSWORD
     if not gk.is_available():
         raise KeyringException("The Gnome keyring is not available")
     logger.debug("GnomeKeyring is available")
     self.loaded = False
     self.lock = threading.RLock()
     
     if not self.loaded:
         (result, keyring_names) = gk.list_keyring_names_sync()
         if self._KEYRING_NAME not in keyring_names:
             logger.error("Error getting the gnome keyring. We'll try to create it: %s")
             logger.debug("Creating keyring " + self._KEYRING_NAME)
             gk.create_sync(self._KEYRING_NAME, None)
         self.loaded = True
예제 #6
0
    def __init__(self):
        self._protocol = "network"
        self._key = gk.ItemType.NETWORK_PASSWORD
        if not gk.is_available():
            raise KeyringException("The Gnome keyring is not available")
        logger.debug("GnomeKeyring is available")
        self.loaded = False
        self.lock = threading.RLock()

        if not self.loaded:
            (result, keyring_names) = gk.list_keyring_names_sync()
            if self._KEYRING_NAME not in keyring_names:
                logger.error(
                    "Error getting the gnome keyring. We'll try to create it: %s"
                )
                logger.debug("Creating keyring " + self._KEYRING_NAME)
                gk.create_sync(self._KEYRING_NAME, None)
            self.loaded = True
예제 #7
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))
예제 #8
0
import sys
from gi.repository import GnomeKeyring as gk

if len(sys.argv) < 3:
    print >> sys.stderr, "invalid arguments\n    python gnomekeyring.py keyring itemname"
    exit(1)

ringname = sys.argv[1]
keyname = sys.argv[2]

(result, keyrings) = gk.list_keyring_names_sync()
if not ringname in keyrings:
    print >> sys.stderr, "keyring '%s' not found" % ringname
    exit(2)


result = gk.unlock_sync(ringname, None)
if not result == gk.Result.OK:
    print >> sys.stderr, "keyring '%s' is locked" % ringname
    exit(3)

(result, ids) = gk.list_item_ids_sync(ringname)
for id in ids:
    (result, info) = gk.item_get_info_sync(ringname, id)
    if info.get_display_name() == keyname:
        print info.get_secret()
        exit(0)

print >> sys.stderr, "keyname '%s' in '%s' not found" % (keyname, ringname)
exit(4)