Forráskód Böngészése

Deactivate old crypto module

oz123 10 éve
szülő
commit
541d390189

+ 2 - 1
.coveragerc

@@ -2,5 +2,6 @@
 omit = pwman/tests/*.py, pwman/ui/mac.py, pwman/ui/win.py, \
        pwman/data/convertdb.py, pwman/data/nodes_multiple_approach.py, \
        pwman/data/models.py, pwman/data/drivers/postgresql.py, \
-       pwman/data/drivers/mysql.py, pwman/exchange/importer.py, pwman/ui/base.py
+       pwman/data/drivers/mysql.py, pwman/exchange/importer.py, pwman/ui/base.py,
+       pwman/util/crypto.py 
 source = pwman

+ 1 - 1
pwman/data/convertdb.py

@@ -20,7 +20,7 @@ from __future__ import print_function
 import os
 import shutil
 import time
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 import pwman.data.factory
 from pwman.util.callback import CLICallback
 from pwman.data.nodes import NewNode

+ 2 - 1
pwman/data/database.py

@@ -19,10 +19,11 @@
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 #============================================================================
 
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 
 __DB_FORMAT__ = 0.5
 
+
 class DatabaseException(Exception):
     pass  # prage: no cover
 

+ 1 - 1
pwman/data/drivers/sqlite.py

@@ -24,7 +24,7 @@
 from pwman.data.database import Database, DatabaseException
 from pwman.data.database import __DB_FORMAT__
 from pwman.data.nodes import NewNode
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 import sqlite3 as sqlite
 import pwman.util.config as config
 import itertools

+ 1 - 1
pwman/data/factory.py

@@ -32,7 +32,7 @@ db.open()
 """
 from pwman.data.database import DatabaseException
 from pwman.data.drivers import sqlite
-#from pwman.data.drivers import osqlite
+
 
 class FactoryException(Exception):
 

+ 1 - 1
pwman/data/nodes.py

@@ -20,7 +20,7 @@
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 #============================================================================
 
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 
 
 class NewNode(object):

+ 1 - 1
pwman/data/tags.py

@@ -20,7 +20,7 @@
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 #============================================================================
 
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 
 
 class TagNew(object):

+ 1 - 2
pwman/tests/crypto_tests.py

@@ -1,7 +1,6 @@
 import pwman.util.config as config
 import os
-from pwman.util.crypto import (CryptoEngine, CryptoException,
-                               CryptoNoCallbackException, CryptoEngineOld)
+from pwman.util.crypto_engine import (CryptoEngine, CryptoException)
 # set cls_timout to negative number (e.g. -1) to disable
 default_config = {'Global': {'umask': '0100', 'colors': 'yes',
                              'cls_timeout': '5'

+ 1 - 3
pwman/tests/db_tests.py

@@ -24,7 +24,7 @@ from pwman.data.drivers.sqlite import DatabaseException, SQLiteDatabaseNewForm
 from pwman.util import config
 from pwman.util.config import get_pass_conf
 from pwman.util.generator import leetlist
-from pwman.util.crypto import CryptoEngine, CryptoException
+from pwman.util.crypto_engine import CryptoEngine
 from pwman import default_config, set_xsel
 from pwman.ui import get_ui_platform
 from pwman.ui.tools import CMDLoop, CliMenuItem
@@ -134,8 +134,6 @@ class DBTests(unittest.TestCase):
         enc = CryptoEngine.get()
         enc.callback = DummyCallback2()
         self.tester.cli._db.changepassword()
-        #self.assertRaises(CryptoBadKeyException,
-        #                  self.tester.cli._db.changepassword, reader=lambda x: "newsecret")
 
     def test_6_db_change_pass(self):
         "fuck yeah, we change the password and the new dummy works"

+ 1 - 1
pwman/tests/test_converter.py

@@ -25,7 +25,7 @@ from pwman.data.database import Database, DatabaseException
 from pwman.data.drivers.sqlite import SQLiteDatabaseNewForm
 from pwman.data.nodes import Node
 from pwman.data.nodes import NewNode
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 from pwman.data.tags import Tag
 from db_tests import node_factory
 from pwman.util.callback import CLICallback

+ 4 - 4
pwman/tests/test_pwman.py

@@ -21,14 +21,14 @@
 import os
 import sys
 import unittest
-from .db_tests import (DBTests, SetupTester, CLITests, ConfigTest,
+from db_tests import (DBTests, SetupTester, CLITests, ConfigTest,
                        TestDBFalseConfig, FactoryTest)
 
-from .crypto_tests import CryptoTest
-from .test_crypto_engine import CryptoEngineTest
+#from .crypto_tests import CryptoTest
+from test_crypto_engine import CryptoEngineTest
 
 if 'win' not in sys.platform:
-    from .test_complete_ui import Ferrum, NEW_DB_PATH
+    from test_complete_ui import Ferrum, NEW_DB_PATH
 
     if os.path.exists(NEW_DB_PATH):
         os.remove(NEW_DB_PATH)

+ 1 - 2
pwman/ui/base.py

@@ -21,8 +21,7 @@
 Define the base CLI interface for pwman3
 """
 from __future__ import print_function
-from pwman.util.crypto import CryptoEngine
-from pwman.util.crypto import zerome
+from pwman.util.crypto_engine import CryptoEngine, zerome
 import pwman.util.config as config
 import re
 import sys

+ 1 - 1
pwman/ui/cli.py

@@ -24,7 +24,7 @@ Define the CLI interface for pwman3 and the helper functions
 """
 from __future__ import print_function
 import pwman
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 import pwman.util.config as config
 import sys
 import cmd

+ 2 - 2
pwman/ui/win.py

@@ -35,7 +35,7 @@ import pwman.util.config as config
 from pwman.ui.cli import PwmanCliNew
 from pwman.data.nodes import NewNode
 from pwman.ui import tools
-from pwman.util.crypto import zerome
+from pwman.util.crypto_engine import zerome
 
 
 def winGetClipboard():
@@ -171,7 +171,7 @@ class PwmanCliWinNew(PwmanCliNew):
             winSetClipboard("")
         except Exception as e:
             self.error(e)
-        
+
     def do_open(self, args):
         ids = self.get_ids(args)
         if not args:

+ 2 - 34
pwman/util/crypto.py

@@ -19,28 +19,6 @@
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
 # ============================================================================
 
-"""
-Encryption Module used by PwmanDatabase
-
-Supports AES, ARC2, Blowfish, CAST, DES, DES3, IDEA, RC5.
-
-Usage:
-import pwman.util.crypto.CryptoEngine as CryptoEngine
-from pwman.util.crypto import CryptoEngine
-
-class myCallback(CryptoEngine.Callback):
-    def execute(self):
-        return "mykey"
-
-params = {'encryptionAlgorithm': 'AES',
-          'encryptionCallback': callbackFunction}
-
-CryptoEngine.init(params)
-
-crypto = CryptoEngine.get()
-ciphertext = crypto.encrypt("plaintext")
-plaintext = cyypto.decrypt(ciphertext)
-"""
 from __future__ import print_function
 from Crypto.Cipher import Blowfish as cBlowfish
 from Crypto.Cipher import AES as cAES
@@ -63,14 +41,6 @@ import hashlib
 import base64
 
 
-def zerome(string):
-    """
-    securely erase strings ...
-    for windows: ctypes.cdll.msvcrt.memset
-    """
-    bufsize = len(string) + 1
-    offset = sys.getsizeof(string) - bufsize
-    ctypes.memset(id(string) + offset, 0, bufsize)
 
 # Use this to tell if crypto is successful or not
 _TAG = "PWMANCRYPTO"
@@ -111,7 +81,7 @@ class CryptoNoCallbackException(CryptoException):
         return "CryptoNoCallbackException: " + self.message
 
 
-class CryptoEngine(object):
+class CryptoEngineO(object):
     """
     Cryptographic Engine, overrides CryptoEngineOld.
     The main change is that _getcipher_real is now hashing the key
@@ -435,7 +405,7 @@ class CryptoEngine(object):
         return plaintext
 
 
-class CryptoEngineOld(CryptoEngine):
+class CryptoEngineOld(CryptoEngineO):
 
     def _getcipher_real(self, key, algo):
         """
@@ -521,5 +491,3 @@ class CryptoEngineOld(CryptoEngine):
             return cPickle.loads(plaintext)
         except (TypeError, ValueError, cPickle.UnpicklingError, EOFError):
             return plaintext
-
-from crypto_engine import CryptoEngine

+ 11 - 0
pwman/util/crypto_engine.py

@@ -27,6 +27,7 @@ import binascii
 import time
 from pwman.util.callback import Callback
 import pwman.util.config as config
+import ctypes
 
 if sys.version_info.major > 2:  # pragma: no cover
     raw_input = input
@@ -35,6 +36,16 @@ EncodeAES = lambda c, s: base64.b64encode(c.encrypt(s))
 DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip()
 
 
+def zerome(string):
+    """
+    securely erase strings ...
+    for windows: ctypes.cdll.msvcrt.memset
+    """
+    bufsize = len(string) + 1
+    offset = sys.getsizeof(string) - bufsize
+    ctypes.memset(id(string) + offset, 0, bufsize)
+
+
 class CryptoException(Exception):
     pass
 

+ 1 - 1
scripts/pwman3

@@ -29,7 +29,7 @@ from pwman.ui.tools import CLICallback
 import pwman.util.config as config
 import pwman.data.factory
 from pwman.data.convertdb import PwmanConvertDB
-from pwman.util.crypto import CryptoEngine
+from pwman.util.crypto_engine import CryptoEngine
 
 
 def auto_convert():