-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow RSA signing with raw data (without a DigestInfo) #13740
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
base: main
Are you sure you want to change the base?
Changes from all commits
6a8b129
6bf891f
813c8dc
2d66d22
8b64ab8
9c5ddeb
de5824f
90f5e82
17083dc
712d5e2
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 |
|---|---|---|
|
|
@@ -290,8 +290,16 @@ impl RsaPrivateKey { | |
| padding: &pyo3::Bound<'p, pyo3::PyAny>, | ||
| algorithm: &pyo3::Bound<'p, pyo3::PyAny>, | ||
| ) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyAny>> { | ||
| let (data, algorithm) = | ||
| utils::calculate_digest_and_algorithm(py, data.as_bytes(), algorithm)?; | ||
| let (data, algorithm) = { | ||
|
Member
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. What happens if I pass NoDigestInfo and also PSS instead of PKCS1v15 for padding? Do we properly handle that case (it should be a ValueError that NoDigestInfo is only allowed for PKCS1v15)? I don't see logic for it. Assuming it's missing, we'll need a test for that once the check is added..
Contributor
Author
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. Currently If you pass I think this is even better than a I added a test case for this code path in 712d5e2 |
||
| if algorithm.is_instance(&types::NO_DIGEST_INFO.get(py)?)? { | ||
| ( | ||
| utils::BytesOrPyBytes::Bytes(data.as_bytes()), | ||
| pyo3::types::PyNone::get(py).to_owned().into_any(), | ||
| ) | ||
| } else { | ||
| utils::calculate_digest_and_algorithm(py, data.as_bytes(), algorithm)? | ||
| } | ||
| }; | ||
|
|
||
| let mut ctx = openssl::pkey_ctx::PkeyCtx::new(&self.pkey)?; | ||
| ctx.sign_init().map_err(|_| { | ||
|
|
@@ -441,8 +449,16 @@ impl RsaPublicKey { | |
| padding: &pyo3::Bound<'_, pyo3::PyAny>, | ||
| algorithm: &pyo3::Bound<'_, pyo3::PyAny>, | ||
| ) -> CryptographyResult<()> { | ||
| let (data, algorithm) = | ||
| utils::calculate_digest_and_algorithm(py, data.as_bytes(), algorithm)?; | ||
| let (data, algorithm) = { | ||
| if algorithm.is_instance(&types::NO_DIGEST_INFO.get(py)?)? { | ||
| ( | ||
| utils::BytesOrPyBytes::Bytes(data.as_bytes()), | ||
| pyo3::types::PyNone::get(py).to_owned().into_any(), | ||
| ) | ||
| } else { | ||
| utils::calculate_digest_and_algorithm(py, data.as_bytes(), algorithm)? | ||
| } | ||
| }; | ||
|
|
||
| let mut ctx = openssl::pkey_ctx::PkeyCtx::new(&self.pkey)?; | ||
| ctx.verify_init()?; | ||
|
|
@@ -488,6 +504,11 @@ impl RsaPublicKey { | |
| padding: &pyo3::Bound<'_, pyo3::PyAny>, | ||
| algorithm: &pyo3::Bound<'_, pyo3::PyAny>, | ||
| ) -> CryptographyResult<pyo3::Bound<'p, pyo3::types::PyBytes>> { | ||
| let algorithm = if algorithm.is_instance(&types::NO_DIGEST_INFO.get(py)?)? { | ||
reaperhulk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| &pyo3::types::PyNone::get(py).to_owned().into_any() | ||
jahkosha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } else { | ||
| algorithm | ||
| }; | ||
| if algorithm.is_instance(&types::PREHASHED.get(py)?)? { | ||
| return Err(CryptographyError::from( | ||
| pyo3::exceptions::PyTypeError::new_err( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.