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

feat: add basic support for certificate_authorities #4506

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

lrstewart
Copy link
Contributor

@lrstewart lrstewart commented Apr 16, 2024

Resolved issues:

Splitting #4502 into more reviewable chunks.

Description of changes:

I add support for the certificate_authorities extension in TLS1.3, and the certificate_authorities field of the CertificateRequest message in TLS1.2.

Call-outs:

Currently, there's no mechanism to actually set config->cert_authorities and trigger the extension to be sent. That will be the next PR, where we will load CAs from the trust store. For now, I manually set the field in the tests.

Testing:

New unit tests.

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

@github-actions github-actions bot added the s2n-core team label Apr 16, 2024
Comment on lines -24 to +25
uint16_t extension_type;
struct s2n_blob extension;
uint16_t extension_type;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding a new extension adds a new element to the client_hello parsed extension list, which adds ~40 bytes to the connection. That triggered the s2n_connection_size_test to yell at me for increasing the size of the connection. To avoid that, I swapped these two fields.

In C, the fields of a struct have to meet alignment requirements. If they don't, the compiler inserts empty space so that they do. By swapping extension and extension_type, I fixed the field alignment and avoided that empty space. See http://www.catb.org/esr/structure-packing/

Basically, this is an easy memory win that reduces the size of the parsed extensions array enough to offset the new element I added to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lrstewart lrstewart marked this pull request as ready for review April 16, 2024 18:56
@lrstewart lrstewart requested review from goatgoose and toidiu April 16, 2024 18:59
tls/extensions/s2n_extension_type_lists.c Outdated Show resolved Hide resolved
tests/unit/s2n_cert_authorities_test.c Show resolved Hide resolved
@lrstewart lrstewart requested a review from goatgoose April 16, 2024 21:18
tls/extensions/s2n_cert_authorities.c Outdated Show resolved Hide resolved
Comment on lines -177 to -180
/* RFC 5246 7.4.4 - If the certificate_authorities list is empty, then the
* client MAY send any certificate of the appropriate ClientCertificateType */
uint16_t acceptable_cert_authorities_len = 0;
POSIX_GUARD(s2n_stuffer_write_uint16(out, acceptable_cert_authorities_len));
Copy link
Contributor

Choose a reason for hiding this comment

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

To me this reads that for TLS1.2 if certificate_authorities list is empty we can send any cert. Why then write 0 instead of writing nothing?

More confusing is that now we call s2n_cert_authorities_send, which writes the size (0) and presumably an empty cert_authorities blob. So the behavior matches the existing behavior... but we also have a s2n_extension_send_if_tls13_connection which makes it seem like we shouldn't be sending anything for TLS1.2??

Seems like the call to s2n_cert_authorities_send is achieving what we want but it might end up being confusing since we technically do send when not tls13 connection. Am I missing something?

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 think you're getting the two mechanisms mixed up.

  • In TLS1.3, we send the extension.
  • In TLS1.2, we don't send the extension. s2n_extension_send_if_tls13_connection is irrelevant because there's no extension involved. Instead, certificate_authorities is part of the actual CertificateRequest message. That's also why we were writing "0" before-- that's a zero-length certificate_authorities. You can't just write nothing because then you're missing a field and the message is malformed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was missing the fact that s2n_cert_req_send is not called from the tls13 state machine.

tests/unit/s2n_server_cert_request_test.c Show resolved Hide resolved
@lrstewart lrstewart requested a review from toidiu April 17, 2024 16:31
@lrstewart lrstewart enabled auto-merge (squash) April 17, 2024 17:45
@lrstewart lrstewart merged commit 86b6730 into aws:main Apr 17, 2024
32 checks passed
@lrstewart lrstewart deleted the ca_ext_1 branch April 17, 2024 20:25
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.

3 participants