Skip to content

Commit

Permalink
Merge pull request #1132 from exploide/md4
Browse files Browse the repository at this point in the history
Import MD4 from pycryptodomex package
  • Loading branch information
cannatag committed Mar 20, 2024
2 parents fd39991 + 3c0af8b commit 92cb049
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions ldap3/utils/ntlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,8 @@ def ntowf_v2(self):
# The specified password is an LM:NTLM hash
password_digest = binascii.unhexlify(passparts[1])
else:
try:
password_digest = hashlib.new('MD4', self._password.encode('utf-16-le')).digest()
except ValueError as e:
try:
from Crypto.Hash import MD4 # try with the Crypto library if present
password_digest = MD4.new(self._password.encode('utf-16-le')).digest()
except ImportError:
raise e # raise original exception

from Cryptodome.Hash import MD4
password_digest = MD4.new(self._password.encode('utf-16-le')).digest()
return hmac.new(password_digest, (self.user_name.upper() + self.user_domain).encode('utf-16-le'), digestmod=hashlib.md5).digest()

def _kxkey(self, response_key_nt, nt_proof_str):
Expand Down Expand Up @@ -565,4 +558,4 @@ def unseal(self, sealed_message):
calculated_signature = self.sign(message, sealed_message[12:16], SERVER)
if calculated_signature != sealed_message[:16]:
raise LDAPSignatureVerificationFailedError("Signature verification failed for the received LDAP message number " + str(self.sequence_number) + ". Expected signature " + sealed_message[:16].hex() + " but got " + calculated_signature.hex() + ".")
return message
return message

0 comments on commit 92cb049

Please sign in to comment.