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

tls: Add a way to inspect peer certificate chain #2630

Conversation

nielsdevreede-rl
Copy link
Contributor

Seastar currently offers the following three functions that enable inspection of part of the certificate chain presented by and accepted from the peer during a TLS handshake using X.509 certificate credentials.

  • seastar::tls::certificate_credentials::set_dn_verification_callback
  • seastar::tls::get_dn_information
  • seastar::tls::get_alt_name_information
    These function only provide access to the Distinguished Name of the subject and the issuer and the Subject Alternative Name of the leaf certificate accepted during the handshake. Applications may have a need to inspect other properties of the certificate or certificate chain as as accepted during the TLS handshake.

Here, we propose to introduce the function seastar::tls::get_peer_certificate_chain to inspect the raw peer certificate chain data as presented and accepted during the TLS handshake. We propose not to introduce any additional abstractions to the intentionally simple existing Seastar TLS interface and to return the raw certificate data as a sequence of sequence of bytes.

We attempt to retain existing Seastar implementation conventions as much as possible, by closely mimicking the existing implementation and documentation of seastar::tls::get_dn_information and seastar::tls::session::get_peer_certificate. This leads to some minor code duplication between seastar::tls::session::get_peer_certificate and seastar::tls::session::get_peer_certificate_chain, which we propose not to resolve as these two superficially similar functions serve different purposes and return incompatible types.

We propose to introduce a single test case, test_peer_certificate_chain_handling, mostly mimicking the test_alt_names test case. For this we also propose to generate simple additional certificate test data.

Please let me know if this is suitable for inclusion upstream. I'm happy to clarify design decisions and/or update my pull request according to your guidance.

Kind regards,

Niels

@avikivity
Copy link
Member

@elcallio please review

Copy link
Contributor

@elcallio elcallio left a comment

Choose a reason for hiding this comment

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

Would maybe like to see a typedef for the byte contents, but no other real objections.

Copy link

@niekbouman-rl niekbouman-rl left a comment

Choose a reason for hiding this comment

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

nice work Niels, I left two small questions in tls_test.cc

tests/unit/tls_test.cc Show resolved Hide resolved
tests/unit/tls_test.cc Show resolved Hide resolved
@avikivity
Copy link
Member

Please use the normal changelog style, we don't use feat(whatever).

@nielsdevreede-rl nielsdevreede-rl force-pushed the feat-get-peer-certificate-chain branch from 454edb9 to 4678025 Compare January 28, 2025 10:19
@nielsdevreede-rl
Copy link
Contributor Author

As requested, I have changed the commit message, introduced a type alias and fixed my CMake errors. For ease of review, I have made the latter changes in separate commits, but would propose to squash all commits into a single commit upon your approval.

@xemul
Copy link
Contributor

xemul commented Jan 28, 2025

As requested, I have changed the commit message,

It's still feat(TLS): introduce tls::get_peer_certificate_chain somehow

@nielsdevreede-rl nielsdevreede-rl changed the title feat(TLS): introduce tls::get_peer_certificate_chain tls: Add a way to inspect peer certificate chain Jan 28, 2025
@nielsdevreede-rl nielsdevreede-rl force-pushed the feat-get-peer-certificate-chain branch 2 times, most recently from 9547a3a to 6043d8c Compare January 28, 2025 14:45
@nielsdevreede-rl
Copy link
Contributor Author

I have updated the pull request title to match the commit description. I have also squashed the commits and synced with master in an attempt to resolve the workflow failures.

src/net/tls.cc Outdated Show resolved Hide resolved
@nielsdevreede-rl
Copy link
Contributor Author

nielsdevreede-rl commented Jan 30, 2025

It seems the test failures are due to the fact the the subject and issuer of the leaf certificate contain identical distinguished names and do not identify the authority by key ID. I managed to resolve this using OpenSSL 3.2.2, but not using OpenSSL 3.2.0, which is the version provided by Ubuntu 24.04. Instead of trying to resolve this, I propose to simplify the unit test so that only a "chain" of length one is tested.

Apologies for the repeated test failures

Copy link

@niekbouman-rl niekbouman-rl left a comment

Choose a reason for hiding this comment

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

LGTM!

tests/unit/tls_test.cc Show resolved Hide resolved
@avikivity
Copy link
Member

Please fold the patches into each other, we only keep patch history if the patches are logically separate, not if they fix each other.

@nielsdevreede-rl nielsdevreede-rl force-pushed the feat-get-peer-certificate-chain branch from d488230 to d8d6b14 Compare February 4, 2025 07:41
@nielsdevreede-rl
Copy link
Contributor Author

Please fold the patches into each other, we only keep patch history if the patches are logically separate, not if they fix each other.

Done

@xemul xemul closed this in 2c941b9 Feb 4, 2025
@nielsdevreede-rl nielsdevreede-rl deleted the feat-get-peer-certificate-chain branch February 4, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants