browser/gemini: avoid inf. recursion on code 60

If the server would blindly respond with code 60 even though we present
a client certificate, it would trigger an infinite recursive call
(open_gemini_url → _handle_response → _handle_cert_required).
This commit is contained in:
dece 2021-11-15 14:15:07 +01:00
parent e0a5ca94ec
commit 0f35971493

View file

@ -124,7 +124,8 @@ def open_gemini_url(
browser.set_status_error(f"Response parsing failed ({url}).") browser.set_status_error(f"Response parsing failed ({url}).")
return None return None
return _handle_response(browser, response, url, redirects) return _handle_response(browser, response, url, redirects,
used_cert=cert_and_key is not None)
def _handle_untrusted_cert(browser: Browser, request: Request): def _handle_untrusted_cert(browser: Browser, request: Request):
@ -151,7 +152,8 @@ def _handle_response(
browser: Browser, browser: Browser,
response: Response, response: Response,
url: str, url: str,
redirects: int redirects: int,
used_cert: bool = False,
) -> Optional[str]: ) -> Optional[str]:
"""Handle a response from a Gemini server. """Handle a response from a Gemini server.
@ -175,6 +177,10 @@ def _handle_response(
elif response.generic_code == 10: elif response.generic_code == 10:
return _handle_input_request(browser, url, response.meta) return _handle_input_request(browser, url, response.meta)
elif response.code == 60: elif response.code == 60:
if used_cert:
error = "Server ignored our certificate."
browser.set_status_error(error)
else:
return _handle_cert_required(browser, response, url, redirects) return _handle_cert_required(browser, response, url, redirects)
elif response.code in (61, 62): elif response.code in (61, 62):
details = response.meta or Response.code.name details = response.meta or Response.code.name