Skip to content

Commit 387f764

Browse files
sfc-gh-mkellersfc-gh-pczajka
authored andcommitted
SNOW-1820480 making OCSP validation code more resillient (#2107)
1 parent 42a7c82 commit 387f764

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

DESCRIPTION.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
88

99
# Release Notes
1010

11+
- v3.12.4(TBD)
12+
- Fixed a bug where multipart uploads to Azure would be missing their MD5 hashes.
13+
- Fixed a bug where OpenTelemetry header injection would sometimes cause Exceptions to be thrown.
14+
- Fixed a bug where OCSP checks would throw TypeError and make mainly GCP blob storage unreachable.
15+
1116
- v3.12.3(October 25,2024)
1217
- Improved the error message for SSL-related issues to provide clearer guidance when an SSL error occurs.
1318
- Improved error message for SQL execution cancellations caused by timeout.

src/snowflake/connector/ocsp_asn1crypto.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
import typing
89
from base64 import b64decode, b64encode
910
from collections import OrderedDict
1011
from datetime import datetime, timezone
@@ -28,6 +29,9 @@
2829
from cryptography.hazmat.backends import default_backend
2930
from cryptography.hazmat.primitives import hashes, serialization
3031
from cryptography.hazmat.primitives.asymmetric import padding, utils
32+
from cryptography.hazmat.primitives.asymmetric.dsa import DSAPublicKey
33+
from cryptography.hazmat.primitives.asymmetric.ec import ECDSA, EllipticCurvePublicKey
34+
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
3135
from OpenSSL.SSL import Connection
3236

3337
from snowflake.connector.errorcode import (
@@ -368,9 +372,21 @@ def verify_signature(self, signature_algorithm, signature, cert, data):
368372
hasher = hashes.Hash(chosen_hash, backend)
369373
hasher.update(data.dump())
370374
digest = hasher.finalize()
375+
additional_kwargs: dict[str, typing.Any] = dict()
376+
if isinstance(public_key, RSAPublicKey):
377+
additional_kwargs["padding"] = padding.PKCS1v15()
378+
additional_kwargs["algorithm"] = utils.Prehashed(chosen_hash)
379+
elif isinstance(public_key, DSAPublicKey):
380+
additional_kwargs["algorithm"] = utils.Prehashed(chosen_hash)
381+
elif isinstance(public_key, EllipticCurvePublicKey):
382+
additional_kwargs["signature_algorithm"] = ECDSA(
383+
utils.Prehashed(chosen_hash)
384+
)
371385
try:
372386
public_key.verify(
373-
signature, digest, padding.PKCS1v15(), utils.Prehashed(chosen_hash)
387+
signature,
388+
digest,
389+
**additional_kwargs,
374390
)
375391
except InvalidSignature:
376392
raise RevocationCheckError(msg="Failed to verify the signature")

test/integ/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def init_test_schema(db_parameters) -> Generator[None, None, None]:
177177
database=ret["database"],
178178
account=ret["account"],
179179
protocol=ret["protocol"],
180+
role=ret["role"],
180181
) as con:
181182
con.cursor().execute(f"CREATE SCHEMA IF NOT EXISTS {TEST_SCHEMA}")
182183
yield

0 commit comments

Comments
 (0)