Fix spurious error queue entries while loading private keys#15283
Fix spurious error queue entries while loading private keys#15283DDvO wants to merge 2 commits intoopenssl:masterfrom
Conversation
77811c0 to
b97067a
Compare
b97067a to
5f4caa7
Compare
|
Do you have an example that resulted in that spurious error queue entry? |
Sure. yields When loading RSA keys instead this does not happen. Update: A simpler way to reproduce this is: |
|
With the proposed changes there is a test failure on which appears to indicate a different type of uncleanness regarding the error queue: |
|
Ah, the spurious error happens because insta.priv.pem holds two items, demonstrated like this: $ ./util/wrap.pl apps/openssl storeutl insta.priv.pem
0: Parameters
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
1: Pkey
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgB3KN9BGnVLlGtTRR
QJTqyn2fS1OH390SzH5NRSLpZB+hRANCAAT95NrJeMI0BP50A/Yx0G88ZY1EJiP7
wOi12pAaMM+nN5iyed17ro8Y4JgIEJcSAt0rNo24FPHb013p/PrEeLXb
-----END PRIVATE KEY-----
Total found: 2The point where this file is loaded is here: Line 630 in 773f1c3 That will, of course, only accept private keys, not key params. This has me think about recent development, where we're taking a closer look at the extected STORE_INFO type in Lines 978 to 991 in 773f1c3 So, it seems to come down to |
|
Indeed the errors occur only with the portion of the private key file! part is unclear (if given at all, it should mention that it does not like the parameters found), while is misleading because the problem is not the |
|
Actually also is misleading in my view since |
|
So I suspect that in a handling for the (EC) PARAMETERS case ( |
c41b255 to
8d5ceb6
Compare
|
I've just found a very simple preliminary fix for the reported spurious update: 'unsupported' error problem, @levitte, will you take care of a deeper/proper solution (which is not urgent in my view)? |
|
Please drop your changes to |
Unfortunately these are still needed to prevent |
|
Or what else do you concretely suggest to get rid of those? |
|
And is my latest quick-fix change to acceptable (for the time being) after all? |
I would have a Lines 978 to 991 in 773f1c3 and simply remove the error printing |
Yes, I plan on doing so. |
Pleased to hear. |
This appears strange to me. For instance like this? As expected, this (or having the pair outside the block) does not prevent the error printed by |
|
As explained above, I am pretty sure that the trial-and-error construct in |
|
How if we simply defer this (as WIP) to the beta phase? |
|
I would like to ask you for a little patience. I intend to use the weekend for something else. |
|
This PR is in a state where it requires action by @openssl/otc but the last update was 30 days ago |
|
This PR is in a state where it requires action by @openssl/otc but the last update was 61 days ago |
|
Is this needed for 3.0? It does not have the 3.0 milestone at the moment |
|
I lost track of this PR on September, |
crypto/crmf/crmf_lib.c
Outdated
There was a problem hiding this comment.
This is not a constant time operation.
There was a problem hiding this comment.
I do not see why this could be problem here.
Using ERR_clear_error() was too aggressive since it deletes all errors, also unrelated ones.
And using ERR_set_mark(); ... ERR_pop_to_mark(); is the usual pattern to get rid of any - and only those - error queue entries potentially added by a function call.
If there is a more efficient way of achieving this please let me know.
There was a problem hiding this comment.
Please note that the following code uses constant time operation. And ERR_clear_error() is constant time unless allocated err data is present.
There was a problem hiding this comment.
Ah, now I see what you are after.
Hmm, looks like even ERR_clear_error() is not really constant-time due to OPENSSL_free(es->err_file[i]), where es->err_file[i] should be NULL if and only if no entry is present at index i.
And I doubt that constant-time behavior is relevant here because at this point an encrypted newly enrolled certificate (which BTW is extremely rare) has been received and is being decrypted. This only happens under the control of the client requesting a certficate and does not happen often.
There was a problem hiding this comment.
The constant_time_* calls go back to #9774 (comment) and #9774 (comment).
To me, following the "best practice" mentioned there appears not really need.
If you prefer, I could move the ERR_pop_to_mark(); after those.
There was a problem hiding this comment.
Please remove the set_mark/pop_to_mark as well.
There was a problem hiding this comment.
Adding the set_mark/pop_to_mark was the actual point of that commit.
As explained, using ERR_clear_error() was too harsh.
We should remove only those entries that were (potentially) added by EVP_PKEY_decrypt().
There was a problem hiding this comment.
I mean there is no point in clearing anything as there should be nothing security sensitive in error queue under the same assumptions that lead to removing the consttime calls.
There was a problem hiding this comment.
Ah, right, so we can simply get rid also of the ERR_clear_error() - even better!
Done so, rebasing and squashing the changes to crmf_lib.c.
4416068 to
942e668
Compare
942e668 to
1196fe5
Compare
t8m
left a comment
There was a problem hiding this comment.
It would be nice to have some testcases to test for error reporting. But that is for different PR I think.
|
This pull request is ready to merge |
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15283)
Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15283) (cherry picked from commit da198ad)
This removes spurious error queue entries such as
when loading private keys via OSSL_STORE: .
The underlying issue was revealed by a recent improvement in #15253.
On this occasion, alsoMakeOSSL_CRMF_ENCRYPTEDVALUE_get1_encCert()conservative on the error queuecrypto/{http,cmp}: Remove obsolete comments w.r.t.ERR_clear_error()