Updated cram-md5 authentication

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) <kix@kix.es>
This commit is contained in:
Rodolfo García Peñas (kix) 2020-10-31 00:06:02 +01:00
parent df16bd595d
commit a60ca038ce

View File

@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import datetime import datetime
import hashlib
import hmac import hmac
import socket import socket
import json import json
@ -184,7 +185,9 @@ class IMAPServer():
self.ui.debug('imap', '__md5handler: got challenge %s' % challenge) self.ui.debug('imap', '__md5handler: got challenge %s' % challenge)
passwd = self.__getpassword() 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) self.ui.debug('imap', '__md5handler: returning %s' % retval)
return retval return retval