Python 3.8 中的 MD4 hashlib 支持
MD4 hashlib support in Python 3.8
我正在尝试为使用 NTLM 身份验证的服务器实现 soap 客户端。我使用的库(依赖于ntlm-auth的requests-ntlm2)通过标准库的hashlib实现了位于NTLM协议核心的MD4算法。
虽然hashlib好像支持MD4:
>>> import hashlib
>>> hashlib.algorithms_available
{'md5-sha1', 'md4', 'shake_128', 'md5', 'blake2s', 'sha3_512', 'ripemd160', 'sha512', 'mdc2', 'blake2b', 'sha3_256', 'sha3_224', 'sha512_224', 'sha1', 'sha384', 'sha256', 'sha224', 'whirlpool', 'sha512_256', 'sha3_384', 'shake_256', 'sm3'}
>>>
我系统中的 openssl 库也是如此:
(victory) C:\code\python\services>openssl
help:
[...]
Message Digest commands (see the `dgst' command for more details)
blake2b512 blake2s256 md4 md5
mdc2 rmd160 sha1 sha224
sha256 sha3-224 sha3-256 sha3-384
sha3-512 sha384 sha512 sha512-224
sha512-256 shake128 shake256 sm3
[...]
当身份验证尝试 运行 python 时会产生 ValueError: unsupported hash type md4 错误。这是回溯的相关部分:
C:\ProgramData\Miniconda3\envs\victory\lib\site-packages\ntlm_auth\compute_hash.py in _ntowfv1(password)
165 return nt_hash
166
--> 167 digest = hashlib.new('md4', password.encode('utf-16-le')).digest()
168
169 return digest
C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py in __hash_new(name, data, **kwargs)
161 # This allows for SHA224/256 and SHA384/512 support even though
162 # the OpenSSL library prior to 0.9.8 doesn't provide them.
--> 163 return __get_builtin_constructor(name)(data)
164
165
C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py in __get_builtin_constructor(name)
118 return constructor
119
--> 120 raise ValueError('unsupported hash type ' + name)
121
122
ValueError: unsupported hash type md4
即使我尝试仅从 hashlib 调用 MD4,我也会得到相同的结果:
>>> import hashlib
>>> hashlib.new('md4')
Traceback (most recent call last):
File "C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py", line 157, in __hash_new
return _hashlib.new(name, data)
ValueError: [digital envelope routines] initialization error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py", line 163, in __hash_new
return __get_builtin_constructor(name)(data)
File "C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py", line 120, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md4
任何关于正在发生的事情的见解and/or任何帮助将不胜感激。
好吧,我的 conda 环境中似乎有什么东西被破坏了。我创建了一个新的相同的,从那以后它一直在工作,无需更改任何其他内容。
我正在尝试为使用 NTLM 身份验证的服务器实现 soap 客户端。我使用的库(依赖于ntlm-auth的requests-ntlm2)通过标准库的hashlib实现了位于NTLM协议核心的MD4算法。
虽然hashlib好像支持MD4:
>>> import hashlib
>>> hashlib.algorithms_available
{'md5-sha1', 'md4', 'shake_128', 'md5', 'blake2s', 'sha3_512', 'ripemd160', 'sha512', 'mdc2', 'blake2b', 'sha3_256', 'sha3_224', 'sha512_224', 'sha1', 'sha384', 'sha256', 'sha224', 'whirlpool', 'sha512_256', 'sha3_384', 'shake_256', 'sm3'}
>>>
我系统中的 openssl 库也是如此:
(victory) C:\code\python\services>openssl
help:
[...]
Message Digest commands (see the `dgst' command for more details)
blake2b512 blake2s256 md4 md5
mdc2 rmd160 sha1 sha224
sha256 sha3-224 sha3-256 sha3-384
sha3-512 sha384 sha512 sha512-224
sha512-256 shake128 shake256 sm3
[...]
当身份验证尝试 运行 python 时会产生 ValueError: unsupported hash type md4 错误。这是回溯的相关部分:
C:\ProgramData\Miniconda3\envs\victory\lib\site-packages\ntlm_auth\compute_hash.py in _ntowfv1(password)
165 return nt_hash
166
--> 167 digest = hashlib.new('md4', password.encode('utf-16-le')).digest()
168
169 return digest
C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py in __hash_new(name, data, **kwargs)
161 # This allows for SHA224/256 and SHA384/512 support even though
162 # the OpenSSL library prior to 0.9.8 doesn't provide them.
--> 163 return __get_builtin_constructor(name)(data)
164
165
C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py in __get_builtin_constructor(name)
118 return constructor
119
--> 120 raise ValueError('unsupported hash type ' + name)
121
122
ValueError: unsupported hash type md4
即使我尝试仅从 hashlib 调用 MD4,我也会得到相同的结果:
>>> import hashlib
>>> hashlib.new('md4')
Traceback (most recent call last):
File "C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py", line 157, in __hash_new
return _hashlib.new(name, data)
ValueError: [digital envelope routines] initialization error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py", line 163, in __hash_new
return __get_builtin_constructor(name)(data)
File "C:\ProgramData\Miniconda3\envs\victory\lib\hashlib.py", line 120, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md4
任何关于正在发生的事情的见解and/or任何帮助将不胜感激。
好吧,我的 conda 环境中似乎有什么东西被破坏了。我创建了一个新的相同的,从那以后它一直在工作,无需更改任何其他内容。