|
5 | 5 | # the Apache 2.0 License: http://www.apache.org/licenses/LICENSE-2.0
|
6 | 6 |
|
7 | 7 |
|
8 |
| -from hashlib import md5 as hashlib_md5 # for MD5 authentication |
| 8 | +import hashlib |
9 | 9 |
|
10 | 10 |
|
11 | 11 | include "scram.pyx"
|
@@ -150,15 +150,28 @@ cdef class CoreProtocol:
|
150 | 150 | cdef _process__auth(self, char mtype):
|
151 | 151 | if mtype == b'R':
|
152 | 152 | # Authentication...
|
153 |
| - self._parse_msg_authentication() |
154 |
| - if self.result_type != RESULT_OK: |
| 153 | + try: |
| 154 | + self._parse_msg_authentication() |
| 155 | + except Exception as ex: |
| 156 | + # Exception in authentication parsing code |
| 157 | + # is usually either malformed authentication data |
| 158 | + # or missing support for cryptographic primitives |
| 159 | + # in the hashlib module. |
| 160 | + self.result_type = RESULT_FAILED |
| 161 | + self.result = apg_exc.InternalClientError( |
| 162 | + f"unexpected error while performing authentication: {ex}") |
| 163 | + self.result.__cause__ = ex |
155 | 164 | self.con_status = CONNECTION_BAD
|
156 | 165 | self._push_result()
|
| 166 | + else: |
| 167 | + if self.result_type != RESULT_OK: |
| 168 | + self.con_status = CONNECTION_BAD |
| 169 | + self._push_result() |
157 | 170 |
|
158 |
| - elif self.auth_msg is not None: |
159 |
| - # Server wants us to send auth data, so do that. |
160 |
| - self._write(self.auth_msg) |
161 |
| - self.auth_msg = None |
| 171 | + elif self.auth_msg is not None: |
| 172 | + # Server wants us to send auth data, so do that. |
| 173 | + self._write(self.auth_msg) |
| 174 | + self.auth_msg = None |
162 | 175 |
|
163 | 176 | elif mtype == b'K':
|
164 | 177 | # BackendKeyData
|
@@ -634,7 +647,7 @@ cdef class CoreProtocol:
|
634 | 647 |
|
635 | 648 | # 'md5' + md5(md5(password + username) + salt))
|
636 | 649 | userpass = ((self.password or '') + (self.user or '')).encode('ascii')
|
637 |
| - hash = hashlib_md5(hashlib_md5(userpass).hexdigest().\ |
| 650 | + hash = hashlib.md5(hashlib.md5(userpass).hexdigest().\ |
638 | 651 | encode('ascii') + salt).hexdigest().encode('ascii')
|
639 | 652 |
|
640 | 653 | msg.write_bytestring(b'md5' + hash)
|
|
0 commit comments