Authobject to use with CRAM-MD5 authentication.
(self, challenge)
| 718 | |
| 719 | |
| 720 | def _CRAM_MD5_AUTH(self, challenge): |
| 721 | """ Authobject to use with CRAM-MD5 authentication. """ |
| 722 | import hmac |
| 723 | |
| 724 | if isinstance(self.password, str): |
| 725 | password = self.password.encode('utf-8') |
| 726 | else: |
| 727 | password = self.password |
| 728 | |
| 729 | try: |
| 730 | authcode = hmac.HMAC(password, challenge, 'md5') |
| 731 | except ValueError: # HMAC-MD5 is not available |
| 732 | raise self.error("CRAM-MD5 authentication is not supported") |
| 733 | return f"{self.user} {authcode.hexdigest()}" |
| 734 | |
| 735 | |
| 736 | def logout(self): |