Browse Source

work towards automatic db password generation

oz123 11 years ago
parent
commit
3874c4cf01
1 changed files with 14 additions and 0 deletions
  1. 14 0
      pwman/tests/db_tests.py

+ 14 - 0
pwman/tests/db_tests.py

@@ -1,6 +1,7 @@
 import os
 import os.path
 import sys
+from Crypto.Random import OSRNG
 
 if 'darwin' in sys.platform:
     from pwman.ui.mac import PwmanCliMac as PwmanCliOld
@@ -50,6 +51,19 @@ class SetupTester(object):
         dbver = 0.4
         dbtype = config.get_value("Database", "type")
         db = pwman.data.factory.create(dbtype, dbver)
+        # TODO:
+        # use db to insert an encrypted password here to the table
+        # KEY
+        # This way the key will be passed by "SELECT THEKEY FROM KEY"
+        # and there won't be a any prompting for password
+        ce = CryptoEngine()
+        ce.set_callback(raw_input)
+        random = OSRNG.new()
+        key = str(random.read(32)).encode('base64')
+        password = '12345'
+        cipher = ce._getcipher_real(password, ce._algo)
+        cipher.encrypt(ce._preparedata(key,
+                       cipher.block_size)).encode('base64')
         self.cli = PwmanCliNew(db, self.xselpath)