-
Notifications
You must be signed in to change notification settings - Fork 216
MPP-3852: Use cryptography
for SNS signature validation, remove pyopenssl
and pem
#5235
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
Conversation
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.
Great fix and reduction in dependencies!
NOTIFICATION_HASH_FORMAT = """\ | ||
Message |
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.
praise: nice little clean-up.
emails/sns.py
Outdated
# Extract the first certificate in the file and confirm it's a valid | ||
# PEM certificate | ||
certificates = pem.parse(smart_bytes(pemfile)) | ||
|
||
certs = x509.load_pem_x509_certificates(pemfile) |
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.
quibble (non-blocking): this is 2x calls to x509.load_pem_x509_certificate
[s] when we could maybe change the code to only call load_pem_x509_certificate
1x and return the single valid cert that it loaded?
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.
I took it one step futher and changed _grab_keyfile
, returning PEM bytes, to _get_signing_public_key
, returning an RSAPublicKey
. This way the certificate is loaded and validated the first time it is read, not every time it is fetched from the cache.
This builds on PR #5234. It changes
emails/sns.py
to usecryptography
for PEM loading, certificate validation, and signature verification. It removes the dependenciespyopenssl
andpem
, which are no longer needed.It adds a new exception
VerificationFailed
for exceptions, rather than replaceOpenSSL.crypto.Error
withcryptography.exceptions.InvalidSignature
. This requires updating some tests andtry
blocks, which would have needed to update anyway, but does insulate the code from future changes.Once this merges, I expect