Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1820480 making OCSP validation code more resillient #2107

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
- v3.12.4(TBD)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this still be TBD?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you can tell me when the next release is happening yes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧞

- Fixed a bug where multipart uploads to Azure would be missing their MD5 hashes.
- Fixed a bug where OpenTelemetry header injection would sometimes cause Exceptions to be thrown.
- Fixed a bug where OCSP checks would throw TypeError and make mainly GCP blob storage unreachable.

- v3.12.3(October 25,2024)
- Improved the error message for SSL-related issues to provide clearer guidance when an SSL error occurs.
Expand Down
18 changes: 17 additions & 1 deletion src/snowflake/connector/ocsp_asn1crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

import typing
from base64 import b64decode, b64encode
from collections import OrderedDict
from datetime import datetime, timezone
Expand All @@ -28,6 +29,9 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding, utils
from cryptography.hazmat.primitives.asymmetric.dsa import DSAPublicKey
from cryptography.hazmat.primitives.asymmetric.ec import ECDSA, EllipticCurvePublicKey
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from OpenSSL.SSL import Connection

from snowflake.connector.errorcode import (
Expand Down Expand Up @@ -368,9 +372,21 @@ def verify_signature(self, signature_algorithm, signature, cert, data):
hasher = hashes.Hash(chosen_hash, backend)
hasher.update(data.dump())
digest = hasher.finalize()
additional_kwargs: dict[str, typing.Any] = dict()
if isinstance(public_key, RSAPublicKey):
additional_kwargs["padding"] = padding.PKCS1v15()
additional_kwargs["algorithm"] = utils.Prehashed(chosen_hash)
elif isinstance(public_key, DSAPublicKey):
additional_kwargs["algorithm"] = utils.Prehashed(chosen_hash)
elif isinstance(public_key, EllipticCurvePublicKey):
additional_kwargs["signature_algorithm"] = ECDSA(
utils.Prehashed(chosen_hash)
)
Comment on lines +375 to +384
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix covers more than the issue reported by the user?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, only the reported issue. TypeError is raised in the case where we send in too many arguments to the verify() call.

try:
public_key.verify(
signature, digest, padding.PKCS1v15(), utils.Prehashed(chosen_hash)
signature,
digest,
**additional_kwargs,
)
except InvalidSignature:
raise RevocationCheckError(msg="Failed to verify the signature")
Expand Down
Loading