mirror of
https://github.com/python/cpython.git
synced 2025-10-20 00:13:47 +00:00
[3.14] gh-136134: imaplib: fix CRAM-MD5 on FIPS-only environments (GH-136615) (#138054)
This commit is contained in:
parent
bfce393614
commit
d574f83206
4 changed files with 49 additions and 31 deletions
|
@ -21,7 +21,7 @@
|
|||
# GET/SETANNOTATION contributed by Tomas Lindroos <skitta@abo.fi> June 2005.
|
||||
# IDLE contributed by Forest <forestix@nom.one> August 2024.
|
||||
|
||||
__version__ = "2.59"
|
||||
__version__ = "2.60"
|
||||
|
||||
import binascii, errno, random, re, socket, subprocess, sys, time, calendar
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
@ -725,9 +725,17 @@ def login_cram_md5(self, user, password):
|
|||
def _CRAM_MD5_AUTH(self, challenge):
|
||||
""" Authobject to use with CRAM-MD5 authentication. """
|
||||
import hmac
|
||||
pwd = (self.password.encode('utf-8') if isinstance(self.password, str)
|
||||
else self.password)
|
||||
return self.user + " " + hmac.HMAC(pwd, challenge, 'md5').hexdigest()
|
||||
|
||||
if isinstance(self.password, str):
|
||||
password = self.password.encode('utf-8')
|
||||
else:
|
||||
password = self.password
|
||||
|
||||
try:
|
||||
authcode = hmac.HMAC(password, challenge, 'md5')
|
||||
except ValueError: # HMAC-MD5 is not available
|
||||
raise self.error("CRAM-MD5 authentication is not supported")
|
||||
return f"{self.user} {authcode.hexdigest()}"
|
||||
|
||||
|
||||
def logout(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue