Skip to content

Comments

ASN.1: Refuse to encode to DER if non-optional items are missing [1.1.1]#16027

Closed
levitte wants to merge 7 commits intoopenssl:OpenSSL_1_1_1-stablefrom
levitte:fix-16026-111
Closed

ASN.1: Refuse to encode to DER if non-optional items are missing [1.1.1]#16027
levitte wants to merge 7 commits intoopenssl:OpenSSL_1_1_1-stablefrom
levitte:fix-16026-111

Conversation

@levitte
Copy link
Member

@levitte levitte commented Jul 8, 2021

Fixes #16026

@levitte levitte added approval: review pending This pull request needs review by a committer branch: 1.1.1 Applies to OpenSSL_1_1_1-stable branch (EOL) labels Jul 8, 2021
@levitte levitte marked this pull request as draft July 8, 2021 11:47
levitte added 2 commits July 8, 2021 13:52
…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.
@levitte
Copy link
Member Author

levitte commented Jul 8, 2021

So much test failure... what box did I open now, Pandora?

levitte added 3 commits July 9, 2021 08:29
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.
@levitte
Copy link
Member Author

levitte commented Jul 9, 2021

Corrresponding for 3.0 in #16036

@levitte levitte marked this pull request as ready for review July 9, 2021 07:11
@levitte
Copy link
Member Author

levitte commented Jul 9, 2021

Failures resolved. I did the length check in the wrong spot...

@t8m t8m added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels Jul 9, 2021
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels Jul 10, 2021
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

openssl-machine pushed a commit that referenced this pull request Jul 10, 2021
…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 #16027)
openssl-machine pushed a commit that referenced this pull request Jul 10, 2021
openssl-machine pushed a commit that referenced this pull request Jul 10, 2021
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 #16027)
openssl-machine pushed a commit that referenced this pull request Jul 10, 2021
Make it only report (and fail on) encoding/decoding failures when success
is expected.

Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #16027)
openssl-machine pushed a commit that referenced this pull request Jul 10, 2021
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from #16027)
@levitte
Copy link
Member Author

levitte commented Jul 10, 2021

Merged

12e9b74 TEST: Check that i2d refuses to encode non-optional items with no content
006906c ASN.1: Refuse to encode to DER if non-optional items are missing
5434acb Fix test/asn1_encode_test.c to not use ASN1_FBOOLEAN
f1d9790 Fix test/asn1_encode_test.c to handle encoding/decoding failure
ea26844 make update (adds a new function code)

@levitte levitte closed this Jul 10, 2021
@levitte levitte deleted the fix-16026-111 branch July 10, 2021 10:08
@kgold2
Copy link

kgold2 commented Aug 9, 2021

This breaks an application using an ISO 11889 HSM.
I suggest, to avoid the regression, to add a new, more restrictive i2d_x509_xxx API, but leave the existing function as it currently works. In general, I think it's better to add new APIs than to change the behavior of existing ones.

@t8m t8m mentioned this pull request Aug 13, 2021
1 task
davidben added a commit to davidben/pyopenssl that referenced this pull request Aug 23, 2021
A default-constructed X509_REQ or NETSCAPE_SPKI contains empty values
for all its fields, notably the OIDs in public keys. Previously, OpenSSL
would silently omit the field, which isn't actually a valid structure.

As of openssl/openssl#16027, OpenSSL will notice
this and return an error rather than serialize garbage. Sadly, that had
to be reverted on 1.1.1, but it is present in the 3.0 branch.

Fix pyOpenSSL's tests to stop trying to serialize invalid objects. It
should fill in the public key (which is mandatory in these structures).
While not syntactically necessary (the empty string is a BIT STRING),
also fill in the signature for NetscapeSPKI.

Tested by running pyOpenSSL tests against a copy of OpenSSL 1.1.1's dev
branch, prior to the changes getting reverted.
davidben added a commit to davidben/pyopenssl that referenced this pull request Aug 23, 2021
A default-constructed X509_REQ or NETSCAPE_SPKI contains empty values
for all its fields, notably the OIDs in public keys. This initial state
is incomplete and not yet a valid object. The ASN.1 structures make the
public key mandatory.  When serializing, OpenSSL would previously
silently omit the field, which doesn't actually produce a valid
structure.

As of openssl/openssl#16027, OpenSSL will notice
this and return an error rather than serialize garbage. Sadly, that had
to be reverted on 1.1.1, but it is present in the 3.0 branch. With that
change, some of pyOpenSSL's tests fail.

The bug here is in pyOpenSSL: pyOpenSSL tests are trying to serialize
incomplete objects. Instead, fill in the public key.  While not
syntactically necessary (the empty string is a BIT STRING), also fill in
the signature for NetscapeSPKI, to better align with real code.

Tested by running pyOpenSSL tests against a copy of OpenSSL 1.1.1's dev
branch, prior to the changes getting reverted.
alex pushed a commit to pyca/pyopenssl that referenced this pull request Aug 23, 2021
A default-constructed X509_REQ or NETSCAPE_SPKI contains empty values
for all its fields, notably the OIDs in public keys. This initial state
is incomplete and not yet a valid object. The ASN.1 structures make the
public key mandatory.  When serializing, OpenSSL would previously
silently omit the field, which doesn't actually produce a valid
structure.

As of openssl/openssl#16027, OpenSSL will notice
this and return an error rather than serialize garbage. Sadly, that had
to be reverted on 1.1.1, but it is present in the 3.0 branch. With that
change, some of pyOpenSSL's tests fail.

The bug here is in pyOpenSSL: pyOpenSSL tests are trying to serialize
incomplete objects. Instead, fill in the public key.  While not
syntactically necessary (the empty string is a BIT STRING), also fill in
the signature for NetscapeSPKI, to better align with real code.

Tested by running pyOpenSSL tests against a copy of OpenSSL 1.1.1's dev
branch, prior to the changes getting reverted.