Пример #1
0
	def __lock_keyring(self):
		"""Method called after specified amount of time has passed"""
		if self._timeout is not None:
			GObject.source_remove(self._timeout)
			self._timeout = None

		# lock keyring
		keyring.lock_sync(self.KEYRING_NAME)

		# update information about keyring
		self.__update_info()
Пример #2
0
    def test_create_lock(self):
        '''create_sync() and locking/unlocking'''

        # create
        self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
                GnomeKeyring.Result.OK)
        (result, info) = GnomeKeyring.get_info_sync(TEST_KEYRING)
        self.assertEqual(result, GnomeKeyring.Result.OK)
        self.assertFalse(info.get_is_locked())

        # try to create already existing ring
        self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
                GnomeKeyring.Result.KEYRING_ALREADY_EXISTS)

        # lock
        self.assertEqual(GnomeKeyring.lock_sync(TEST_KEYRING),
                GnomeKeyring.Result.OK)
        self.assertTrue(GnomeKeyring.get_info_sync(TEST_KEYRING)[1].get_is_locked())

        # unlock with wrong password
        self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, 'h4ck'),
                GnomeKeyring.Result.IO_ERROR)

        # unlock with correct password
        self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, TEST_PWD),
                GnomeKeyring.Result.OK)
Пример #3
0
    def test_create_lock(self):
        '''create_sync() and locking/unlocking'''

        # create
        self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
                         GnomeKeyring.Result.OK)
        (result, info) = GnomeKeyring.get_info_sync(TEST_KEYRING)
        self.assertEqual(result, GnomeKeyring.Result.OK)
        self.assertFalse(info.get_is_locked())

        # try to create already existing ring
        self.assertEqual(GnomeKeyring.create_sync(TEST_KEYRING, TEST_PWD),
                         GnomeKeyring.Result.KEYRING_ALREADY_EXISTS)

        # lock
        self.assertEqual(GnomeKeyring.lock_sync(TEST_KEYRING),
                         GnomeKeyring.Result.OK)
        self.assertTrue(
            GnomeKeyring.get_info_sync(TEST_KEYRING)[1].get_is_locked())

        # unlock with wrong password
        self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, 'h4ck'),
                         GnomeKeyring.Result.IO_ERROR)

        # unlock with correct password
        self.assertEqual(GnomeKeyring.unlock_sync(TEST_KEYRING, TEST_PWD),
                         GnomeKeyring.Result.OK)
Пример #4
0
        result = gkr.unlock_sync(
            'login',
            getpass.getpass(prompt='Enter password for '
                            'login keyring: '))
        if result == gkr.Result.IO_ERROR:  # Incorrect password
            sys.exit(1)

    # Connect to libsecret
    service = Secret.Service.get_sync(Secret.ServiceFlags.OPEN_SESSION
                                      | Secret.ServiceFlags.LOAD_COLLECTIONS)
    collections = service.get_collections()

    # Search the default keyring
    items = service.unlock_sync(collections, None)[1][0].get_items()

    # Match the item's name using the search string as a regular expression
    found = [i for i in items if compile(sys.argv[1]).search(i.get_label())]

    if len(found):
        # Prompt the user to display any results. Use curses.wrapper to ensure
        # things are taken care of in case of a KeyboardInterrupt or other
        # exception, and that the screen is wiped afterwards.
        curses.wrapper(display_results, found)
    else:
        # Helpful feedback
        print("No matches for search term '{}'.".format(sys.argv[1]))

    # Relock the keyring if necessary
    if was_locked:
        gkr.lock_sync(KEYRING)
	def lock(self):
		result = GnomeKeyring.lock_sync(self.keyring)
		if result == GnomeKeyring.Result.OK:
			return True
		return False		
Пример #6
0
        import getpass
        result = gkr.unlock_sync('login',
                                 getpass.getpass(prompt='Enter password for '
                                                 'login keyring: '))
        if result == gkr.Result.IO_ERROR:  # Incorrect password
            sys.exit(1)

    # Connect to libsecret
    service = Secret.Service.get_sync(Secret.ServiceFlags.OPEN_SESSION |
                                      Secret.ServiceFlags.LOAD_COLLECTIONS)
    collections = service.get_collections()

    # Search the default keyring
    items = service.unlock_sync(collections, None)[1][0].get_items()

    # Match the item's name using the search string as a regular expression
    found = [i for i in items if compile(sys.argv[1]).search(i.get_label())]

    if len(found):
        # Prompt the user to display any results. Use curses.wrapper to ensure
        # things are taken care of in case of a KeyboardInterrupt or other
        # exception, and that the screen is wiped afterwards.
        curses.wrapper(display_results, found)
    else:
        # Helpful feedback
        print("No matches for search term '{}'.".format(sys.argv[1]))

    # Relock the keyring if necessary
    if was_locked:
        gkr.lock_sync(KEYRING)