blob: 4c6650cff534e33258538adf96204a4f89730004 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
"""passlib.win32 - MS Windows support
the LMHASH and NTHASH algorithms are used in various windows related contexts,
but generally not in a manner compatible with how passlib is structured.
in particular, they have no identifying marks, both being
32 bytes of binary data. thus, they can't be easily identified
in a context with other hashes, so a CryptHandler hasn't been defined for them.
this module provided two functions to aid in any use-cases which exist.
.. warning::
these functions should not be used for new code unless an existing
system requires them, they are both known broken,
and are beyond insecure on their own.
.. autofunction:: raw_lmhash
.. autofunction:: raw_nthash
See also :mod:`passlib.drivers.nthash`.
"""
#=========================================================
#imports
#=========================================================
#core
from binascii import hexlify
#site
#pkg
from passlib.utils.des import des_encrypt_block
from passlib.drivers.import nthash
from passlib.drivers.nthash import raw_nthash
#local
__all__ = [
"nthash",
"raw_lmhash",
"raw_nthash",
]
#=========================================================
#helpers
#=========================================================
LM_MAGIC = "KGS!@#$%"
def raw_lmhash(secret, hex=False):
"encode password using des-based LMHASH algorithm; returns string of raw bytes"
#XXX: encoding should be oem ascii
ns = secret.upper()[:14] + "\x00" * (14-len(secret))
out = des_encrypt_block(ns[:7], LM_MAGIC) + des_encrypt_block(ns[7:], LM_MAGIC)
return hexlify(out) if hex else out
#=========================================================
#eoc
#=========================================================
|