-
Notifications
You must be signed in to change notification settings - Fork 55
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
Ensure correct error handling for large MPIs #941
Comments
@killy631 would you like to take this issue? Cannot assign it to you until commented. |
OK, I will take |
Is there failed or demo? |
I meant - failed test in some suite.. |
@killy631 Nope, there is no one (yet) - the idea is to build the test which will make sure that library works well in such cases (i.e. doesn't crash, has unexpected behavior and so on, and just reports an error). |
@antonsviridenko is going to take this for trial. Welcome! |
ok, I've started working on it |
Which library functions are supposed to be tested? Only ones exposed in public API inside include/ directory or internal ones from src/librepgp? I used https://github.com/rnpgp/rnp/blob/master/src/tests/streams.cpp#L444 as a reference, but maybe I am moving into the wrong direction? |
@antonsviridenko while all MPI load is done via |
Keyrings in src/tests/data/keyrings directory, they should be considered read-only, am I right? For example, if I want to test importing keys of PGP_MPINT_BITS size, I should use some temporary keyring created in runtime, correct? |
@antonsviridenko yeah, those are used in multiple tests, and breaking them will most likely break those tests. Feel free to create separate folder for your data files named according to your test's name. |
What packet type can contain these oid-s? Can you provide some more details? Seems that RFC4880 mentions OID-s only once, in context of hash algorithms. |
@antonsviridenko please see sections 5.6.4-5.6.6 of RFC 4880 bis -08. Basically, each EC-related key packet contains curve OID. |
ok, I think I've probably found some bug in dumping signature packet:
It displays error about wrong bit count, but still continues displaying packet contents. For RSA public key packets I tested before, it refused to display them when some inconsistency is detected.
I suspect it should not search for a new packet header here, because now with 1 byte appended signature packet file should be complete. 16385 bit MPI should have 2049 octets containing integer.
|
Seems that signature packet parser goes off by 1 octet somewhere |
@antonsviridenko Thanks for finding this out. Confirmed - there is an error in the function Regarding MPIs - RFC tells that MPI bit size must correspond to the MPI contents, and we are strictly following this. Probably GnuPG processes such MPIs without error or warning to be compatible with other buggy implementations. |
ok, I've tried to fix it What binary should I attach gdb to for debugging? It's bit not clear in these ctests :) |
@antonsviridenko for segfault errors usually it is faster to build with sanitizers, so you'll get call stack and a lot of other useful information on failure.
For debugging I used Visual Studio Code and attached to rnp_tests executable. That required some setup of launch.json, like the following:
|
https://github.com/rnpgp/rnp/blob/master/src/librepgp/stream-parse.cpp#L824 I guess returning RNP_SUCCESS here is not an intended action, RNP_ERROR_BAD_FORMAT should be an appropriate error code, am I right? |
@antonsviridenko no, it is correct - function returns RNP_SUCCESS in case when signature processed and stream can continue. In this case just one of the signatures will be marked as unknown (for instance, it has newer version, unknown public key/hash algorithm, and so on). |
I got some memory leak report from CI tests, https://github.com/antonsviridenko/rnp/runs/385090505
but checking with valgrind on my machine gives no errors:
Probably something environment-specific. Any ideas how to solve this? |
@antonsviridenko No, it is a real memory leak. centos run gives symbolicated log:
And it's source - function
Thanks for spotting this, and please update PR with this fix. |
here it is Is it ok to close this issue in multiple pull requests, one per key algorithm (i.e. RSA, DSA, EC and so on)? Otherwise it could take a longer time to implement & sync with master branch updates. I think RSA part is completed and can be merged already. |
@antonsviridenko sure, this issue can be addressed in multiple PRs. Please go ahead! |
I am looking at DSA now, seems that it makes no sense to try to generate 16384 bit or larger keys. https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-08.html#rfc.section.14.6 RFC says
So it defines key sizes generated by an implementation, but does not explicitly say what p an q sizes CAN be accepted. Now the rnp code does not strictly compare key size to 1024, 2048 or 3072, but checks if it is within range [1024-3072] |
@antonsviridenko it would be enough to test that rnp behaves correctly for larger-then-expected DSA key sizes (including too large MPIs of course). |
Looks like generating larger than expected DSA keys requires some efforts. Like patching libbotan in order to remove limitations on p and q max size and then making custom builds. Other possible way is to manually edit DSA key packets in hex editor and increase MPIs. But there are 5 MPIs to be tested per each key (p, q, g, y, x). Maybe there is some better way to do it? |
@antonsviridenko If it takes too much time probably we can skip those cases and switch to other tasks. |
Description
While OpenPGP standard allows MPI lengths up to 64k bits, we allow only smaller ones.
Construct dummy key, signature and PKESK data files and make sure those are loaded with correct error reporting, without AV and range-check failures.
Separate test file should be added to rnp_tests suite.
The text was updated successfully, but these errors were encountered: