libpass 1.7.5.post0__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.
- libpass-1.7.5.post0.dist-info/METADATA +81 -0
- libpass-1.7.5.post0.dist-info/RECORD +69 -0
- libpass-1.7.5.post0.dist-info/WHEEL +4 -0
- libpass-1.7.5.post0.dist-info/licenses/LICENSE +116 -0
- 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/_setup/__init__.py +1 -0
- passlib/_setup/stamp.py +159 -0
- passlib/apache.py +1185 -0
- passlib/apps.py +260 -0
- passlib/context.py +2066 -0
- passlib/crypto/__init__.py +1 -0
- passlib/crypto/_blowfish/__init__.py +171 -0
- passlib/crypto/_blowfish/_gen_files.py +256 -0
- passlib/crypto/_blowfish/base.py +1239 -0
- passlib/crypto/_blowfish/unrolled.py +1691 -0
- passlib/crypto/_md4.py +249 -0
- passlib/crypto/des.py +2283 -0
- passlib/crypto/digest.py +1111 -0
- passlib/crypto/scrypt/__init__.py +299 -0
- passlib/crypto/scrypt/_builtin.py +254 -0
- passlib/crypto/scrypt/_gen_files.py +161 -0
- passlib/crypto/scrypt/_salsa.py +188 -0
- passlib/exc.py +432 -0
- passlib/ext/__init__.py +1 -0
- passlib/ext/django/__init__.py +6 -0
- passlib/ext/django/models.py +38 -0
- passlib/ext/django/utils.py +1326 -0
- passlib/handlers/__init__.py +1 -0
- passlib/handlers/argon2.py +1119 -0
- passlib/handlers/bcrypt.py +1217 -0
- passlib/handlers/cisco.py +450 -0
- passlib/handlers/des_crypt.py +642 -0
- passlib/handlers/digests.py +184 -0
- passlib/handlers/django.py +545 -0
- passlib/handlers/fshp.py +223 -0
- passlib/handlers/ldap_digests.py +379 -0
- passlib/handlers/md5_crypt.py +375 -0
- passlib/handlers/misc.py +224 -0
- passlib/handlers/mssql.py +258 -0
- passlib/handlers/mysql.py +136 -0
- passlib/handlers/oracle.py +177 -0
- passlib/handlers/pbkdf2.py +521 -0
- passlib/handlers/phpass.py +142 -0
- passlib/handlers/postgres.py +61 -0
- passlib/handlers/roundup.py +33 -0
- passlib/handlers/scram.py +589 -0
- passlib/handlers/scrypt.py +413 -0
- passlib/handlers/sha1_crypt.py +173 -0
- passlib/handlers/sha2_crypt.py +657 -0
- passlib/handlers/sun_md5_crypt.py +387 -0
- passlib/handlers/windows.py +349 -0
- passlib/hash.py +111 -0
- passlib/hosts.py +112 -0
- passlib/ifc.py +354 -0
- passlib/pwd.py +813 -0
- passlib/registry.py +583 -0
- passlib/totp.py +1968 -0
- passlib/utils/__init__.py +1221 -0
- passlib/utils/binary.py +897 -0
- passlib/utils/compat/__init__.py +200 -0
- passlib/utils/decor.py +234 -0
- passlib/utils/des.py +35 -0
- passlib/utils/handlers.py +2857 -0
- passlib/utils/md4.py +34 -0
- passlib/utils/pbkdf2.py +188 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"""passlib.handlers.mssql - MS-SQL Password Hash
|
|
2
|
+
|
|
3
|
+
Notes
|
|
4
|
+
=====
|
|
5
|
+
MS-SQL has used a number of hash algs over the years,
|
|
6
|
+
most of which were exposed through the undocumented
|
|
7
|
+
'pwdencrypt' and 'pwdcompare' sql functions.
|
|
8
|
+
|
|
9
|
+
Known formats
|
|
10
|
+
-------------
|
|
11
|
+
6.5
|
|
12
|
+
snefru hash, ascii encoded password
|
|
13
|
+
no examples found
|
|
14
|
+
|
|
15
|
+
7.0
|
|
16
|
+
snefru hash, unicode (what encoding?)
|
|
17
|
+
saw ref that these blobs were 16 bytes in size
|
|
18
|
+
no examples found
|
|
19
|
+
|
|
20
|
+
2000
|
|
21
|
+
byte string using displayed as 0x hex, using 0x0100 prefix.
|
|
22
|
+
contains hashes of password and upper-case password.
|
|
23
|
+
|
|
24
|
+
2007
|
|
25
|
+
same as 2000, but without the upper-case hash.
|
|
26
|
+
|
|
27
|
+
refs
|
|
28
|
+
----------
|
|
29
|
+
https://blogs.msdn.com/b/lcris/archive/2007/04/30/sql-server-2005-about-login-password-hashes.aspx?Redirected=true
|
|
30
|
+
http://us.generation-nt.com/securing-passwords-hash-help-35429432.html
|
|
31
|
+
http://forum.md5decrypter.co.uk/topic230-mysql-and-mssql-get-password-hashes.aspx
|
|
32
|
+
http://www.theregister.co.uk/2002/07/08/cracking_ms_sql_server_passwords/
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# =============================================================================
|
|
36
|
+
# imports
|
|
37
|
+
# =============================================================================
|
|
38
|
+
# core
|
|
39
|
+
from binascii import hexlify, unhexlify
|
|
40
|
+
from hashlib import sha1
|
|
41
|
+
import re
|
|
42
|
+
import logging
|
|
43
|
+
|
|
44
|
+
log = logging.getLogger(__name__)
|
|
45
|
+
from warnings import warn
|
|
46
|
+
|
|
47
|
+
# site
|
|
48
|
+
# pkg
|
|
49
|
+
from passlib.utils import consteq
|
|
50
|
+
from passlib.utils.compat import bascii_to_str
|
|
51
|
+
import passlib.utils.handlers as uh
|
|
52
|
+
|
|
53
|
+
# local
|
|
54
|
+
__all__ = [
|
|
55
|
+
"mssql2000",
|
|
56
|
+
"mssql2005",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# =============================================================================
|
|
61
|
+
# mssql 2000
|
|
62
|
+
# =============================================================================
|
|
63
|
+
def _raw_mssql(secret, salt):
|
|
64
|
+
assert isinstance(secret, str)
|
|
65
|
+
assert isinstance(salt, bytes)
|
|
66
|
+
return sha1(secret.encode("utf-16-le") + salt).digest()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
BIDENT = b"0x0100"
|
|
70
|
+
##BIDENT2 = b("\x01\x00")
|
|
71
|
+
UIDENT = "0x0100"
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _ident_mssql(hash, csize, bsize):
|
|
75
|
+
"""common identify for mssql 2000/2005"""
|
|
76
|
+
if isinstance(hash, str):
|
|
77
|
+
if len(hash) == csize and hash.startswith(UIDENT):
|
|
78
|
+
return True
|
|
79
|
+
elif isinstance(hash, bytes):
|
|
80
|
+
if len(hash) == csize and hash.startswith(BIDENT):
|
|
81
|
+
return True
|
|
82
|
+
##elif len(hash) == bsize and hash.startswith(BIDENT2): # raw bytes
|
|
83
|
+
## return True
|
|
84
|
+
else:
|
|
85
|
+
raise uh.exc.ExpectedStringError(hash, "hash")
|
|
86
|
+
return False
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _parse_mssql(hash, csize, bsize, handler):
|
|
90
|
+
"""common parser for mssql 2000/2005; returns 4 byte salt + checksum"""
|
|
91
|
+
if isinstance(hash, str):
|
|
92
|
+
if len(hash) == csize and hash.startswith(UIDENT):
|
|
93
|
+
try:
|
|
94
|
+
return unhexlify(hash[6:].encode("utf-8"))
|
|
95
|
+
except TypeError: # throw when bad char found
|
|
96
|
+
pass
|
|
97
|
+
elif isinstance(hash, bytes):
|
|
98
|
+
# assumes ascii-compat encoding
|
|
99
|
+
assert isinstance(hash, bytes)
|
|
100
|
+
if len(hash) == csize and hash.startswith(BIDENT):
|
|
101
|
+
try:
|
|
102
|
+
return unhexlify(hash[6:])
|
|
103
|
+
except TypeError: # throw when bad char found
|
|
104
|
+
pass
|
|
105
|
+
##elif len(hash) == bsize and hash.startswith(BIDENT2): # raw bytes
|
|
106
|
+
## return hash[2:]
|
|
107
|
+
else:
|
|
108
|
+
raise uh.exc.ExpectedStringError(hash, "hash")
|
|
109
|
+
raise uh.exc.InvalidHashError(handler)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class mssql2000(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
|
|
113
|
+
"""This class implements the password hash used by MS-SQL 2000, and follows the :ref:`password-hash-api`.
|
|
114
|
+
|
|
115
|
+
It supports a fixed-length salt.
|
|
116
|
+
|
|
117
|
+
The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:
|
|
118
|
+
|
|
119
|
+
:type salt: bytes
|
|
120
|
+
:param salt:
|
|
121
|
+
Optional salt string.
|
|
122
|
+
If not specified, one will be autogenerated (this is recommended).
|
|
123
|
+
If specified, it must be 4 bytes in length.
|
|
124
|
+
|
|
125
|
+
:type relaxed: bool
|
|
126
|
+
:param relaxed:
|
|
127
|
+
By default, providing an invalid value for one of the other
|
|
128
|
+
keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
|
|
129
|
+
and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
|
|
130
|
+
will be issued instead. Correctable errors include
|
|
131
|
+
``salt`` strings that are too long.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
# ===================================================================
|
|
135
|
+
# algorithm information
|
|
136
|
+
# ===================================================================
|
|
137
|
+
name = "mssql2000"
|
|
138
|
+
setting_kwds = ("salt",)
|
|
139
|
+
checksum_size = 40
|
|
140
|
+
min_salt_size = max_salt_size = 4
|
|
141
|
+
|
|
142
|
+
# ===================================================================
|
|
143
|
+
# formatting
|
|
144
|
+
# ===================================================================
|
|
145
|
+
|
|
146
|
+
# 0100 - 2 byte identifier
|
|
147
|
+
# 4 byte salt
|
|
148
|
+
# 20 byte checksum
|
|
149
|
+
# 20 byte checksum
|
|
150
|
+
# = 46 bytes
|
|
151
|
+
# encoded '0x' + 92 chars = 94
|
|
152
|
+
|
|
153
|
+
@classmethod
|
|
154
|
+
def identify(cls, hash):
|
|
155
|
+
return _ident_mssql(hash, 94, 46)
|
|
156
|
+
|
|
157
|
+
@classmethod
|
|
158
|
+
def from_string(cls, hash):
|
|
159
|
+
data = _parse_mssql(hash, 94, 46, cls)
|
|
160
|
+
return cls(salt=data[:4], checksum=data[4:])
|
|
161
|
+
|
|
162
|
+
def to_string(self):
|
|
163
|
+
raw = self.salt + self.checksum
|
|
164
|
+
# raw bytes format - BIDENT2 + raw
|
|
165
|
+
return "0x0100" + bascii_to_str(hexlify(raw).upper())
|
|
166
|
+
|
|
167
|
+
def _calc_checksum(self, secret):
|
|
168
|
+
if isinstance(secret, bytes):
|
|
169
|
+
secret = secret.decode("utf-8")
|
|
170
|
+
salt = self.salt
|
|
171
|
+
return _raw_mssql(secret, salt) + _raw_mssql(secret.upper(), salt)
|
|
172
|
+
|
|
173
|
+
@classmethod
|
|
174
|
+
def verify(cls, secret, hash):
|
|
175
|
+
# NOTE: we only compare against the upper-case hash
|
|
176
|
+
# XXX: add 'full' just to verify both checksums?
|
|
177
|
+
uh.validate_secret(secret)
|
|
178
|
+
self = cls.from_string(hash)
|
|
179
|
+
chk = self.checksum
|
|
180
|
+
if chk is None:
|
|
181
|
+
raise uh.exc.MissingDigestError(cls)
|
|
182
|
+
if isinstance(secret, bytes):
|
|
183
|
+
secret = secret.decode("utf-8")
|
|
184
|
+
result = _raw_mssql(secret.upper(), self.salt)
|
|
185
|
+
return consteq(result, chk[20:])
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# =============================================================================
|
|
189
|
+
# handler
|
|
190
|
+
# =============================================================================
|
|
191
|
+
class mssql2005(uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler):
|
|
192
|
+
"""This class implements the password hash used by MS-SQL 2005, and follows the :ref:`password-hash-api`.
|
|
193
|
+
|
|
194
|
+
It supports a fixed-length salt.
|
|
195
|
+
|
|
196
|
+
The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:
|
|
197
|
+
|
|
198
|
+
:type salt: bytes
|
|
199
|
+
:param salt:
|
|
200
|
+
Optional salt string.
|
|
201
|
+
If not specified, one will be autogenerated (this is recommended).
|
|
202
|
+
If specified, it must be 4 bytes in length.
|
|
203
|
+
|
|
204
|
+
:type relaxed: bool
|
|
205
|
+
:param relaxed:
|
|
206
|
+
By default, providing an invalid value for one of the other
|
|
207
|
+
keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
|
|
208
|
+
and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
|
|
209
|
+
will be issued instead. Correctable errors include
|
|
210
|
+
``salt`` strings that are too long.
|
|
211
|
+
"""
|
|
212
|
+
|
|
213
|
+
# ===================================================================
|
|
214
|
+
# algorithm information
|
|
215
|
+
# ===================================================================
|
|
216
|
+
name = "mssql2005"
|
|
217
|
+
setting_kwds = ("salt",)
|
|
218
|
+
|
|
219
|
+
checksum_size = 20
|
|
220
|
+
min_salt_size = max_salt_size = 4
|
|
221
|
+
|
|
222
|
+
# ===================================================================
|
|
223
|
+
# formatting
|
|
224
|
+
# ===================================================================
|
|
225
|
+
|
|
226
|
+
# 0x0100 - 2 byte identifier
|
|
227
|
+
# 4 byte salt
|
|
228
|
+
# 20 byte checksum
|
|
229
|
+
# = 26 bytes
|
|
230
|
+
# encoded '0x' + 52 chars = 54
|
|
231
|
+
|
|
232
|
+
@classmethod
|
|
233
|
+
def identify(cls, hash):
|
|
234
|
+
return _ident_mssql(hash, 54, 26)
|
|
235
|
+
|
|
236
|
+
@classmethod
|
|
237
|
+
def from_string(cls, hash):
|
|
238
|
+
data = _parse_mssql(hash, 54, 26, cls)
|
|
239
|
+
return cls(salt=data[:4], checksum=data[4:])
|
|
240
|
+
|
|
241
|
+
def to_string(self):
|
|
242
|
+
raw = self.salt + self.checksum
|
|
243
|
+
# raw bytes format - BIDENT2 + raw
|
|
244
|
+
return "0x0100" + bascii_to_str(hexlify(raw)).upper()
|
|
245
|
+
|
|
246
|
+
def _calc_checksum(self, secret):
|
|
247
|
+
if isinstance(secret, bytes):
|
|
248
|
+
secret = secret.decode("utf-8")
|
|
249
|
+
return _raw_mssql(secret, self.salt)
|
|
250
|
+
|
|
251
|
+
# ===================================================================
|
|
252
|
+
# eoc
|
|
253
|
+
# ===================================================================
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
# =============================================================================
|
|
257
|
+
# eof
|
|
258
|
+
# =============================================================================
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""passlib.handlers.mysql
|
|
2
|
+
|
|
3
|
+
MySQL 3.2.3 / OLD_PASSWORD()
|
|
4
|
+
|
|
5
|
+
This implements Mysql's OLD_PASSWORD algorithm, introduced in version 3.2.3, deprecated in version 4.1.
|
|
6
|
+
|
|
7
|
+
See :mod:`passlib.handlers.mysql_41` for the new algorithm was put in place in version 4.1
|
|
8
|
+
|
|
9
|
+
This algorithm is known to be very insecure, and should only be used to verify existing password hashes.
|
|
10
|
+
|
|
11
|
+
http://djangosnippets.org/snippets/1508/
|
|
12
|
+
|
|
13
|
+
MySQL 4.1.1 / NEW PASSWORD
|
|
14
|
+
This implements Mysql new PASSWORD algorithm, introduced in version 4.1.
|
|
15
|
+
|
|
16
|
+
This function is unsalted, and therefore not very secure against rainbow attacks.
|
|
17
|
+
It should only be used when dealing with mysql passwords,
|
|
18
|
+
for all other purposes, you should use a salted hash function.
|
|
19
|
+
|
|
20
|
+
Description taken from http://dev.mysql.com/doc/refman/6.0/en/password-hashing.html
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
# =============================================================================
|
|
24
|
+
# imports
|
|
25
|
+
# =============================================================================
|
|
26
|
+
# core
|
|
27
|
+
from hashlib import sha1
|
|
28
|
+
import re
|
|
29
|
+
import logging
|
|
30
|
+
|
|
31
|
+
log = logging.getLogger(__name__)
|
|
32
|
+
from warnings import warn
|
|
33
|
+
|
|
34
|
+
# site
|
|
35
|
+
# pkg
|
|
36
|
+
from passlib.utils import to_native_str
|
|
37
|
+
import passlib.utils.handlers as uh
|
|
38
|
+
|
|
39
|
+
# local
|
|
40
|
+
__all__ = [
|
|
41
|
+
"mysql323",
|
|
42
|
+
"mysq41",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# =============================================================================
|
|
47
|
+
# backend
|
|
48
|
+
# =============================================================================
|
|
49
|
+
class mysql323(uh.StaticHandler):
|
|
50
|
+
"""This class implements the MySQL 3.2.3 password hash, and follows the :ref:`password-hash-api`.
|
|
51
|
+
|
|
52
|
+
It has no salt and a single fixed round.
|
|
53
|
+
|
|
54
|
+
The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
# ===================================================================
|
|
58
|
+
# class attrs
|
|
59
|
+
# ===================================================================
|
|
60
|
+
name = "mysql323"
|
|
61
|
+
checksum_size = 16
|
|
62
|
+
checksum_chars = uh.HEX_CHARS
|
|
63
|
+
|
|
64
|
+
# ===================================================================
|
|
65
|
+
# methods
|
|
66
|
+
# ===================================================================
|
|
67
|
+
@classmethod
|
|
68
|
+
def _norm_hash(cls, hash):
|
|
69
|
+
return hash.lower()
|
|
70
|
+
|
|
71
|
+
def _calc_checksum(self, secret):
|
|
72
|
+
# FIXME: no idea if mysql has a policy about handling unicode passwords
|
|
73
|
+
if isinstance(secret, str):
|
|
74
|
+
secret = secret.encode("utf-8")
|
|
75
|
+
|
|
76
|
+
MASK_32 = 0xFFFFFFFF
|
|
77
|
+
MASK_31 = 0x7FFFFFFF
|
|
78
|
+
WHITE = b" \t"
|
|
79
|
+
|
|
80
|
+
nr1 = 0x50305735
|
|
81
|
+
nr2 = 0x12345671
|
|
82
|
+
add = 7
|
|
83
|
+
for c in secret:
|
|
84
|
+
if c in WHITE:
|
|
85
|
+
continue
|
|
86
|
+
tmp = c
|
|
87
|
+
nr1 ^= ((((nr1 & 63) + add) * tmp) + (nr1 << 8)) & MASK_32
|
|
88
|
+
nr2 = (nr2 + ((nr2 << 8) ^ nr1)) & MASK_32
|
|
89
|
+
add = (add + tmp) & MASK_32
|
|
90
|
+
return "%08x%08x" % (nr1 & MASK_31, nr2 & MASK_31)
|
|
91
|
+
|
|
92
|
+
# ===================================================================
|
|
93
|
+
# eoc
|
|
94
|
+
# ===================================================================
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# =============================================================================
|
|
98
|
+
# handler
|
|
99
|
+
# =============================================================================
|
|
100
|
+
class mysql41(uh.StaticHandler):
|
|
101
|
+
"""This class implements the MySQL 4.1 password hash, and follows the :ref:`password-hash-api`.
|
|
102
|
+
|
|
103
|
+
It has no salt and a single fixed round.
|
|
104
|
+
|
|
105
|
+
The :meth:`~passlib.ifc.PasswordHash.hash` and :meth:`~passlib.ifc.PasswordHash.genconfig` methods accept no optional keywords.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
# ===================================================================
|
|
109
|
+
# class attrs
|
|
110
|
+
# ===================================================================
|
|
111
|
+
name = "mysql41"
|
|
112
|
+
_hash_prefix = "*"
|
|
113
|
+
checksum_chars = uh.HEX_CHARS
|
|
114
|
+
checksum_size = 40
|
|
115
|
+
|
|
116
|
+
# ===================================================================
|
|
117
|
+
# methods
|
|
118
|
+
# ===================================================================
|
|
119
|
+
@classmethod
|
|
120
|
+
def _norm_hash(cls, hash):
|
|
121
|
+
return hash.upper()
|
|
122
|
+
|
|
123
|
+
def _calc_checksum(self, secret):
|
|
124
|
+
# FIXME: no idea if mysql has a policy about handling unicode passwords
|
|
125
|
+
if isinstance(secret, str):
|
|
126
|
+
secret = secret.encode("utf-8")
|
|
127
|
+
return sha1(sha1(secret).digest()).hexdigest().upper()
|
|
128
|
+
|
|
129
|
+
# ===================================================================
|
|
130
|
+
# eoc
|
|
131
|
+
# ===================================================================
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# =============================================================================
|
|
135
|
+
# eof
|
|
136
|
+
# =============================================================================
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"""passlib.handlers.oracle - Oracle DB Password Hashes"""
|
|
2
|
+
|
|
3
|
+
# =============================================================================
|
|
4
|
+
# imports
|
|
5
|
+
# =============================================================================
|
|
6
|
+
# core
|
|
7
|
+
from binascii import hexlify, unhexlify
|
|
8
|
+
from hashlib import sha1
|
|
9
|
+
import re
|
|
10
|
+
import logging
|
|
11
|
+
|
|
12
|
+
log = logging.getLogger(__name__)
|
|
13
|
+
# site
|
|
14
|
+
# pkg
|
|
15
|
+
from passlib.utils import to_unicode, xor_bytes
|
|
16
|
+
from passlib.crypto.des import des_encrypt_block
|
|
17
|
+
import passlib.utils.handlers as uh
|
|
18
|
+
|
|
19
|
+
# local
|
|
20
|
+
__all__ = ["oracle10g", "oracle11g"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# =============================================================================
|
|
24
|
+
# oracle10
|
|
25
|
+
# =============================================================================
|
|
26
|
+
def des_cbc_encrypt(key, value, iv=b"\x00" * 8, pad=b"\x00"):
|
|
27
|
+
"""performs des-cbc encryption, returns only last block.
|
|
28
|
+
|
|
29
|
+
this performs a specific DES-CBC encryption implementation
|
|
30
|
+
as needed by the Oracle10 hash. it probably won't be useful for
|
|
31
|
+
other purposes as-is.
|
|
32
|
+
|
|
33
|
+
input value is null-padded to multiple of 8 bytes.
|
|
34
|
+
|
|
35
|
+
:arg key: des key as bytes
|
|
36
|
+
:arg value: value to encrypt, as bytes.
|
|
37
|
+
:param iv: optional IV
|
|
38
|
+
:param pad: optional pad byte
|
|
39
|
+
|
|
40
|
+
:returns: last block of DES-CBC encryption of all ``value``'s byte blocks.
|
|
41
|
+
"""
|
|
42
|
+
value += pad * (-len(value) % 8) # null pad to multiple of 8
|
|
43
|
+
hash = iv # start things off
|
|
44
|
+
for offset in range(0, len(value), 8):
|
|
45
|
+
chunk = xor_bytes(hash, value[offset : offset + 8])
|
|
46
|
+
hash = des_encrypt_block(key, chunk)
|
|
47
|
+
return hash
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# magic string used as initial des key by oracle10
|
|
51
|
+
ORACLE10_MAGIC = b"\x01\x23\x45\x67\x89\xab\xcd\xef"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class oracle10(uh.HasUserContext, uh.StaticHandler):
|
|
55
|
+
"""This class implements the password hash used by Oracle up to version 10g, and follows the :ref:`password-hash-api`.
|
|
56
|
+
|
|
57
|
+
It does a single round of hashing, and relies on the username as the salt.
|
|
58
|
+
|
|
59
|
+
The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the
|
|
60
|
+
following additional contextual keywords:
|
|
61
|
+
|
|
62
|
+
:type user: str
|
|
63
|
+
:param user: name of oracle user account this password is associated with.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
# ===================================================================
|
|
67
|
+
# algorithm information
|
|
68
|
+
# ===================================================================
|
|
69
|
+
name = "oracle10"
|
|
70
|
+
checksum_chars = uh.HEX_CHARS
|
|
71
|
+
checksum_size = 16
|
|
72
|
+
|
|
73
|
+
# ===================================================================
|
|
74
|
+
# methods
|
|
75
|
+
# ===================================================================
|
|
76
|
+
@classmethod
|
|
77
|
+
def _norm_hash(cls, hash):
|
|
78
|
+
return hash.upper()
|
|
79
|
+
|
|
80
|
+
def _calc_checksum(self, secret):
|
|
81
|
+
# FIXME: not sure how oracle handles unicode.
|
|
82
|
+
# online docs about 10g hash indicate it puts ascii chars
|
|
83
|
+
# in a 2-byte encoding w/ the high byte set to null.
|
|
84
|
+
# they don't say how it handles other chars, or what encoding.
|
|
85
|
+
#
|
|
86
|
+
# so for now, encoding secret & user to utf-16-be,
|
|
87
|
+
# since that fits, and if secret/user is bytes,
|
|
88
|
+
# we assume utf-8, and decode first.
|
|
89
|
+
#
|
|
90
|
+
# this whole mess really needs someone w/ an oracle system,
|
|
91
|
+
# and some answers :)
|
|
92
|
+
if isinstance(secret, bytes):
|
|
93
|
+
secret = secret.decode("utf-8")
|
|
94
|
+
user = to_unicode(self.user, "utf-8", param="user")
|
|
95
|
+
input = (user + secret).upper().encode("utf-16-be")
|
|
96
|
+
hash = des_cbc_encrypt(ORACLE10_MAGIC, input)
|
|
97
|
+
hash = des_cbc_encrypt(hash, input)
|
|
98
|
+
return hexlify(hash).decode("ascii").upper()
|
|
99
|
+
|
|
100
|
+
# ===================================================================
|
|
101
|
+
# eoc
|
|
102
|
+
# ===================================================================
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# =============================================================================
|
|
106
|
+
# oracle11
|
|
107
|
+
# =============================================================================
|
|
108
|
+
class oracle11(uh.HasSalt, uh.GenericHandler):
|
|
109
|
+
"""This class implements the Oracle11g password hash, and follows the :ref:`password-hash-api`.
|
|
110
|
+
|
|
111
|
+
It supports a fixed-length salt.
|
|
112
|
+
|
|
113
|
+
The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords:
|
|
114
|
+
|
|
115
|
+
:type salt: str
|
|
116
|
+
:param salt:
|
|
117
|
+
Optional salt string.
|
|
118
|
+
If not specified, one will be autogenerated (this is recommended).
|
|
119
|
+
If specified, it must be 20 hexadecimal characters.
|
|
120
|
+
|
|
121
|
+
:type relaxed: bool
|
|
122
|
+
:param relaxed:
|
|
123
|
+
By default, providing an invalid value for one of the other
|
|
124
|
+
keywords will result in a :exc:`ValueError`. If ``relaxed=True``,
|
|
125
|
+
and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning`
|
|
126
|
+
will be issued instead. Correctable errors include
|
|
127
|
+
``salt`` strings that are too long.
|
|
128
|
+
|
|
129
|
+
.. versionadded:: 1.6
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
# ===================================================================
|
|
133
|
+
# class attrs
|
|
134
|
+
# ===================================================================
|
|
135
|
+
# --GenericHandler--
|
|
136
|
+
name = "oracle11"
|
|
137
|
+
setting_kwds = ("salt",)
|
|
138
|
+
checksum_size = 40
|
|
139
|
+
checksum_chars = uh.UPPER_HEX_CHARS
|
|
140
|
+
|
|
141
|
+
# --HasSalt--
|
|
142
|
+
min_salt_size = max_salt_size = 20
|
|
143
|
+
salt_chars = uh.UPPER_HEX_CHARS
|
|
144
|
+
|
|
145
|
+
# ===================================================================
|
|
146
|
+
# methods
|
|
147
|
+
# ===================================================================
|
|
148
|
+
_hash_regex = re.compile("^S:(?P<chk>[0-9a-f]{40})(?P<salt>[0-9a-f]{20})$", re.I)
|
|
149
|
+
|
|
150
|
+
@classmethod
|
|
151
|
+
def from_string(cls, hash):
|
|
152
|
+
hash = to_unicode(hash, "ascii", "hash")
|
|
153
|
+
m = cls._hash_regex.match(hash)
|
|
154
|
+
if not m:
|
|
155
|
+
raise uh.exc.InvalidHashError(cls)
|
|
156
|
+
salt, chk = m.group("salt", "chk")
|
|
157
|
+
return cls(salt=salt, checksum=chk.upper())
|
|
158
|
+
|
|
159
|
+
def to_string(self):
|
|
160
|
+
chk = self.checksum
|
|
161
|
+
hash = "S:%s%s" % (chk.upper(), self.salt.upper())
|
|
162
|
+
return hash
|
|
163
|
+
|
|
164
|
+
def _calc_checksum(self, secret):
|
|
165
|
+
if isinstance(secret, str):
|
|
166
|
+
secret = secret.encode("utf-8")
|
|
167
|
+
chk = sha1(secret + unhexlify(self.salt.encode("ascii"))).hexdigest()
|
|
168
|
+
return chk.upper()
|
|
169
|
+
|
|
170
|
+
# ===================================================================
|
|
171
|
+
# eoc
|
|
172
|
+
# ===================================================================
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# =============================================================================
|
|
176
|
+
# eof
|
|
177
|
+
# =============================================================================
|