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:
parent
e0a5ca94ec
commit
0f35971493
|
@ -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,7 +177,11 @@ 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:
|
||||||
return _handle_cert_required(browser, response, url, redirects)
|
if used_cert:
|
||||||
|
error = "Server ignored our certificate."
|
||||||
|
browser.set_status_error(error)
|
||||||
|
else:
|
||||||
|
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
|
||||||
error = f"Client certificate error: {details}"
|
error = f"Client certificate error: {details}"
|
||||||
|
|
Reference in a new issue