From a60ca038ce6ec05647b2807644f25c55e9a9137a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sat, 31 Oct 2020 00:06:02 +0100 Subject: [PATCH] Updated cram-md5 authentication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch updates the cram-md5 auth. We include two steps: - Convert the password variable from string to bytes. This change is because in Python2 strings and bytes are the same, but not in Python3 - Updates the call to hmac.new, now the digestmod argument is mandatory. I used hashlib.md5, because we need md5 hash. Closes #19 Signed-off-by: Rodolfo García Peñas (kix) --- offlineimap/imapserver.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py index e6411dd..e9816ac 100644 --- a/offlineimap/imapserver.py +++ b/offlineimap/imapserver.py @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import datetime +import hashlib import hmac import socket import json @@ -184,7 +185,9 @@ class IMAPServer(): self.ui.debug('imap', '__md5handler: got challenge %s' % challenge) passwd = self.__getpassword() - retval = self.username + ' ' + hmac.new(passwd, challenge).hexdigest() + retval = self.username + ' ' +\ + hmac.new(bytes(passwd, encoding='utf-8'), challenge, + digestmod=hashlib.md5).hexdigest() self.ui.debug('imap', '__md5handler: returning %s' % retval) return retval