in src/local_gpu_verifier/src/verifier/cc_admin_utils.py [0:0]
def fetch_ocsp_response_from_url(ocsp_request_data, url, max_retries):
""" A static method to prepare http request and send it to the ocsp server
and returns the ocsp response message.
Args:
ocsp_request_data (bytes): the raw ocsp request message.
url (str): the url of the ocsp service.
max_retries (int, optional): the maximum number of retries to be performed in case of any error.
Returns:
[cryptography.hazmat.backends.openssl.ocsp._OCSPResponse]: the ocsp response message object.
"""
# OCSP service URL should start with https
if not url.lower().startswith("https"):
info_log.error(f"The OCSP service url {url} does not start with https")
return None
# Sending the ocsp request to the given url
try:
ocsp_request = request.Request(url, ocsp_request_data)
ocsp_request.add_header("Content-Type", "application/ocsp-request")
with request.urlopen(ocsp_request) as ocsp_response_data:
ocsp_response = ocsp.load_der_ocsp_response(ocsp_response_data.read())
event_log.debug(f"Successfully fetched the ocsp response from {url}")
return ocsp_response
except Exception as e:
event_log.error(f"Error while fetching the ocsp response from {url}")
if isinstance(e, HTTPError):
event_log.error(f"HTTP Error code : {e.code}")
if max_retries > 0:
time.sleep(BaseSettings.OCSP_RETRY_DELAY)
return CcAdminUtils.fetch_ocsp_response_from_url(ocsp_request_data, url, max_retries - 1)
else:
return None