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

Add support for RSA_R_OAEP_DECODING_ERROR error flag. #2323

Closed

Conversation

EnTeQuAk
Copy link
Contributor

@EnTeQuAk EnTeQuAk commented Sep 4, 2015

This pull request adds support for the RSA_R_OAEP_DECODING_ERROR error flag referenced here: https://github.com/openssl/openssl/blob/master/include/openssl/rsa.h#L626

This error code is being raised on error condition (e.g wrong private key) for this code: https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/#decryption

I actually didn't see any tests for RSA_R_PKCS_DECODING_ERROR flag and don't really know how to test such flags. Please let me know if you need any, I'd be happy for any guidance here 😃

@reaperhulk
Copy link
Member

@EnTeQuAk thanks for the PR! In this case I think a good test is whatever you used to produce the problem.

@codecov-io
Copy link

Current coverage is 99.97%

Merging #2323 into master will decrease coverage by -0.01% as of 0976585

@@            master   #2323   diff @@
======================================
  Files          115     115       
  Stmts        11950   11957     +7
  Branches      1334    1335     +1
  Methods          0       0       
======================================
+ Hit          11948   11954     +6
- Partial          2       3     +1
  Missed           0       0       

Review entire Coverage Diff as of 0976585

Powered by Codecov. Updated on successful CI builds.

@EnTeQuAk
Copy link
Contributor Author

EnTeQuAk commented Sep 4, 2015

@reaperhulk added simple test that would fail on decryption without the support of RSA_R_PKCS_DECODING_ERROR

@reaperhulk
Copy link
Member

Your patch appears to be designed to have it properly raise a ValueError on a decryption failure rather than an AssertionError, correct? The test you put up passes without any issues on current trunk without your proposed patch.

@EnTeQuAk
Copy link
Contributor Author

EnTeQuAk commented Sep 4, 2015

@reaperhulk that's weird, yeah, if decryption fails (which it does not in the test) a ValueError is expected instead of an AssertionError. Let me check why it's not failing without the patch, I used different rsa-keys here for testing but thought it'd be all the same.

I'll re-check

@reaperhulk
Copy link
Member

@EnTeQuAk your test doesn't expect a failure at all (it just encrypts/decrypts and asserts that decryption was successful), so it isn't going to exercise the failure case (which would require a pytest.raises(ValueError)). Did you copy the wrong test?

@EnTeQuAk
Copy link
Contributor Author

EnTeQuAk commented Sep 4, 2015

Ah no, it's not expecting a failure. The patch fixes a wrongly raised AssertionError.

@reaperhulk
Copy link
Member

I am still a bit confused I think. The patch adds a new error code to the list of expected codes when _handle_rsa_enc_dec_error is called. This is only called when a decryption/encryption has failed though, so the test case you've provided can't exercise that code path.

@EnTeQuAk
Copy link
Contributor Author

EnTeQuAk commented Sep 4, 2015

Thanks, I've been blind. Updated the test 😄 Now this fails on master.

@reaperhulk
Copy link
Member

Thanks to a new GH feature you'll need to merge the latest master into this to be fully up to date before we can merge as well (sorry!)


with pytest.raises(ValueError):
RSA_KEY_512_ALT.private_key(backend).decrypt(
ciphertext,
Copy link
Member

Choose a reason for hiding this comment

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

Can you please move the RSA_KEY_512_ALT.private_key(backend) call outside of the with pytest.raises(ValueError) block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@reaperhulk
Copy link
Member

Also this new test passes for me on master without the patch as well, which suggests this issue is specific to a particular OpenSSL. What OS/distro/OpenSSL version are you seeing this on?

@EnTeQuAk
Copy link
Contributor Author

EnTeQuAk commented Sep 4, 2015

@reaperhulk I'm using OpenSSL 1.0.2d 9 Jul 2015 on ArchLinux

@reaperhulk
Copy link
Member

Sigh, stupid OpenSSL. I'm using 1.0.2d for my tests as well, but can't replicate. Figures.

@reaperhulk
Copy link
Member

jenkins, ok to test

@EnTeQuAk
Copy link
Contributor Author

EnTeQuAk commented Sep 4, 2015

Not cool. I'll try to recheck some time tomorrow (CET) what might be going on here. 😞

@@ -29,7 +29,7 @@
from cryptography.hazmat.primitives.ciphers.modes import CBC, CTR, Mode

from ..primitives.fixtures_dsa import DSA_KEY_2048
from ..primitives.fixtures_rsa import RSA_KEY_2048, RSA_KEY_512
from ..primitives.fixtures_rsa import RSA_KEY_2048, RSA_KEY_512, RSA_KEY_512_ALT
Copy link
Member

Choose a reason for hiding this comment

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

This line is too long, you'll need to format it:

from ..primitives.fixtures_rsa import (
    RSA_KEY_2048, RSA_KEY_512, RSA_KEY_512_ALT
)

@reaperhulk
Copy link
Member

@EnTeQuAk have you had a chance to revisit this or would you like us to take it over? It looks like there's just one small PEP8 problem.

@EnTeQuAk
Copy link
Contributor Author

@reaperhulk Hey, sorry, I did not have the time recently to figure it out. I'll fix the pep8 problem shortly, I'm just curious about the fact that the test works for you on master without the patch but it doesn't for me. I need to test this on various machines. In any case, I'm still on it.

@reaperhulk reaperhulk closed this Dec 28, 2015
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants