Skip to content

Commit debbb3c

Browse files
sfc-gh-stakedaankit-bhatnagar167
authored andcommitted
SNOW-90415 : Caught uncaught exception.
SNOW-91743 : Updated connection timeouts for Cache Server and OCSP Responders. SNOW-82276 : Removed support for OLD OCSP URL for Privatelink in SnowSQL. SNOW-90234 : OOB Telemetry for Revoked Certificates is updated to be sent with Urgent flag.
1 parent fb1f5d4 commit debbb3c

File tree

5 files changed

+248
-84
lines changed

5 files changed

+248
-84
lines changed

connection.py

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@
7373
HeartBeatTimer, get_time_millis)
7474
from .util_text import split_statements, construct_hostname, parse_account
7575

76-
from snowflake.connector.network import APPLICATION_SNOWSQL
77-
7876

7977
def DefaultConverterClass():
8078
if PY_ISSUE_23517 or IS_WINDOWS:
@@ -612,36 +610,11 @@ def __set_error_attributes(self):
612610
@staticmethod
613611
def setup_ocsp_privatelink(app, hostname):
614612
SnowflakeConnection.OCSP_ENV_LOCK.acquire()
615-
if app is APPLICATION_SNOWSQL:
616-
ocsp_cache_server = u'http://ocsp{}/ocsp_response_cache.json'.format(
617-
hostname[hostname.index('.'):])
618-
'''
619-
Check if user has configured a custom OCSP Cache Server URL
620-
'''
621-
if 'SF_OCSP_RESPONSE_CACHE_SERVER_URL' not in os.environ:
622-
os.environ[
623-
'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server
624-
else:
625-
if "ocsp_response_cache" not in os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']:
626-
if not os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']. \
627-
startswith("http://"):
628-
ocsp_cache_server = "http://{0}/{1}".format(
629-
os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'],
630-
"ocsp_response_cache.json")
631-
else:
632-
ocsp_cache_server = "{0}/{1}".format(
633-
os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'],
634-
"ocsp_response_cache.json")
635-
else:
636-
ocsp_cache_server = os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL']
637-
638-
os.environ['SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server
639-
else:
640-
ocsp_cache_server = \
641-
u'http://ocsp.{}/ocsp_response_cache.json'.format(
642-
hostname)
643-
os.environ[
644-
'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server
613+
ocsp_cache_server = \
614+
u'http://ocsp.{}/ocsp_response_cache.json'.format(
615+
hostname)
616+
os.environ[
617+
'SF_OCSP_RESPONSE_CACHE_SERVER_URL'] = ocsp_cache_server
645618
logger.debug(u"OCSP Cache Server is updated: %s", ocsp_cache_server)
646619
SnowflakeConnection.OCSP_ENV_LOCK.release()
647620

ocsp_asn1crypto.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from snowflake.connector.ocsp_snowflake import SnowflakeOCSP
2626
from collections import OrderedDict
2727
from snowflake.connector.ssd_internal_keys import ret_wildcard_hkey
28+
from os import getenv
2829

2930
logger = getLogger(__name__)
3031

@@ -223,11 +224,16 @@ def is_valid_time(self, cert_id, ocsp_response):
223224
def process_ocsp_response(self, issuer, cert_id, ocsp_response):
224225
try:
225226
res = OCSPResponse.load(ocsp_response)
227+
if self.test_mode is not None:
228+
ocsp_load_failure = getenv("SF_TEST_OCSP_FORCE_BAD_OCSP_RESPONSE")
229+
if ocsp_load_failure is not None:
230+
raise RevocationCheckError("Force fail")
226231
except Exception:
227232
raise RevocationCheckError(
228233
msg='Invalid OCSP Response',
229234
errno=ER_INVALID_OCSP_RESPONSE
230235
)
236+
231237
if res['response_status'].native != 'successful':
232238
raise RevocationCheckError(
233239
msg="Invalid Status: {0}".format(res['response_status'].native),
@@ -256,6 +262,7 @@ def process_ocsp_response(self, issuer, cert_id, ocsp_response):
256262
ocsp_cert['tbs_certificate'])
257263

258264
cert_valid, debug_msg = self.check_cert_time_validity(cur_time, ocsp_cert)
265+
259266
if not cert_valid:
260267
raise RevocationCheckError(
261268
msg=debug_msg,
@@ -277,6 +284,15 @@ def process_ocsp_response(self, issuer, cert_id, ocsp_response):
277284

278285
single_response = tbs_response_data['responses'][0]
279286
cert_status = single_response['cert_status'].name
287+
if self.test_mode is not None:
288+
test_cert_status = getenv("SF_TEST_OCSP_CERT_STATUS")
289+
if test_cert_status == 'revoked':
290+
cert_status = 'revoked'
291+
elif test_cert_status == 'unknown':
292+
cert_status = 'unknown'
293+
elif test_cert_status == 'good':
294+
cert_status = 'good'
295+
280296
try:
281297
if cert_status == 'good':
282298
self._process_good_status(single_response, cert_id, ocsp_response)

ocsp_pyasn1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from datetime import datetime
1212
from logging import getLogger
1313
from threading import Lock
14+
from os import getenv
1415

1516
import pyasn1
1617
from Cryptodome.Hash import SHA256, SHA384, SHA1, SHA512
@@ -438,6 +439,10 @@ def is_valid_time(self, cert_id, ocsp_response):
438439
def process_ocsp_response(self, issuer, cert_id, ocsp_response):
439440
try:
440441
res = der_decoder.decode(ocsp_response, OCSPResponse())[0]
442+
if self.test_mode is not None:
443+
ocsp_load_failure = getenv("SF_TEST_OCSP_FORCE_BAD_OCSP_RESPONSE")
444+
if ocsp_load_failure is not None:
445+
raise RevocationCheckError("Force fail")
441446
except Exception:
442447
raise RevocationCheckError(
443448
msg='Invalid OCSP Response',
@@ -502,6 +507,16 @@ def process_ocsp_response(self, issuer, cert_id, ocsp_response):
502507

503508
single_response = tbs_response_data.getComponentByName('responses')[0]
504509
cert_status = single_response.getComponentByName('certStatus')
510+
511+
if self.test_mode is not None:
512+
test_cert_status = getenv("SF_TEST_OCSP_CERT_STATUS")
513+
if test_cert_status == 'revoked':
514+
cert_status = 'revoked'
515+
elif test_cert_status == 'unknown':
516+
cert_status = 'unknown'
517+
elif test_cert_status == 'good':
518+
cert_status = 'good'
519+
505520
try:
506521
if cert_status.getName() == 'good':
507522
self._process_good_status(single_response, cert_id, ocsp_response)

0 commit comments

Comments
 (0)