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

fix: cert verify test fix #4545

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

fix: cert verify test fix #4545

wants to merge 29 commits into from

Conversation

jouho
Copy link
Contributor

@jouho jouho commented May 7, 2024

Resolved issues:

Resolves #4431

Description of changes:

  • Previously, a test case was not running due to missing #include "crypto/s2n_rsa_pss.h". This is now added so the corresponding test is running.

  • One of the test cases were failing even if the tests were enabled and this change fixes it. Specifically, the test was failing on calling s2n_tls_cert_verify_send() because The test runs in a for-loop with different configuration. The first iteration uses s2n_ecdsa_sha256 as signature scheme for the test and the second iteration uses s2n_rsa_pss_pss_sha256 as the signature scheme. The first iteration passes, but the second iteration fails because we're always setting test_scheme.sig_alg = S2N_SIGNATURE_ECDSA; this causes mismatch with RSA_PSS_PSS when sending cert_verify.

  • Negative test cases were using a single connection object to send and receive cert_verify message. This is an incorrect set up as we do not want to introduce another source of failure other than the ones we are explicitly testing,. Therefore the tests are modified to use two connections (sending_conn and verifying_conn) to properly simulate the test cases

  • In order to get better test result, change EXPECT_FAILURE() calls to EXPECT_FAILURE_WITH_ERRNO() with specific error to expect in each test case

  • Clean up code to reduce redundancy and improve readability

Call-outs:

Testing:

Confirmed s2n_tls_cert_verify_test now runs all tests and passes all cases

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

@jouho jouho requested review from lrstewart and maddeleine May 7, 2024 21:34
@github-actions github-actions bot added the s2n-core team label May 7, 2024
@jouho jouho changed the title Cert verify test fix fix: cert verify test fix May 7, 2024
tests/unit/s2n_tls13_cert_verify_test.c Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
@jouho jouho requested a review from maddeleine May 10, 2024 23:43
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
@jouho jouho requested a review from maddeleine May 14, 2024 00:08
@maddeleine
Copy link
Contributor

It looks like this test is no failing when we build with FIPS-validated libcryptos? You'll need to investigate that.

tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Show resolved Hide resolved
@jouho jouho requested a review from maddeleine May 15, 2024 22:32
@jouho jouho requested a review from maddeleine May 16, 2024 21:02
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
tests/unit/s2n_tls13_cert_verify_test.c Outdated Show resolved Hide resolved
Comment on lines 266 to 273
/* Use a hash algorithm different from sender by prepending corresponding iana value */
EXPECT_SUCCESS(s2n_stuffer_rewrite(&verifying_conn->handshake.io));
if (sig_scheme.sig_alg == S2N_SIGNATURE_ECDSA) {
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&verifying_conn->handshake.io, TLS_SIGNATURE_SCHEME_ECDSA_SHA384));
} else {
EXPECT_SUCCESS(s2n_stuffer_write_uint16(&verifying_conn->handshake.io, TLS_SIGNATURE_SCHEME_RSA_PSS_PSS_SHA384));
}
EXPECT_SUCCESS(s2n_stuffer_skip_write(&verifying_conn->handshake.io, write_cursor_position));
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a shame that RSA-PSS was added in TLS1.3 so doesn't follow the TLS1.2 formula of the first byte being the hash and the second byte being the sig alg. That would have made this test easier :( https://datatracker.ietf.org/doc/html/rfc5246#section-7.4.1.4.1

But this is incredibly fragile as-is. You need a sig scheme that matches for one field but not for the other. You should probably add a field to the s2n_tls13_cert_verify_test struct so that we can specify the "sig scheme with different hash" when we specify the test sig scheme.

@jouho jouho requested a review from lrstewart May 22, 2024 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

s2n_tls13_cert_verify_test doesn't run all cases
3 participants