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 X509_get_signature_info #1504

Merged
merged 5 commits into from
Apr 10, 2024

Conversation

samuel40791765
Copy link
Contributor

@samuel40791765 samuel40791765 commented Mar 21, 2024

Issues:

Resolves CryptoAlg-2264

Description of changes:

MySQL 8.2/8.3 depends on X509_get_signature_info. This symbol originated from an OpenSSL 1.1.1 commit (openssl/openssl@786dd2c) implementing support for "custom signature parameters".
The commit mainly allows the user to set and retrieve information about the signature type. There's also a custom ASN1 method handler that OpenSSL implemented in this commit.
We don't support custom EVP_PKEY ASN1 methods and setting your own signature information doesn't make much sense without the custom methods, so I've only implemented support for retrieving the signature type. MySQL only depends on retrieving the signature info, so this fits our use case.

Call-outs:

CryptoAlg-2393 was cut to track RSA PSS support in libssl, which was uncovered in the postgres CI.

Testing:

New test

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@samuel40791765 samuel40791765 requested a review from a team as a code owner March 21, 2024 19:07
@samuel40791765 samuel40791765 force-pushed the custom-sigs branch 3 times, most recently from 147682d to 943da00 Compare March 22, 2024 21:03
@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 76.97%. Comparing base (7cad9e3) to head (d56c5bd).

Files Patch % Lines
crypto/x509/x509_set.c 89.47% 4 Missing ⚠️
crypto/x509v3/v3_purp.c 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1504      +/-   ##
==========================================
+ Coverage   76.95%   76.97%   +0.01%     
==========================================
  Files         425      425              
  Lines       71562    71602      +40     
==========================================
+ Hits        55071    55113      +42     
+ Misses      16491    16489       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

crypto/x509/x509_set.c Show resolved Hide resolved
flags);
}

int x509_init_signature_info(X509 *x509) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't recall if we were only adding the check on external functions first, but if we are also adding to same checks to internal functions then should this validated x509 != NULL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This did come up a long while back, I think the final consensus was to cover external functions. The justification being that there would be NULL checks in the external functions calling these internal functions, so the extra check would be overkill and add additional bloat.


int X509_get_signature_info(X509 *x509, int *digest_nid, int *pubkey_nid,
int *sec_bits, uint32_t *flags) {
if (!X509_check_purpose(x509, -1, -1)) {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like the intent of this is to just trigger x509v3_cache_extensions, as it will bail out of the function afterwards due to id == -1. Would it be clearer to just call the cache function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh nice catch, I was just following the original openssl implementation, but that makes sense. I'll also add this comment from OpenSSL to X509_check_purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like Postgres is also dependent on this function and the new behavior is causing the postgres CI to fail..
I'm guessing that X509_get_signature_info is just a information retrieval function, so the cert is allowed to "invalid extensions".. which explains why OpenSSL's implementation didn't check the return value. It's a bit of a pain, but I'll have to change this to be less error prone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nvm, the postgres CI was failing since the initial change. I'll have to figure out what's going on here

Copy link
Contributor

@WillChilds-Klein WillChilds-Klein Apr 9, 2024

Choose a reason for hiding this comment

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

I see all CI checks have passed. What ended up being the issue with the postgres checks?

EDIT: nevermind, i see it was our lack of PSS support in libssl.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to mention I cut CryptoAlg-2393 to track PSS support in libssl. I'll add that in the commit/PR description.

crypto/x509/internal.h Show resolved Hide resolved
include/openssl/x509.h Outdated Show resolved Hide resolved
crypto/x509/x509_set.c Show resolved Hide resolved
@WillChilds-Klein WillChilds-Klein self-requested a review April 9, 2024 20:36
@samuel40791765 samuel40791765 merged commit dd247e2 into aws:main Apr 10, 2024
45 checks passed
@samuel40791765 samuel40791765 deleted the custom-sigs branch April 10, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants