From 57a79f547b13fb7cec7151d54b544c4d3c74b6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Borgstr=C3=B6m?= Date: Sun, 24 Oct 2010 22:13:34 +0200 Subject: [PATCH] Added keychain chpass --- dedupestore/archiver.py | 8 ++++++++ dedupestore/crypto.py | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dedupestore/archiver.py b/dedupestore/archiver.py index 2b144e1e3..961429779 100644 --- a/dedupestore/archiver.py +++ b/dedupestore/archiver.py @@ -83,6 +83,10 @@ class Archiver(object): def do_keychain_restrict(self, args): return KeyChain(args.input).restrict(args.output) + def do_keychain_chpass(self, args): + return KeyChain(args.keychain).chpass() + + def run(self, args=None): parser = argparse.ArgumentParser(description='Dedupestore') parser.add_argument('-k', '--key-chain', dest='keychain', type=str, @@ -105,6 +109,10 @@ class Archiver(object): subparser.add_argument('output', metavar='OUTPUT', type=str, help='Keychain to create') subparser.set_defaults(func=self.do_keychain_restrict) + subparser = subsubparsers.add_parser('chpass') + subparser.add_argument('keychain', metavar='KEYCHAIN', type=str, + help='Path to keychain') + subparser.set_defaults(func=self.do_keychain_chpass) subparser = subparsers.add_parser('create') subparser.set_defaults(func=self.do_create) diff --git a/dedupestore/crypto.py b/dedupestore/crypto.py index 80be49a86..2096c7faf 100644 --- a/dedupestore/crypto.py +++ b/dedupestore/crypto.py @@ -20,6 +20,7 @@ class KeyChain(object): def __init__(self, path=None): self.aes_id = self.rsa_read = self.rsa_create = None + self.path = path if path: self.open(path) @@ -87,13 +88,23 @@ class KeyChain(object): self.save(path, self.password) return 0 + def chpass(self): + self.rsa_read = self.rsa_read.publickey() + password, password2 = 1, 2 + while password != password2: + password = getpass('New password: ') + password2 = getpass('New password again: ') + if password != password2: + logging.error('Passwords do not match') + self.save(self.path, password) + return 0 + @staticmethod def generate(path): if os.path.exists(path): logging.error('%s already exists', path) return 1 - password = '' - password2 = 'x' + password, password2 = 1, 2 while password != password2: password = getpass('Keychain password: ') password2 = getpass('Keychain password again: ')