GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Changed OCSP cert returns error status instead of raising an exceptio… · byule/snowflake-connector-python@c30f74f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • errorcode.py
  • ocsp_asn1crypto.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎errorcode.py‎

Copy file name to clipboardExpand all lines: errorcode.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
ER_OPENSSL_IS_NOT_ACCESSIBLE = 254006
6767
ER_INVALID_OCSP_RESPONSE = 254007
6868
ER_CA_CERTIFICATE_NOT_FOUND = 254008
69+
ER_SERVER_CERTIFICATE_UNKNOWN = 254009
6970

7071
# converter
7172
ER_NOT_SUPPORT_DATA_TYPE = 255001
Collapse file

‎ocsp_asn1crypto.py‎

Copy file name to clipboardExpand all lines: ocsp_asn1crypto.py
+27-16Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from snowflake.connector.compat import (urlsplit, OK)
3333
from snowflake.connector.errorcode import (
3434
ER_INVALID_OCSP_RESPONSE,
35+
ER_SERVER_CERTIFICATE_UNKNOWN,
3536
ER_SERVER_CERTIFICATE_REVOKED)
3637
from snowflake.connector.errors import OperationalError
3738

@@ -337,7 +338,7 @@ def _lazy_read_ca_bundle():
337338
'Set REQUESTS_CA_BUNDLE to the file.')
338339

339340

340-
def _create_ocsp_request(issuer, subject):
341+
def create_ocsp_request(issuer, subject):
341342
"""
342343
Create CertId and OCSPRequest
343344
"""
@@ -510,7 +511,7 @@ def _process_unknown_status(cert_id):
510511
del OCSP_VALIDATION_CACHE[hkey]
511512
raise OperationalError(
512513
msg=u"The certificate is in UNKNOWN revocation status.",
513-
errno=ER_SERVER_CERTIFICATE_REVOKED,
514+
errno=ER_SERVER_CERTIFICATE_UNKNOWN,
514515
)
515516

516517

@@ -656,7 +657,7 @@ def is_cert_id_in_cache(issuer, subject):
656657
global OCSP_VALIDATION_CACHE
657658
global OCSP_VALIDATION_CACHE_UPDATED
658659

659-
cert_id, req = _create_ocsp_request(issuer, subject)
660+
cert_id, req = create_ocsp_request(issuer, subject)
660661
hkey = _decode_cert_id_key(cert_id)
661662
with OCSP_VALIDATION_CACHE_LOCK:
662663
current_time = int(time.time())
@@ -720,10 +721,8 @@ def validate_by_direct_connection(issuer, subject, do_retry=True):
720721
"Retrying... %s/%s", ex, retry + 1, max_retry)
721722
err = ex
722723
cache_status = False
723-
if err:
724-
raise err
725724

726-
return True, cert_id, ocsp_response
725+
return err, issuer, subject, cert_id, ocsp_response
727726

728727

729728
def _download_ocsp_response_cache(url, do_retry=True):
@@ -776,7 +775,7 @@ def _validate_certificates_sequential(cert_data, do_retry=True):
776775
results = []
777776
_check_ocsp_response_cache_server(cert_data)
778777
for issuer, subject in cert_data:
779-
r = validate_by_direct_connection(issuer, subject, do_retry)
778+
r = validate_by_direct_connection(issuer, subject, do_retry=do_retry)
780779
results.append(r)
781780
return results
782781

@@ -796,7 +795,7 @@ def _check_ocsp_response_cache_server(cert_data):
796795
in_cache = True
797796
for issuer, subject in cert_data:
798797
# check if OCSP response is in cache
799-
cert_id, _ = _create_ocsp_request(issuer, subject)
798+
cert_id, _ = create_ocsp_request(issuer, subject)
800799
hkey = _decode_cert_id_key(cert_id)
801800
with OCSP_VALIDATION_CACHE_LOCK:
802801
if hkey not in OCSP_VALIDATION_CACHE:
@@ -957,16 +956,19 @@ def __init__(self, ocsp_response_cache_uri=None,
957956
_read_ocsp_response_cache(self._ocsp_response_cache_uri)
958957
'test'.encode("charmap")
959958

960-
def validate_certfile(self, cert_filename):
959+
def validate_certfile(self, cert_filename, no_exception=False):
961960
"""
962961
Validates the certificate is NOT revoked
963962
"""
964963
cert_map = {}
965964
read_cert_bundle(cert_filename, cert_map)
966965
cert_data = _create_pair_issuer_subject(cert_map)
967-
return self._validate(None, cert_data, do_retry=False)
966+
return self._validate(
967+
None, cert_data, do_retry=False, no_exception=no_exception)
968968

969-
def validate(self, hostname, connection, ignore_no_ocsp=False):
969+
def validate(
970+
self, hostname, connection,
971+
ignore_no_ocsp=False, no_exception=False):
970972
"""
971973
Validates the certificate is not revoked using OCSP
972974
"""
@@ -976,14 +978,16 @@ def validate(self, hostname, connection, ignore_no_ocsp=False):
976978
return True
977979

978980
cert_data = _extract_certificate_chain(connection)
979-
return self._validate(hostname, cert_data)
981+
return self._validate(hostname, cert_data, no_exception=no_exception)
980982

981-
def _validate(self, hostname, cert_data, do_retry=True):
983+
def _validate(
984+
self, hostname, cert_data, do_retry=True, no_exception=False):
982985
global OCSP_VALIDATION_CACHE_UPDATED
983986
global OCSP_VALIDATION_CACHE
984987

985988
# Validate certs sequentially if OCSP response cache server is used
986-
results = _validate_certificates_sequential(cert_data, do_retry)
989+
results = _validate_certificates_sequential(
990+
cert_data, do_retry=do_retry)
987991

988992
with OCSP_VALIDATION_CACHE_LOCK:
989993
if OCSP_VALIDATION_CACHE_UPDATED:
@@ -1000,5 +1004,12 @@ def _validate(self, hostname, cert_data, do_retry=True):
10001004
len(cert_data)),
10011005
errno=ER_INVALID_OCSP_RESPONSE
10021006
)
1003-
logger.debug('ok')
1004-
return True
1007+
any_err = False
1008+
for err, issuer, subject, cert_id, ocsp_response in results:
1009+
if not no_exception and err is not None:
1010+
raise err
1011+
elif err is not None:
1012+
any_err = True
1013+
1014+
logger.debug('ok' if not any_err else 'failed')
1015+
return results

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.