Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PYTHON-2999 Remove unused and internal only CRAM-MD5 auth mechanism
  • Loading branch information
ShaneHarvey committed Nov 4, 2021
commit a2849b19032b78ea8976386cba6d9aaa54d91849
26 changes: 0 additions & 26 deletions pymongo/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,6 @@ def _authenticate_plain(credentials, sock_info):
sock_info.command(source, cmd)


def _authenticate_cram_md5(credentials, sock_info):
"""Authenticate using CRAM-MD5 (RFC 2195)
"""
source = credentials.source
username = credentials.username
password = credentials.password
# The password used as the mac key is the
# same as what we use for MONGODB-CR
passwd = _password_digest(username, password)
cmd = SON([('saslStart', 1),
('mechanism', 'CRAM-MD5'),
('payload', Binary(b'')),
('autoAuthorize', 1)])
response = sock_info.command(source, cmd)
# MD5 as implicit default digest for digestmod is deprecated
# in python 3.4
mac = hmac.HMAC(key=passwd.encode('utf-8'), digestmod=hashlib.md5)
mac.update(response['payload'])
challenge = username.encode('utf-8') + b' ' + mac.hexdigest().encode('utf-8')
cmd = SON([('saslContinue', 1),
('conversationId', response['conversationId']),
('payload', Binary(challenge))])
sock_info.command(source, cmd)


def _authenticate_x509(credentials, sock_info):
"""Authenticate using MONGODB-X509.
"""
Expand Down Expand Up @@ -497,7 +472,6 @@ def _authenticate_default(credentials, sock_info):


_AUTH_MAP = {
'CRAM-MD5': _authenticate_cram_md5,
'GSSAPI': _authenticate_gssapi,
'MONGODB-CR': _authenticate_mongo_cr,
'MONGODB-X509': _authenticate_x509,
Expand Down
5 changes: 1 addition & 4 deletions pymongo/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,7 @@ def validate_read_preference_mode(dummy, value):
def validate_auth_mechanism(option, value):
"""Validate the authMechanism URI option.
"""
# CRAM-MD5 is for server testing only. Undocumented,
# unsupported, may be removed at any time. You have
# been warned.
if value not in MECHANISMS and value != 'CRAM-MD5':
if value not in MECHANISMS:
raise ValueError("%s must be in %s" % (option, tuple(MECHANISMS)))
return value

Expand Down