Prechádzať zdrojové kódy

Add property callback to CryptoEngine

This way we can easily change "public" or "private"
access to callback
oz123 10 rokov pred
rodič
commit
c2f476e76e
3 zmenil súbory, kde vykonal 13 pridanie a 9 odobranie
  1. 1 0
      pwman/tests/test_tools.py
  2. 5 5
      pwman/ui/cli.py
  3. 7 4
      pwman/util/crypto.py

+ 1 - 0
pwman/tests/test_tools.py

@@ -89,4 +89,5 @@ class SetupTester(object):
             db = factory.create(dbtype, self.dbver, self.filename)
         else:
             db = factory.create(dbtype, self.dbver)
+
         self.cli = PwmanCliNew(db, self.xselpath, DummyCallback)

+ 5 - 5
pwman/ui/cli.py

@@ -1,4 +1,4 @@
-#============================================================================
+# ============================================================================
 # This file is part of Pwman3.
 #
 # Pwman3 is free software; you can redistribute it and/or modify
@@ -13,11 +13,11 @@
 # You should have received a copy of the GNU General Public License
 # along with Pwman3; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#============================================================================
+# ============================================================================
 # Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
-#============================================================================
+# ============================================================================
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
-#============================================================================
+# ============================================================================
 # pylint: disable=I0011
 """
 Define the CLI interface for pwman3 and the helper functions
@@ -53,7 +53,7 @@ class PwmanCliNew(cmd.Cmd, Aliases, BaseCommands):
         self.hasxsel = hasxsel
         try:
             enc = CryptoEngine.get()
-            enc._callback = callback()
+            enc.callback = callback()
             self._db = db
             #  this cascades down all the way to setting the database key
             self._db.open()

+ 7 - 4
pwman/util/crypto.py

@@ -62,6 +62,7 @@ import ctypes
 import hashlib
 import base64
 
+
 def zerome(string):
     """
     securely erase strings ...
@@ -241,6 +242,10 @@ class CryptoEngine(object):
         """
         return self._callback
 
+    @callback.setter
+    def callback(self, callback):
+        self._callback = callback
+
     def changepassword(self):
         """
         Creates a new key. The key itself is actually stored in
@@ -322,8 +327,6 @@ class CryptoEngine(object):
         if self._keycrypted is None:
             raise CryptoNoKeyException("Encryption key has not been generated")
 
-
-
     def _getcipher(self):
         """
         get cypher from user, to decrypt DB
@@ -372,8 +375,8 @@ class CryptoEngine(object):
             if sys.version_info.major > 2:
                 key = key.encode('utf-8')
             for i in range(1000):
-               key = hashlib.sha256(key)
-               key = key.digest()
+                key = hashlib.sha256(key)
+                key = key.digest()
 
             key = hashlib.sha256(key)
             cipher = cAES.new(key.digest(), cAES.MODE_ECB)