Procházet zdrojové kódy

Fix for old database - converting from cPickle

When converting the database from old format
object are still save as they where, so
string that where cPickle.dumps were drugged on.
This creates a bug when trying to decrypt them.
Hence reapplying the changes from previous commit
16dd14a0b09726fda4801a042493833624367103

cPickle will stay a bit longer ...
oz123 před 11 roky
rodič
revize
8d201e428e
1 změnil soubory, kde provedl 13 přidání a 2 odebrání
  1. 13 2
      pwman/util/crypto.py

+ 13 - 2
pwman/util/crypto.py

@@ -55,6 +55,7 @@ from Crypto.Random import OSRNG
 
 from pwman.util.callback import Callback
 import pwman.util.config as config
+import cPickle
 import time
 import sys
 import ctypes
@@ -325,7 +326,6 @@ password again")
                             % max_tries)
 
         key = str(key).decode('base64')
-
         self._cipher = self._getcipher_real(key,
                                             self._algo)
 
@@ -381,6 +381,7 @@ password again")
         """
         prepare data before encrypting
         """
+        #plaintext = cPickle.dumps(obj)
         plaintext = _TAG + obj
         numblocks = (len(plaintext)/blocksize) + 1
         newdatasize = blocksize*numblocks
@@ -395,7 +396,17 @@ password again")
         else:
             raise CryptoBadKeyException("Error decrypting, bad key")
 
-        return plaintext
+        try:
+            # old db version used to write stuff to db with
+            # plaintext = cPickle.dumps(obj)
+            # TODO: completely remove this block, and convert
+            # the DB to a completely plain text ...
+
+            # This implies that the coversion from OLD DATABASE FORMAT has
+            # to plain strings too ...
+            return cPickle.loads(plaintext)
+        except (TypeError, ValueError, cPickle.UnpicklingError, EOFError):
+            return plaintext
 
 
 class DummyCryptoEngine(CryptoEngine):