ASN.1: Refuse to encode to DER if non-optional items are missing [3.0]#16036
ASN.1: Refuse to encode to DER if non-optional items are missing [3.0]#16036levitte wants to merge 6 commits intoopenssl:masterfrom
Conversation
…tent The test case creates an RSA public key and tries to pass it through i2d_PrivateKey(). This SHOULD fail, since the private bits are missing.
ASN1_FBOOLEAN is designed to use as a default for optional ASN1 items. This test program used it for non-optional items, which doesn't encode well.
Make it only report (and fail on) encoding/decoding failures when success is expected.
|
This is like #16027, but for 3.0 |
|
The CI failure is only CMP related - perhaps @DDvO can look at it? I suppose the test makes some incorrect expectations? |
I have no idea... test/cmp_ctx_test.c is too macroised for me to follow, not to mention debug. |
|
(irrelevant comment removed) |
|
So it appears that this particular test tries to set an incomplete certificate (signature algorithm is unset): Line 822 in 0007ff2 The result is that |
|
I suppose replacing all the X509_new() calls in the test with calls to X509_dup() of a real certificate should fix it? |
The underlying issue is that |
The stack trace you originally provided here was of interest. It shows why part of the certificate get/set test failed, namely only those calling |
t8m
left a comment
There was a problem hiding this comment.
Approving the base change done by Richard.
|
@t8m, many thanks for fixing the test |
|
24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually. |
…tent The test case creates an RSA public key and tries to pass it through i2d_PrivateKey(). This SHOULD fail, since the private bits are missing. Reviewed-by: Tomas Mraz <[email protected]> (Merged from #16036)
Fixes #16026 Reviewed-by: Tomas Mraz <[email protected]> (Merged from #16036)
ASN1_FBOOLEAN is designed to use as a default for optional ASN1 items. This test program used it for non-optional items, which doesn't encode well. Reviewed-by: Tomas Mraz <[email protected]> (Merged from #16036)
Make it only report (and fail on) encoding/decoding failures when success is expected. Reviewed-by: Tomas Mraz <[email protected]> (Merged from #16036)
Reviewed-by: Richard Levitte <[email protected]> Reviewed-by: David von Oheimb <[email protected]> (Merged from #16036)
|
Merged 2296cc3 TEST: Check that i2d refuses to encode non-optional items with no content |
As I wrote above, the quick solution taken here is just a workaround. |
| i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, iclass); | ||
| if (!i) | ||
| return 0; | ||
| if (i == 0 && (tt->flags & ASN1_TFLG_OPTIONAL) == 0) { |
There was a problem hiding this comment.
I believe this block is unreachable because the line immediately after it would have returned zero first. It seems:
- They should be swapped.
- This call is missing a check for negative values.
Fixes #16026