Browse Source

Added keychain chpass

Jonas Borgström 14 years ago
parent
commit
57a79f547b
2 changed files with 21 additions and 2 deletions
  1. 8 0
      dedupestore/archiver.py
  2. 13 2
      dedupestore/crypto.py

+ 8 - 0
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)

+ 13 - 2
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: ')