passlib 1.9.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passlib/__init__.py +3 -0
- passlib/_data/wordsets/bip39.txt +2049 -0
- passlib/_data/wordsets/eff_long.txt +7776 -0
- passlib/_data/wordsets/eff_prefixed.txt +1296 -0
- passlib/_data/wordsets/eff_short.txt +1296 -0
- passlib/_logging.py +3 -0
- passlib/_protocols.py +33 -0
- passlib/apache.py +1106 -0
- passlib/apps.py +215 -0
- passlib/context.py +1944 -0
- passlib/crypto/__init__.py +1 -0
- passlib/crypto/_blowfish/__init__.py +153 -0
- passlib/crypto/_blowfish/_gen_files.py +238 -0
- passlib/crypto/_blowfish/base.py +1212 -0
- passlib/crypto/_blowfish/unrolled.py +1664 -0
- passlib/crypto/_md4.py +229 -0
- passlib/crypto/des.py +2250 -0
- passlib/crypto/digest.py +760 -0
- passlib/crypto/scrypt/__init__.py +273 -0
- passlib/crypto/scrypt/_builtin.py +220 -0
- passlib/crypto/scrypt/_gen_files.py +142 -0
- passlib/crypto/scrypt/_salsa.py +180 -0
- passlib/exc.py +409 -0
- passlib/ext/__init__.py +1 -0
- passlib/ext/django/__init__.py +6 -0
- passlib/ext/django/models.py +21 -0
- passlib/ext/django/utils.py +1181 -0
- passlib/handlers/__init__.py +1 -0
- passlib/handlers/argon2.py +999 -0
- passlib/handlers/bcrypt.py +996 -0
- passlib/handlers/cisco.py +396 -0
- passlib/handlers/des_crypt.py +504 -0
- passlib/handlers/digests.py +149 -0
- passlib/handlers/django.py +510 -0
- passlib/handlers/fshp.py +185 -0
- passlib/handlers/ldap_digests.py +356 -0
- passlib/handlers/md5_crypt.py +286 -0
- passlib/handlers/misc.py +201 -0
- passlib/handlers/mssql.py +217 -0
- passlib/handlers/mysql.py +92 -0
- passlib/handlers/oracle.py +137 -0
- passlib/handlers/pbkdf2.py +454 -0
- passlib/handlers/phpass.py +110 -0
- passlib/handlers/postgres.py +34 -0
- passlib/handlers/roundup.py +18 -0
- passlib/handlers/scram.py +532 -0
- passlib/handlers/scrypt.py +357 -0
- passlib/handlers/sha1_crypt.py +121 -0
- passlib/handlers/sha2_crypt.py +562 -0
- passlib/handlers/sun_md5_crypt.py +334 -0
- passlib/handlers/windows.py +299 -0
- passlib/hash.py +106 -0
- passlib/hosts.py +85 -0
- passlib/ifc.py +307 -0
- passlib/pwd.py +709 -0
- passlib/registry.py +547 -0
- passlib/totp.py +1852 -0
- passlib/utils/__init__.py +901 -0
- passlib/utils/binary.py +852 -0
- passlib/utils/compat/__init__.py +141 -0
- passlib/utils/decor.py +220 -0
- passlib/utils/des.py +31 -0
- passlib/utils/handlers.py +2616 -0
- passlib/utils/md4.py +25 -0
- passlib/utils/pbkdf2.py +172 -0
- passlib-1.9.5.dist-info/METADATA +90 -0
- passlib-1.9.5.dist-info/RECORD +69 -0
- passlib-1.9.5.dist-info/WHEEL +4 -0
- passlib-1.9.5.dist-info/licenses/LICENSE +116 -0
passlib/hash.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""
|
|
2
|
+
passlib.hash - proxy object mapping hash scheme names -> handlers
|
|
3
|
+
|
|
4
|
+
==================
|
|
5
|
+
***** NOTICE *****
|
|
6
|
+
==================
|
|
7
|
+
|
|
8
|
+
This module does not actually contain any hashes. This file
|
|
9
|
+
is a stub that replaces itself with a proxy object.
|
|
10
|
+
|
|
11
|
+
This proxy object (passlib.registry._PasslibRegistryProxy)
|
|
12
|
+
handles lazy-loading hashes as they are requested.
|
|
13
|
+
|
|
14
|
+
The actual implementation of the various hashes is store elsewhere,
|
|
15
|
+
mainly in the submodules of the ``passlib.handlers`` subpackage.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# XXX: if any platform has problem w/ lazy modules, could support 'non-lazy'
|
|
20
|
+
# version which just imports all schemes known to list_crypt_handlers()
|
|
21
|
+
|
|
22
|
+
import sys
|
|
23
|
+
|
|
24
|
+
from passlib.registry import _proxy
|
|
25
|
+
|
|
26
|
+
sys.modules[__name__] = _proxy # type: ignore[assignment]
|
|
27
|
+
|
|
28
|
+
# =============================================================================
|
|
29
|
+
# HACK: the following bit of code is unreachable, but it's presence seems to
|
|
30
|
+
# help make autocomplete work for certain IDEs such as PyCharm.
|
|
31
|
+
# this list is automatically regenerated using $SOURCE/admin/regen.py
|
|
32
|
+
# =============================================================================
|
|
33
|
+
|
|
34
|
+
# ----------------------------------------------------
|
|
35
|
+
# begin autocomplete hack (autogenerated 2016-11-10)
|
|
36
|
+
# ----------------------------------------------------
|
|
37
|
+
if False:
|
|
38
|
+
from passlib.handlers.argon2 import argon2
|
|
39
|
+
from passlib.handlers.bcrypt import bcrypt, bcrypt_sha256
|
|
40
|
+
from passlib.handlers.cisco import cisco_asa, cisco_pix, cisco_type7
|
|
41
|
+
from passlib.handlers.des_crypt import bigcrypt, bsdi_crypt, crypt16, des_crypt
|
|
42
|
+
from passlib.handlers.digests import (
|
|
43
|
+
hex_md4,
|
|
44
|
+
hex_md5,
|
|
45
|
+
hex_sha1,
|
|
46
|
+
hex_sha256,
|
|
47
|
+
hex_sha512,
|
|
48
|
+
htdigest,
|
|
49
|
+
)
|
|
50
|
+
from passlib.handlers.django import (
|
|
51
|
+
django_argon2,
|
|
52
|
+
django_bcrypt,
|
|
53
|
+
django_bcrypt_sha256,
|
|
54
|
+
django_des_crypt,
|
|
55
|
+
django_disabled,
|
|
56
|
+
django_pbkdf2_sha1,
|
|
57
|
+
django_pbkdf2_sha256,
|
|
58
|
+
django_salted_md5,
|
|
59
|
+
django_salted_sha1,
|
|
60
|
+
)
|
|
61
|
+
from passlib.handlers.fshp import fshp
|
|
62
|
+
from passlib.handlers.ldap_digests import ( # type: ignore[attr-defined]
|
|
63
|
+
ldap_bcrypt,
|
|
64
|
+
ldap_bsdi_crypt,
|
|
65
|
+
ldap_des_crypt,
|
|
66
|
+
ldap_md5,
|
|
67
|
+
ldap_md5_crypt,
|
|
68
|
+
ldap_plaintext,
|
|
69
|
+
ldap_salted_md5,
|
|
70
|
+
ldap_salted_sha1,
|
|
71
|
+
ldap_salted_sha256,
|
|
72
|
+
ldap_salted_sha512,
|
|
73
|
+
ldap_sha1,
|
|
74
|
+
ldap_sha1_crypt,
|
|
75
|
+
ldap_sha256_crypt,
|
|
76
|
+
ldap_sha512_crypt,
|
|
77
|
+
)
|
|
78
|
+
from passlib.handlers.md5_crypt import apr_md5_crypt, md5_crypt
|
|
79
|
+
from passlib.handlers.misc import plaintext, unix_disabled
|
|
80
|
+
from passlib.handlers.mssql import mssql2000, mssql2005
|
|
81
|
+
from passlib.handlers.mysql import mysql41, mysql323
|
|
82
|
+
from passlib.handlers.oracle import oracle10, oracle11
|
|
83
|
+
from passlib.handlers.pbkdf2 import (
|
|
84
|
+
atlassian_pbkdf2_sha1,
|
|
85
|
+
cta_pbkdf2_sha1,
|
|
86
|
+
dlitz_pbkdf2_sha1,
|
|
87
|
+
grub_pbkdf2_sha512,
|
|
88
|
+
ldap_pbkdf2_sha1,
|
|
89
|
+
ldap_pbkdf2_sha256,
|
|
90
|
+
ldap_pbkdf2_sha512,
|
|
91
|
+
pbkdf2_sha1,
|
|
92
|
+
pbkdf2_sha256,
|
|
93
|
+
pbkdf2_sha512,
|
|
94
|
+
)
|
|
95
|
+
from passlib.handlers.phpass import phpass
|
|
96
|
+
from passlib.handlers.postgres import postgres_md5
|
|
97
|
+
from passlib.handlers.roundup import ldap_hex_md5, ldap_hex_sha1, roundup_plaintext
|
|
98
|
+
from passlib.handlers.scram import scram
|
|
99
|
+
from passlib.handlers.scrypt import scrypt
|
|
100
|
+
from passlib.handlers.sha1_crypt import sha1_crypt
|
|
101
|
+
from passlib.handlers.sha2_crypt import sha256_crypt, sha512_crypt
|
|
102
|
+
from passlib.handlers.sun_md5_crypt import sun_md5_crypt
|
|
103
|
+
from passlib.handlers.windows import bsd_nthash, lmhash, msdcc, msdcc2, nthash
|
|
104
|
+
# ----------------------------------------------------
|
|
105
|
+
# end autocomplete hack
|
|
106
|
+
# ----------------------------------------------------
|
passlib/hosts.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from passlib import registry
|
|
2
|
+
from passlib.context import LazyCryptContext
|
|
3
|
+
|
|
4
|
+
# local
|
|
5
|
+
__all__ = [
|
|
6
|
+
"linux_context",
|
|
7
|
+
"linux2_context",
|
|
8
|
+
"openbsd_context",
|
|
9
|
+
"netbsd_context",
|
|
10
|
+
"freebsd_context",
|
|
11
|
+
"host_context",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# known platform names - linux2
|
|
16
|
+
|
|
17
|
+
linux_context = linux2_context = LazyCryptContext(
|
|
18
|
+
schemes=["sha512_crypt", "sha256_crypt", "md5_crypt", "des_crypt", "unix_disabled"],
|
|
19
|
+
deprecated=["des_crypt"],
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# known platform names -
|
|
24
|
+
# freebsd2
|
|
25
|
+
# freebsd3
|
|
26
|
+
# freebsd4
|
|
27
|
+
# freebsd5
|
|
28
|
+
# freebsd6
|
|
29
|
+
# freebsd7
|
|
30
|
+
#
|
|
31
|
+
# netbsd1
|
|
32
|
+
|
|
33
|
+
# referencing source via -http://fxr.googlebit.com
|
|
34
|
+
# freebsd 6,7,8 - des, md5, bcrypt, bsd_nthash
|
|
35
|
+
# netbsd - des, ext, md5, bcrypt, sha1
|
|
36
|
+
# openbsd - des, ext, md5, bcrypt
|
|
37
|
+
|
|
38
|
+
freebsd_context = LazyCryptContext(
|
|
39
|
+
["bcrypt", "md5_crypt", "bsd_nthash", "des_crypt", "unix_disabled"]
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
openbsd_context = LazyCryptContext(
|
|
43
|
+
["bcrypt", "md5_crypt", "bsdi_crypt", "des_crypt", "unix_disabled"]
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
netbsd_context = LazyCryptContext(
|
|
47
|
+
["bcrypt", "sha1_crypt", "md5_crypt", "bsdi_crypt", "des_crypt", "unix_disabled"]
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
# XXX: include darwin in this list? it's got a BSD crypt variant,
|
|
51
|
+
# but that's not what it uses for user passwords.
|
|
52
|
+
|
|
53
|
+
if registry.os_crypt_present:
|
|
54
|
+
# NOTE: this is basically mimicing the output of os crypt(),
|
|
55
|
+
# except that it uses passlib's (usually stronger) defaults settings,
|
|
56
|
+
# and can be inspected and used much more flexibly.
|
|
57
|
+
|
|
58
|
+
def _iter_os_crypt_schemes():
|
|
59
|
+
"""helper which iterates over supported os_crypt schemes"""
|
|
60
|
+
out = registry.get_supported_os_crypt_schemes()
|
|
61
|
+
if out:
|
|
62
|
+
# only offer disabled handler if there's another scheme in front,
|
|
63
|
+
# as this can't actually hash any passwords
|
|
64
|
+
out += ("unix_disabled",)
|
|
65
|
+
return out
|
|
66
|
+
|
|
67
|
+
host_context = LazyCryptContext(_iter_os_crypt_schemes())
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# known platform strings -
|
|
71
|
+
# aix3
|
|
72
|
+
# aix4
|
|
73
|
+
# atheos
|
|
74
|
+
# beos5
|
|
75
|
+
# darwin
|
|
76
|
+
# generic
|
|
77
|
+
# hp-ux11
|
|
78
|
+
# irix5
|
|
79
|
+
# irix6
|
|
80
|
+
# mac
|
|
81
|
+
# next3
|
|
82
|
+
# os2emx
|
|
83
|
+
# riscos
|
|
84
|
+
# sunos5
|
|
85
|
+
# unixware7
|
passlib/ifc.py
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
|
|
5
|
+
from passlib.utils.decor import deprecated_method
|
|
6
|
+
|
|
7
|
+
# local
|
|
8
|
+
__all__ = [
|
|
9
|
+
"PasswordHash",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PasswordHash(ABC):
|
|
14
|
+
"""This class describes an abstract interface which all password hashes
|
|
15
|
+
in Passlib adhere to. Under Python 2.6 and up, this is an actual
|
|
16
|
+
Abstract Base Class built using the :mod:`!abc` module.
|
|
17
|
+
|
|
18
|
+
See the Passlib docs for full documentation.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
# ---------------------------------------------------------------
|
|
22
|
+
# general information
|
|
23
|
+
# ---------------------------------------------------------------
|
|
24
|
+
##name
|
|
25
|
+
##setting_kwds
|
|
26
|
+
##context_kwds
|
|
27
|
+
|
|
28
|
+
#: flag which indicates this hasher matches a "disabled" hash
|
|
29
|
+
#: (e.g. unix_disabled, or django_disabled); and doesn't actually
|
|
30
|
+
#: depend on the provided password.
|
|
31
|
+
is_disabled = False
|
|
32
|
+
|
|
33
|
+
#: Should be None, or a positive integer indicating hash
|
|
34
|
+
#: doesn't support secrets larger than this value.
|
|
35
|
+
#: Whether hash throws error or silently truncates secret
|
|
36
|
+
#: depends on .truncate_error and .truncate_verify_reject flags below.
|
|
37
|
+
#: NOTE: calls may treat as boolean, since value will never be 0.
|
|
38
|
+
#: .. versionadded:: 1.7
|
|
39
|
+
#: .. TODO: passlib 1.8: deprecate/rename this attr to "max_secret_size"?
|
|
40
|
+
truncate_size: int | None = None
|
|
41
|
+
|
|
42
|
+
# NOTE: these next two default to the optimistic "ideal",
|
|
43
|
+
# most hashes in passlib have to default to False
|
|
44
|
+
# for backward compat and/or expected behavior with existing hashes.
|
|
45
|
+
|
|
46
|
+
#: If True, .hash() should throw a :exc:`~passlib.exc.PasswordSizeError` for
|
|
47
|
+
#: any secrets larger than .truncate_size. Many hashers default to False
|
|
48
|
+
#: for historical / compatibility purposes, indicating they will silently
|
|
49
|
+
#: truncate instead. All such hashers SHOULD support changing
|
|
50
|
+
#: the policy via ``.using(truncate_error=True)``.
|
|
51
|
+
#: .. versionadded:: 1.7
|
|
52
|
+
#: .. TODO: passlib 1.8: deprecate/rename this attr to "truncate_hash_error"?
|
|
53
|
+
truncate_error = True
|
|
54
|
+
|
|
55
|
+
#: If True, .verify() should reject secrets larger than max_password_size.
|
|
56
|
+
#: Many hashers default to False for historical / compatibility purposes,
|
|
57
|
+
#: indicating they will match on the truncated portion instead.
|
|
58
|
+
#: .. versionadded:: 1.7.1
|
|
59
|
+
truncate_verify_reject = True
|
|
60
|
+
|
|
61
|
+
# ---------------------------------------------------------------
|
|
62
|
+
# salt information -- if 'salt' in setting_kwds
|
|
63
|
+
# ---------------------------------------------------------------
|
|
64
|
+
##min_salt_size
|
|
65
|
+
##max_salt_size
|
|
66
|
+
##default_salt_size
|
|
67
|
+
##salt_chars
|
|
68
|
+
##default_salt_chars
|
|
69
|
+
|
|
70
|
+
# ---------------------------------------------------------------
|
|
71
|
+
# rounds information -- if 'rounds' in setting_kwds
|
|
72
|
+
# ---------------------------------------------------------------
|
|
73
|
+
##min_rounds
|
|
74
|
+
##max_rounds
|
|
75
|
+
##default_rounds
|
|
76
|
+
##rounds_cost
|
|
77
|
+
|
|
78
|
+
# ---------------------------------------------------------------
|
|
79
|
+
# encoding info -- if 'encoding' in context_kwds
|
|
80
|
+
# ---------------------------------------------------------------
|
|
81
|
+
##default_encoding
|
|
82
|
+
@classmethod
|
|
83
|
+
@abstractmethod
|
|
84
|
+
def hash(
|
|
85
|
+
cls,
|
|
86
|
+
secret, # *
|
|
87
|
+
**setting_and_context_kwds,
|
|
88
|
+
): # pragma: no cover -- abstract method
|
|
89
|
+
r"""
|
|
90
|
+
Hash secret, returning result.
|
|
91
|
+
Should handle generating salt, etc, and should return string
|
|
92
|
+
containing identifier, salt & other configuration, as well as digest.
|
|
93
|
+
|
|
94
|
+
:param \\*\\*settings_kwds:
|
|
95
|
+
|
|
96
|
+
Pass in settings to customize configuration of resulting hash.
|
|
97
|
+
|
|
98
|
+
.. deprecated:: 1.7
|
|
99
|
+
|
|
100
|
+
Starting with Passlib 1.7, callers should no longer pass settings keywords
|
|
101
|
+
(e.g. ``rounds`` or ``salt`` directly to :meth:`!hash`); should use
|
|
102
|
+
``.using(**settings).hash(secret)`` construction instead.
|
|
103
|
+
|
|
104
|
+
Support will be removed in Passlib 2.0.
|
|
105
|
+
|
|
106
|
+
:param \\*\\*context_kwds:
|
|
107
|
+
|
|
108
|
+
Specific algorithms may require context-specific information (such as the user login).
|
|
109
|
+
"""
|
|
110
|
+
# FIXME: need stub for classes that define .encrypt() instead ...
|
|
111
|
+
# this should call .encrypt(), and check for recursion back to here.
|
|
112
|
+
raise NotImplementedError("must be implemented by subclass")
|
|
113
|
+
|
|
114
|
+
@deprecated_method(deprecated="1.7", removed="2.0", replacement=".hash()")
|
|
115
|
+
@classmethod
|
|
116
|
+
def encrypt(cls, *args, **kwds):
|
|
117
|
+
"""
|
|
118
|
+
Legacy alias for :meth:`hash`.
|
|
119
|
+
|
|
120
|
+
.. deprecated:: 1.7
|
|
121
|
+
This method was renamed to :meth:`!hash` in version 1.7.
|
|
122
|
+
This alias will be removed in version 2.0, and should only
|
|
123
|
+
be used for compatibility with Passlib 1.3 - 1.6.
|
|
124
|
+
"""
|
|
125
|
+
return cls.hash(*args, **kwds)
|
|
126
|
+
|
|
127
|
+
# XXX: could provide default implementation which hands value to
|
|
128
|
+
# hash(), and then does constant-time comparision on the result
|
|
129
|
+
# (after making both are same string type)
|
|
130
|
+
@classmethod
|
|
131
|
+
@abstractmethod
|
|
132
|
+
def verify(
|
|
133
|
+
cls, secret, hash, **context_kwds
|
|
134
|
+
): # pragma: no cover -- abstract method
|
|
135
|
+
"""verify secret against hash, returns True/False"""
|
|
136
|
+
raise NotImplementedError("must be implemented by subclass")
|
|
137
|
+
|
|
138
|
+
@classmethod
|
|
139
|
+
@abstractmethod
|
|
140
|
+
def using(cls, relaxed=False, **kwds):
|
|
141
|
+
"""
|
|
142
|
+
Return another hasher object (typically a subclass of the current one),
|
|
143
|
+
which integrates the configuration options specified by ``kwds``.
|
|
144
|
+
This should *always* return a new object, even if no configuration options are changed.
|
|
145
|
+
|
|
146
|
+
.. todo::
|
|
147
|
+
|
|
148
|
+
document which options are accepted.
|
|
149
|
+
|
|
150
|
+
:returns:
|
|
151
|
+
typically returns a subclass for most hasher implementations.
|
|
152
|
+
|
|
153
|
+
.. todo::
|
|
154
|
+
|
|
155
|
+
add this method to main documentation.
|
|
156
|
+
"""
|
|
157
|
+
raise NotImplementedError("must be implemented by subclass")
|
|
158
|
+
|
|
159
|
+
@classmethod
|
|
160
|
+
def needs_update(cls, hash, secret=None):
|
|
161
|
+
"""
|
|
162
|
+
check if hash's configuration is outside desired bounds,
|
|
163
|
+
or contains some other internal option which requires
|
|
164
|
+
updating the password hash.
|
|
165
|
+
|
|
166
|
+
:param hash:
|
|
167
|
+
hash string to examine
|
|
168
|
+
|
|
169
|
+
:param secret:
|
|
170
|
+
optional secret known to have verified against the provided hash.
|
|
171
|
+
(this is used by some hashes to detect legacy algorithm mistakes).
|
|
172
|
+
|
|
173
|
+
:return:
|
|
174
|
+
whether secret needs re-hashing.
|
|
175
|
+
|
|
176
|
+
.. versionadded:: 1.7
|
|
177
|
+
"""
|
|
178
|
+
# by default, always report that we don't need update
|
|
179
|
+
return False
|
|
180
|
+
|
|
181
|
+
@classmethod
|
|
182
|
+
@abstractmethod
|
|
183
|
+
def identify(cls, hash): # pragma: no cover -- abstract method
|
|
184
|
+
"""check if hash belongs to this scheme, returns True/False"""
|
|
185
|
+
raise NotImplementedError("must be implemented by subclass")
|
|
186
|
+
|
|
187
|
+
@deprecated_method(deprecated="1.7", removed="2.0")
|
|
188
|
+
@classmethod
|
|
189
|
+
def genconfig(cls, **setting_kwds): # pragma: no cover -- abstract method
|
|
190
|
+
"""
|
|
191
|
+
compile settings into a configuration string for genhash()
|
|
192
|
+
|
|
193
|
+
.. deprecated:: 1.7
|
|
194
|
+
|
|
195
|
+
As of 1.7, this method is deprecated, and slated for complete removal in Passlib 2.0.
|
|
196
|
+
|
|
197
|
+
For all known real-world uses, hashing a constant string
|
|
198
|
+
should provide equivalent functionality.
|
|
199
|
+
|
|
200
|
+
This deprecation may be reversed if a use-case presents itself in the mean time.
|
|
201
|
+
"""
|
|
202
|
+
# NOTE: this fallback runs full hash alg, w/ whatever cost param is passed along.
|
|
203
|
+
# implementations (esp ones w/ variable cost) will want to subclass this
|
|
204
|
+
# with a constant-time implementation that just renders a config string.
|
|
205
|
+
if cls.context_kwds:
|
|
206
|
+
raise NotImplementedError("must be implemented by subclass")
|
|
207
|
+
return cls.using(**setting_kwds).hash("")
|
|
208
|
+
|
|
209
|
+
@deprecated_method(deprecated="1.7", removed="2.0")
|
|
210
|
+
@classmethod
|
|
211
|
+
def genhash(cls, secret, config, **context):
|
|
212
|
+
"""
|
|
213
|
+
generated hash for secret, using settings from config/hash string
|
|
214
|
+
|
|
215
|
+
.. deprecated:: 1.7
|
|
216
|
+
|
|
217
|
+
As of 1.7, this method is deprecated, and slated for complete removal in Passlib 2.0.
|
|
218
|
+
|
|
219
|
+
This deprecation may be reversed if a use-case presents itself in the mean time.
|
|
220
|
+
"""
|
|
221
|
+
# XXX: if hashes reliably offered a .parse() method, could make a fallback for this.
|
|
222
|
+
raise NotImplementedError("must be implemented by subclass")
|
|
223
|
+
|
|
224
|
+
# the following entry points are used internally by passlib,
|
|
225
|
+
# and aren't documented as part of the exposed interface.
|
|
226
|
+
# they are subject to change between releases,
|
|
227
|
+
# but are documented here so there's a list of them *somewhere*.
|
|
228
|
+
|
|
229
|
+
# ---------------------------------------------------------------
|
|
230
|
+
# extra metdata
|
|
231
|
+
# ---------------------------------------------------------------
|
|
232
|
+
|
|
233
|
+
#: this attribute shouldn't be used by hashers themselves,
|
|
234
|
+
#: it's reserved for the CryptContext to track which hashers are deprecated.
|
|
235
|
+
#: Note the context will only set this on objects it owns (and generated by .using()),
|
|
236
|
+
#: and WONT set it on global objects.
|
|
237
|
+
#: [added in 1.7]
|
|
238
|
+
#: TODO: document this, or at least the use of testing for
|
|
239
|
+
#: 'CryptContext().handler().deprecated'
|
|
240
|
+
deprecated = False
|
|
241
|
+
|
|
242
|
+
#: optionally present if hasher corresponds to format built into Django.
|
|
243
|
+
#: this attribute (if not None) should be the Django 'algorithm' name.
|
|
244
|
+
#: also indicates to passlib.ext.django that (when installed in django),
|
|
245
|
+
#: django's native hasher should be used in preference to this one.
|
|
246
|
+
## django_name
|
|
247
|
+
|
|
248
|
+
# ---------------------------------------------------------------
|
|
249
|
+
# checksum information - defined for many hashes
|
|
250
|
+
# ---------------------------------------------------------------
|
|
251
|
+
## checksum_chars
|
|
252
|
+
## checksum_size
|
|
253
|
+
|
|
254
|
+
# ---------------------------------------------------------------
|
|
255
|
+
# experimental methods
|
|
256
|
+
# ---------------------------------------------------------------
|
|
257
|
+
|
|
258
|
+
##@classmethod
|
|
259
|
+
##def normhash(cls, hash):
|
|
260
|
+
## """helper to clean up non-canonic instances of hash.
|
|
261
|
+
## currently only provided by bcrypt() to fix an historical passlib issue.
|
|
262
|
+
## """
|
|
263
|
+
|
|
264
|
+
# experimental helper to parse hash into components.
|
|
265
|
+
##@classmethod
|
|
266
|
+
##def parsehash(cls, hash, checksum=True, sanitize=False):
|
|
267
|
+
## """helper to parse hash into components, returns dict"""
|
|
268
|
+
|
|
269
|
+
# experiment helper to estimate bitsize of different hashes,
|
|
270
|
+
# implement for GenericHandler, but may be currently be off for some hashes.
|
|
271
|
+
# want to expand this into a way to programmatically compare
|
|
272
|
+
# "strengths" of different hashes and hash algorithms.
|
|
273
|
+
# still needs to have some factor for estimate relative cost per round,
|
|
274
|
+
# ala in the style of the scrypt whitepaper.
|
|
275
|
+
##@classmethod
|
|
276
|
+
##def bitsize(cls, **kwds):
|
|
277
|
+
## """returns dict mapping component -> bits contributed.
|
|
278
|
+
## components currently include checksum, salt, rounds.
|
|
279
|
+
## """
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class DisabledHash(PasswordHash):
|
|
283
|
+
"""
|
|
284
|
+
extended disabled-hash methods; only need be present if .disabled = True
|
|
285
|
+
"""
|
|
286
|
+
|
|
287
|
+
is_disabled = True
|
|
288
|
+
|
|
289
|
+
@classmethod
|
|
290
|
+
def disable(cls, hash=None):
|
|
291
|
+
"""
|
|
292
|
+
return string representing a 'disabled' hash;
|
|
293
|
+
optionally including previously enabled hash
|
|
294
|
+
(this is up to the individual scheme).
|
|
295
|
+
"""
|
|
296
|
+
# default behavior: ignore original hash, return standalone marker
|
|
297
|
+
return cls.hash("")
|
|
298
|
+
|
|
299
|
+
@classmethod
|
|
300
|
+
def enable(cls, hash):
|
|
301
|
+
"""
|
|
302
|
+
given a disabled-hash string,
|
|
303
|
+
extract previously-enabled hash if one is present,
|
|
304
|
+
otherwise raises ValueError
|
|
305
|
+
"""
|
|
306
|
+
# default behavior: no way to restore original hash
|
|
307
|
+
raise ValueError("cannot restore original hash")
|