def on_unlock_clicked(self, widget): """Attempt to unlock the keychain.""" print("Unlocking!") print(widget) my_keychain = Keychain(path=DEFAULT_KEYCHAIN_PATH) my_keychain.unlock(widget.get_text()) self.close()
def test_unlock_and_read_web_form_password(self): keychain = Keychain(path=self.keychain_path) unlock_result = keychain.unlock("wrong-password") self.assertFalse(unlock_result) unlock_result = keychain.unlock("badger") self.assertTrue(unlock_result) self.assertIsNone(keychain.item("does-not-exist")) self.assertEquals("123456", keychain.item("onetosix").password) self.assertEquals("abcdef", keychain.item("atof").password)
def __init__(self, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, getpass=getpass.getpass, arguments=sys.argv[1:]): self.stdin = stdin self.stdout = stdout self.stderr = stderr self.getpass = getpass self.arguments = self.argument_parser().parse_args(arguments) self.keychain = Keychain(self.arguments.path)
def test_unlock_and_read_with_fuzzy_matching(self): keychain = Keychain(path=self.keychain_path) keychain.unlock("badger") item = keychain.item("foobr", fuzzy_threshold=70) self.assertEquals("foobar", item.password)
def test_unlock_and_read_generic_account_password(self): keychain = Keychain(path=self.keychain_path) keychain.unlock("badger") self.assertEquals("flibble", keychain.item("Generic Account").password)
def test_unlock_and_read_generated_password(self): keychain = Keychain(path=self.keychain_path) keychain.unlock("badger") self.assertEquals("foobar", keychain.item("foobar").password)
def test_key_by_id_with_bad_id(self): keychain = Keychain(self.data_path) key = keychain.key(identifier="not-a-real-key") self.assertIsNone(key)
def test_key_by_id(self): keychain = Keychain(self.data_path) key = keychain.key(identifier="525E210E0B4C49799D7E47DD8E789C78") self.assertEquals("525E210E0B4C49799D7E47DD8E789C78", key.identifier) self.assertEquals("SL5", key.level)
def test_key_by_id_with_bad_security_level(self): keychain = Keychain(self.data_path) key = keychain.key(security_level="not-a-real-key") self.assertIsNone(key)
def test_locked_flag(self): keychain = Keychain(self.data_path) self.assertTrue(keychain.locked) self.assertTrue(keychain.unlock("badger")) self.assertFalse(keychain.locked)
import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), "..")) from onepassword import Keychain DEFAULT_KEYCHAIN_PATH = "~/Dropbox/1Password.agilekeychain" parser = argparse.ArgumentParser() parser.add_argument("item", help="The name of the password to decrypt") parser.add_argument("--path", default=os.environ.get('ONEPASSWORD_KEYCHAIN', DEFAULT_KEYCHAIN_PATH), help="Path to your 1Password.agilekeychain file") args = parser.parse_args() keychain = Keychain(args.path) while keychain.locked: try: keychain.unlock(getpass("Master password: "******"") sys.exit(0) item = keychain.item(args.item) if item is not None: print(repr(item._data['notesPlain'])) else: sys.stderr.write("Could not find a item named '%s'\n" % args.item) sys.exit(1)