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 Version Check for CSR Verification #24677

Closed
wants to merge 3 commits into from

Conversation

erbsland-dev
Copy link
Contributor

@erbsland-dev erbsland-dev commented Jun 18, 2024

Fixes #5738: This change introduces a check for the version number of a CSR document before its signature is verified. If the version number is not 1 (encoded as zero), the verification function fails with an X509_R_UNSUPPORTED_VERSION error.

To minimise impact, this check is only applied when verifying a certificate signing request using the -verify argument limiting it to the X509_REQ_verify_ex and X509_REQ_verify functions. This ensures that malformed certificate requests are rejected by a certification authority, enhancing security and preventing potential issues.

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label Jun 18, 2024
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Jun 18, 2024
@nhorman
Copy link
Contributor

nhorman commented Jun 18, 2024

@erbsland-dev would you please sign an icla as documented here so that we can review, and potentially accept this PR? I don't think we can circumvent the agreement, as it wouldn't be considered trivial.

Copy link
Contributor

@nhorman nhorman left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@t8m t8m added hold: cla required The contributor needs to submit a license agreement branch: master Merge to master branch approval: review pending This pull request needs review by a committer approval: otc review pending This pull request needs review by an OTC member triaged: feature The issue/pr requests/adds a feature cla: trivial One of the commits is marked as 'CLA: trivial' tests: exempted The PR is exempt from requirements for testing labels Jun 19, 2024
@@ -43,6 +43,11 @@ int X509_verify(X509 *a, EVP_PKEY *r)
int X509_REQ_verify_ex(X509_REQ *a, EVP_PKEY *r, OSSL_LIB_CTX *libctx,
const char *propq)
{
if (X509_REQ_get_version(a) != X509_REQ_VERSION_1) {
ERR_raise_data(ERR_LIB_X509, ERR_R_UNSUPPORTED, "version != 1");
Copy link
Member

Choose a reason for hiding this comment

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

IMO ERR_raise(ERR_LIB_X509, X509_R_UNSUPPORTED_VERSION); would be more appropriate. Of course that requires running make update to add the new error reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@t8m I fully agree. I avoided adding a new error reason to keep this pull request minimal and its impact easily observable.

However, since the library lacks version checks in most of the X509 code, I would recommend introducing this new error code along with stricter version checking for all X509 functions.

@erbsland-dev
Copy link
Contributor Author

@nhorman I also wrote a test for this, but I found no guidelines if the test shall go along with the original PR, or be committed as independent PR.

@t8m
Copy link
Member

t8m commented Jun 19, 2024

@nhorman I also wrote a test for this, but I found no guidelines if the test shall go along with the original PR, or be committed as independent PR.

It should be included in this PR.

@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Jun 19, 2024
erbsland-dev added a commit to erbsland-dev/openssl that referenced this pull request Jun 19, 2024
As suggested in PR openssl#24677, introduce a new error code `X509_R_UNSUPPORTED_VERSION` to report malformed X509 requests with a version other than 1.
Changing the error reporting in `X509_REQ_verify_ex`, using the new error code.
@erbsland-dev
Copy link
Contributor Author

@t8m Based on your recommendation, I added the new error code X509_R_UNSUPPORTED_VERSION after assessing its impact. The addition of this error code for X509 has minimal impact but significantly improves the readability of the returned error message.

Copy link
Member

@t8m t8m left a comment

Choose a reason for hiding this comment

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

Just style nits.

Also please drop the CLA: trivial annotations from the first commits.

test/x509_req_test.c Outdated Show resolved Hide resolved
test/x509_req_test.c Show resolved Hide resolved
test/x509_req_test.c Show resolved Hide resolved
@t8m t8m added tests: present The PR has suitable tests present hold: cla required The contributor needs to submit a license agreement and removed tests: exempted The PR is exempt from requirements for testing cla: trivial One of the commits is marked as 'CLA: trivial' labels Jun 19, 2024
Fixes openssl#5738: This change introduces a check for the version number of a CSR document before its signature is verified. If the version number is not 1 (encoded as zero), the verification function fails with an `X509_R_UNSUPPORTED_VERSION` error.

To minimize impact, this check is only applied when verifying a certificate signing request using the `-verify` argument, resulting in a `X509_REQ_verify` call. This ensures that malformed certificate requests are rejected by a certification authority, enhancing security and preventing potential issues.
Tests openssl#5738: Introduce a new test to verify that a malformed X509 request with the version field set to version 6 fails either early when reading from data or later when `X509_REQ_verify` is called.
Adding a new test recipe `60-test_x509_req.t`
@erbsland-dev
Copy link
Contributor Author

@t8m I apologize for the oversights; I’m not accustomed to writing C code anymore. I have also squashed the commits into two: one for the changes and one for the tests. Additionally, I removed the “CLA: trivial” note and adjusted the commit messages accordingly.

@t8m t8m removed the approval: otc review pending This pull request needs review by an OTC member label Jun 19, 2024
Update the `x509_req_test` to ensure ANSI compatibility. The integrated certificate string was too long, so the PEM certificate has been moved to `certs/x509-req-detect-invalid-version.pem`. The test have been updated to load this certificate from the file on disk.
@erbsland-dev erbsland-dev reopened this Jun 20, 2024
@erbsland-dev erbsland-dev reopened this Jun 20, 2024
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label Jun 20, 2024
@t8m
Copy link
Member

t8m commented Jun 20, 2024

@nhorman please rereview

@erbsland-dev
Copy link
Contributor Author

@t8m @nhorman If there are any smaller fixes or enhancements I can help with, please let me know. Since I don’t have a comprehensive overview of the project, it’s difficult for me to identify the most important issues. However, as a lifelong user of the library, I’m eager to contribute. If you can point me to specific tasks that need implementation, I’d be happy to work on them.

@nhorman
Copy link
Contributor

nhorman commented Jun 20, 2024

Review holds, approved

@nhorman
Copy link
Contributor

nhorman commented Jun 20, 2024

@erbsland-dev thank you for the offer. To keep you informed, typically we mark issues that we feel should be addressed, but are not within our capacity to handle, with the "help wanted" tag. You are more than welcome to scan that list at your discretion and create PR's for them at will. If you like, leave a comment and I'll happily assign them to you.

Further, we have a "good first issue" tag that further refines out issues that have been in the past considered to be a good starting point for people just getting involved, if you're so inclined.

A word of warning, as you have likely noticed, I've been cleaning up our issue list lately, and the help wanted issues are not well groomed yet, so its a bit of a "wild west" situtation, and you may find many issues that are old, and not clearly defined. I apologize for that, but do you're best, cleaning that up is on my list :)

@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 Jun 20, 2024
@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 Jun 21, 2024
@openssl-machine
Copy link
Collaborator

This pull request is ready to merge

@nhorman
Copy link
Contributor

nhorman commented Jun 21, 2024

merged to master, thank you for your contribution!

@nhorman nhorman closed this Jun 21, 2024
openssl-machine pushed a commit that referenced this pull request Jun 21, 2024
Fixes #5738: This change introduces a check for the version number of a CSR document before its signature is verified. If the version number is not 1 (encoded as zero), the verification function fails with an `X509_R_UNSUPPORTED_VERSION` error.

To minimize impact, this check is only applied when verifying a certificate signing request using the `-verify` argument, resulting in a `X509_REQ_verify` call. This ensures that malformed certificate requests are rejected by a certification authority, enhancing security and preventing potential issues.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #24677)
openssl-machine pushed a commit that referenced this pull request Jun 21, 2024
Tests #5738: Introduce a new test to verify that a malformed X509 request with the version field set to version 6 fails either early when reading from data or later when `X509_REQ_verify` is called.
Adding a new test recipe `60-test_x509_req.t`

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #24677)
openssl-machine pushed a commit that referenced this pull request Jun 21, 2024
Update the `x509_req_test` to ensure ANSI compatibility. The integrated certificate string was too long, so the PEM certificate has been moved to `certs/x509-req-detect-invalid-version.pem`. The test have been updated to load this certificate from the file on disk.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #24677)
@erbsland-dev erbsland-dev deleted the issue-5738 branch June 22, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Merge to master branch tests: present The PR has suitable tests present triaged: feature The issue/pr requests/adds a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The version of a CSR is not checked using openssl req.
5 participants