|
38 | 38 | _authenticate_oidc, |
39 | 39 | _get_authenticator, |
40 | 40 | ) |
| 41 | +from pymongo.asynchronous.helpers import _getaddrinfo |
41 | 42 | from pymongo.auth_shared import ( |
42 | 43 | MongoCredential, |
43 | 44 | _authenticate_scram_start, |
@@ -177,15 +178,22 @@ def _auth_key(nonce: str, username: str, password: str) -> str: |
177 | 178 | return md5hash.hexdigest() |
178 | 179 |
|
179 | 180 |
|
180 | | -def _canonicalize_hostname(hostname: str, option: str | bool) -> str: |
| 181 | +async def _canonicalize_hostname(hostname: str, option: str | bool) -> str: |
181 | 182 | """Canonicalize hostname following MIT-krb5 behavior.""" |
182 | 183 | # https://github.com/krb5/krb5/blob/d406afa363554097ac48646a29249c04f498c88e/src/util/k5test.py#L505-L520 |
183 | 184 | if option in [False, "none"]: |
184 | 185 | return hostname |
185 | 186 |
|
186 | | - af, socktype, proto, canonname, sockaddr = socket.getaddrinfo( |
187 | | - hostname, None, 0, 0, socket.IPPROTO_TCP, socket.AI_CANONNAME |
188 | | - )[0] |
| 187 | + af, socktype, proto, canonname, sockaddr = ( |
| 188 | + await _getaddrinfo( |
| 189 | + hostname, |
| 190 | + None, |
| 191 | + family=0, |
| 192 | + type=0, |
| 193 | + proto=socket.IPPROTO_TCP, |
| 194 | + flags=socket.AI_CANONNAME, |
| 195 | + ) |
| 196 | + )[0] # type: ignore[index] |
189 | 197 |
|
190 | 198 | # For forward just to resolve the cname as dns.lookup() will not return it. |
191 | 199 | if option == "forward": |
@@ -213,7 +221,7 @@ async def _authenticate_gssapi(credentials: MongoCredential, conn: AsyncConnecti |
213 | 221 | # Starting here and continuing through the while loop below - establish |
214 | 222 | # the security context. See RFC 4752, Section 3.1, first paragraph. |
215 | 223 | host = props.service_host or conn.address[0] |
216 | | - host = _canonicalize_hostname(host, props.canonicalize_host_name) |
| 224 | + host = await _canonicalize_hostname(host, props.canonicalize_host_name) |
217 | 225 | service = props.service_name + "@" + host |
218 | 226 | if props.service_realm is not None: |
219 | 227 | service = service + "@" + props.service_realm |
|
0 commit comments