-
Notifications
You must be signed in to change notification settings - Fork 485
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
from __future__ import annotations | ||
|
||
import typing | ||
from base64 import b64decode, b64encode | ||
from collections import OrderedDict | ||
from datetime import datetime, timezone | ||
|
@@ -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 ( | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fix covers more than the issue reported by the user? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, only the reported issue. |
||
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") | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧞