diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-03-17 17:54:48 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-03-17 17:54:48 -0400 |
| commit | b038c662c529e89357da625f408d4933a820e0e2 (patch) | |
| tree | 78ae566b5835f2328c44098ebdd754d415cee213 | |
| parent | 72b370d8506a8a494e6841ffc4673ed63fdcfef4 (diff) | |
| download | passlib-b038c662c529e89357da625f408d4933a820e0e2.tar.gz | |
disabled pure-python bcrypt backend - just too painfully slow to count as "supporting" bcrypt
| -rw-r--r-- | passlib/drivers/bcrypt.py | 39 | ||||
| -rw-r--r-- | passlib/tests/test_drivers.py | 10 | ||||
| -rw-r--r-- | passlib/tests/utils.py | 8 | ||||
| -rw-r--r-- | passlib/utils/drivers.py | 6 |
4 files changed, 41 insertions, 22 deletions
diff --git a/passlib/drivers/bcrypt.py b/passlib/drivers/bcrypt.py index 4c50a79..a8932e6 100644 --- a/passlib/drivers/bcrypt.py +++ b/passlib/drivers/bcrypt.py @@ -25,7 +25,7 @@ from passlib.utils import os_crypt, classproperty from passlib.utils.drivers import BackendExtHash #TODO: make this a lazy import, generally don't want to load it. -from passlib.utils._slow_bcrypt import raw_bcrypt as slow_raw_bcrypt +##from passlib.utils._slow_bcrypt import raw_bcrypt as slow_raw_bcrypt #pkg #local @@ -58,14 +58,18 @@ class bcrypt(BackendExtHash): Typically you want to leave this alone, and let it default to ``2a``, but it can be set to ``2`` to use the older version of BCrypt. - It will use the first available of three possible backends: + It will use the first available of two possible backends: * `py-bcrypt <http://www.mindrot.org/projects/py-bcrypt/>`_, if installed. * stdlib :func:`crypt()`, if the host OS supports BCrypt. - * a pure python implementation of BCrypt built into passlib (very slow). You can see which backend is in use by calling the :meth:`get_backend()` method. """ + + #NOTE: the builtin implementation has been disabled, + # as it is pure python and about ~500 times slower than pybcrypt. +## * a pure python implementation of BCrypt built into passlib. + #========================================================= #class attrs #========================================================= @@ -134,12 +138,13 @@ class bcrypt(BackendExtHash): #========================================================= #primary interface #========================================================= - backends = ("pybcrypt", "os_crypt", "builtin") + backends = ("pybcrypt", "os_crypt") - _has_backend_builtin = True + ##_has_backend_builtin = True @classproperty def _has_backend_pybcrypt(cls): + return False return pybcrypt_hashpw is not None @classproperty @@ -155,16 +160,20 @@ class bcrypt(BackendExtHash): ) @classmethod - def set_backend(cls, name=None): - result = super(bcrypt, cls).set_backend(name) - #issue warning if builtin is ever chosen by default - # (but if they explicitly ask for it, let it happen) - if name != "builtin" and result == "builtin": - warn("PassLib's builtin bcrypt is too slow for production use; PLEASE INSTALL pybcrypt") - return result - - def _calc_checksum_builtin(self, secret): - return slow_raw_bcrypt(secret, self.ident, self.salt, self.rounds) + def _no_backends_msg(cls): + return "no BCrypt backends available - please install pybcrypt for BCrypt support" + + ##@classmethod + ##def set_backend(cls, name=None): + ## result = super(bcrypt, cls).set_backend(name) + ## #issue warning if builtin is ever chosen by default + ## # (but if they explicitly ask for it, let it happen) + ## if name != "builtin" and result == "builtin": + ## warn("PassLib's builtin bcrypt is too slow for production use; PLEASE INSTALL pybcrypt") + ## return result + + ##def _calc_checksum_builtin(self, secret): + ## return slow_raw_bcrypt(secret, self.ident, self.salt, self.rounds) def _calc_checksum_os_crypt(self, secret): if isinstance(secret, unicode): diff --git a/passlib/tests/test_drivers.py b/passlib/tests/test_drivers.py index 93c229f..e5affc1 100644 --- a/passlib/tests/test_drivers.py +++ b/passlib/tests/test_drivers.py @@ -59,11 +59,17 @@ class BCryptTest(HandlerCase): '$2a$6$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.' ] +try: + bcrypt.get_backend() +except EnvironmentError: + #no bcrypt backends available! + BCryptTest = None + #NOTE: pybcrypt backend will be chosen as primary if possible, so just check for os crypt and builtin OsCrypt_BCryptTest = create_backend_case(BCryptTest, "os_crypt") -#this one's unusuablly slow, don't test it unless user asks for it. -Builtin_BCryptTest = create_backend_case(BCryptTest, "builtin") if enable_option("slow") else None +###this one's unusuablly slow, don't test it unless user asks for it. +##Builtin_BCryptTest = create_backend_case(BCryptTest, "builtin") if enable_option("slow") else None #========================================================= #bigcrypt diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index e44db7a..336f711 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -49,11 +49,9 @@ def enable_option(*names): """check if a given test should be included based on the env var. test flags: - all run ALL tests - backends test active backends + active-backends test active backends all-backends test ALL backends, even the inactive ones - - slow required to enable really slow tests (eg builtin bcrypt backend) + all run ALL tests """ return 'all' in tests or any(name in tests for name in names) @@ -610,6 +608,8 @@ def enable_backend_case(handler, name): def create_backend_case(base_test, name): "create a test case (subclassing); if test doesn't need to be enabled, returns None" + if base_test is None: + return None handler = base_test.handler if not enable_backend_case(handler, name): diff --git a/passlib/utils/drivers.py b/passlib/utils/drivers.py index 2d210ee..e65bc17 100644 --- a/passlib/utils/drivers.py +++ b/passlib/utils/drivers.py @@ -534,6 +534,10 @@ class BackendExtHash(ExtHash): return getattr(cls, "_has_backend_" + name) @classmethod + def _no_backends_msg(cls): + return "no %s backends available" % (cls.name,) + + @classmethod def set_backend(cls, name=None): "change class to use specified backend" if not name: @@ -544,7 +548,7 @@ class BackendExtHash(ExtHash): if cls.has_backend(name): break else: - raise EnvironmentError, "no %s backends available" % (cls.name,) + raise EnvironmentError, cls._no_backends_msg() elif not cls.has_backend(name): raise ValueError, "%s backend not available: %r" % (cls.name, name) cls.calc_checksum = getattr(cls, "_calc_checksum_" + name) |
