2727
2828from snowflake .connector .ocsp_snowflake import SnowflakeOCSP
2929from .compat import (PY2 )
30- from .errorcode import (ER_INVALID_OCSP_RESPONSE )
30+ from .errorcode import (ER_INVALID_OCSP_RESPONSE , ER_INVALID_OCSP_RESPONSE_CODE )
3131from .errors import (OperationalError )
3232from .rfc6960 import (
3333 OCSPRequest ,
3939 BasicOCSPResponse ,
4040 Version )
4141
42+ from snowflake .connector .ssd_internal_keys import ret_wildcard_hkey
43+
4244logger = getLogger (__name__ )
4345
4446
@@ -63,6 +65,8 @@ class SnowflakeOCSPPyasn1(SnowflakeOCSP):
6365 sha512WithRSAEncryption : SHA512 ,
6466 }
6567
68+ WILDCARD_CERTID = None
69+
6670 @staticmethod
6771 def _get_pyasn1_version ():
6872 with SnowflakeOCSPPyasn1 .PYASN1_VERSION_LOCK :
@@ -78,6 +82,7 @@ def _get_pyasn1_version():
7882
7983 def __init__ (self , ** kwargs ):
8084 super (SnowflakeOCSPPyasn1 , self ).__init__ (** kwargs )
85+ self .WILDCARD_CERTID = self .encode_cert_id_key (ret_wildcard_hkey ())
8186
8287 def encode_cert_id_key (self , hkey ):
8388 issuer_name_hash , issuer_key_hash , serial_number = hkey
@@ -350,26 +355,26 @@ def _convert_generalized_time_to_datetime(self, gentime):
350355 return datetime .strptime (str (gentime ), '%Y%m%d%H%M%SZ' )
351356
352357 def is_valid_time (self , cert_id , ocsp_response ):
353- try :
354- res = der_decoder .decode (ocsp_response , OCSPResponse ())[0 ]
358+ res = der_decoder .decode (ocsp_response , OCSPResponse ())[0 ]
355359
356- if res .getComponentByName ('responseStatus' ) != OCSPResponseStatus (
357- 'successful' ):
358- raise OperationalError (
359- msg = "Invalid Status: {0}" .format (
360- res .getComponentByName ('response_status' )),
361- errno = ER_INVALID_OCSP_RESPONSE )
360+ if res .getComponentByName ('responseStatus' ) != OCSPResponseStatus (
361+ 'successful' ):
362+ raise OperationalError (
363+ msg = "Invalid Status: {0}" .format (
364+ res .getComponentByName ('response_status' )),
365+ errno = ER_INVALID_OCSP_RESPONSE )
362366
363- response_bytes = res .getComponentByName ('responseBytes' )
364- basic_ocsp_response = der_decoder .decode (
365- response_bytes .getComponentByName ('response' ),
366- BasicOCSPResponse ())[0 ]
367+ response_bytes = res .getComponentByName ('responseBytes' )
368+ basic_ocsp_response = der_decoder .decode (
369+ response_bytes .getComponentByName ('response' ),
370+ BasicOCSPResponse ())[0 ]
367371
368- tbs_response_data = basic_ocsp_response .getComponentByName (
369- 'tbsResponseData' )
372+ tbs_response_data = basic_ocsp_response .getComponentByName (
373+ 'tbsResponseData' )
370374
371- single_response = tbs_response_data .getComponentByName ('responses' )[0 ]
372- cert_status = single_response .getComponentByName ('certStatus' )
375+ single_response = tbs_response_data .getComponentByName ('responses' )[0 ]
376+ cert_status = single_response .getComponentByName ('certStatus' )
377+ try :
373378 if cert_status .getName () == 'good' :
374379 self ._process_good_status (single_response , cert_id , ocsp_response )
375380 except Exception as ex :
@@ -379,7 +384,13 @@ def is_valid_time(self, cert_id, ocsp_response):
379384 return True
380385
381386 def process_ocsp_response (self , issuer , cert_id , ocsp_response ):
382- res = der_decoder .decode (ocsp_response , OCSPResponse ())[0 ]
387+ try :
388+ res = der_decoder .decode (ocsp_response , OCSPResponse ())[0 ]
389+ except Exception :
390+ raise OperationalError (
391+ msg = 'Invalid OCSP Response' ,
392+ errno = ER_INVALID_OCSP_RESPONSE
393+ )
383394
384395 if res .getComponentByName ('responseStatus' ) != OCSPResponseStatus (
385396 'successful' ):
@@ -435,7 +446,7 @@ def process_ocsp_response(self, issuer, cert_id, ocsp_response):
435446 raise OperationalError (
436447 msg = "Unknown revocation status was returned. OCSP response "
437448 "may be malformed: {0}" .format (cert_status ),
438- errno = ER_INVALID_OCSP_RESPONSE
449+ errno = ER_INVALID_OCSP_RESPONSE_CODE
439450 )
440451
441452 def verify_signature (self , signature_algorithm , signature , cert , data ):
0 commit comments