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

[757] https tls cert chains #758

Conversation

aklyuchev
Copy link


Note: by creating a PR or an issue you automatically agree to the CLA. See CONTRIBUTING.md. Feel free to remove this note, the agreement holds.

@aklyuchev aklyuchev requested a review from segoon as a code owner November 12, 2024 13:19
@fdr400
Copy link
Member

fdr400 commented Nov 12, 2024

It it possible to add tests for it?

@aklyuchev
Copy link
Author

It it possible to add tests for it?

tests for what?
for openssl function which is used here?
i don't think it make sense

core/src/server/component.cpp Outdated Show resolved Hide resolved
core/src/server/component.cpp Outdated Show resolved Hide resolved
core/src/engine/io/tls_wrapper.cpp Outdated Show resolved Hide resolved
@apolukhin
Copy link
Member

It it possible to add tests for it?

tests for what? for openssl function which is used here? i don't think it make sense

It makes sense from the point of documentation. OpenSSL is overcomplicated, especially for the beginners. A test with some hints on how to create tls chains and how the file is named would be helpful. It also makes sense as a smoke test - the openssl function may require some other functions to be called before setting the chain... a test would prevent breaking the functionality during refactorings.

Please, add a smoke test to https://github.com/userver-framework/userver/blob/develop/core/src/engine/io/tls_wrapper_test.cpp

@aklyuchev aklyuchev changed the title [757] https tls chains http cert [757] https tls cert chains Nov 13, 2024
Copy link
Member

@apolukhin apolukhin left a comment

Choose a reason for hiding this comment

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

it took some time for me to realize the drawback of this PR. SSL_CTX_use_certificate_chain_file does blocking IO operations (reads data from disk). We try hard to do the blocking operations not in the main task processor for CPU bound tasks. So the file reading should not be done in TlsWrapper::StartTlsServer.

It looks like the certificates could be extracted from chain file https://unix.stackexchange.com/questions/368123/how-to-extract-the-root-ca-and-subordinate-ca-from-a-certificate-chain-in-linux . After that the certificates could be passed via cert, key and extra_cert_authorities parameters of the TlsWrapper::StartTlsServer function.

The PR could be changed to do the following:

  • Make a function crypto::blocking::LoadFromChainFile that returns crypto::Certificate's
  • Call that function in core/src/server/net/listener_config.cpp and the certificates would make their way to core/src/server/net/listener_impl.cpp

@aklyuchev aklyuchev force-pushed the us757-https-tls-chains_http_cert branch from eba1ffc to 0b6e98c Compare January 5, 2025 10:22
@aklyuchev aklyuchev requested a review from apolukhin January 6, 2025 08:50
Copy link
Member

@apolukhin apolukhin left a comment

Choose a reason for hiding this comment

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

Very good work! Thank you very much

Added a few nitpocks

@@ -63,7 +63,7 @@ namespace components {
/// task_processor | task processor to process incoming requests | -
/// backlog | max count of new connections pending acceptance | 1024
/// tls.ca | paths to TLS CAs for client authentication | -
/// tls.cert | path to TLS server certificate | -
/// tls.cert | path to TLS server certificate chain | -
Copy link
Member

@apolukhin apolukhin Jan 6, 2025

Choose a reason for hiding this comment

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

How about path to TLS server certificate or certificate chain

Copy link
Author

Choose a reason for hiding this comment

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

ok

@@ -44,6 +45,15 @@ class Certificate {
std::shared_ptr<NativeType> cert_;
};

using CertificatesChain = std::list<Certificate>;
Copy link
Member

Choose a reason for hiding this comment

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

Why not std::vector ?

Copy link
Author

Choose a reason for hiding this comment

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

number of certificates in chain is not known in advance

CertificatesChain LoadCertficatesChainFromString(std::string_view chain)
{
CertificatesChain certificates;
const std::string beginMarker = "-----BEGIN CERTIFICATE-----";
Copy link
Member

Choose a reason for hiding this comment

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

constexpr std::string_view

{
CertificatesChain certificates;
const std::string beginMarker = "-----BEGIN CERTIFICATE-----";
const std::string endMarker = "-----END CERTIFICATE-----";
Copy link
Member

Choose a reason for hiding this comment

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

constexpr std::string_view

/// list of 'Certificate's.
///
/// @throw crypto::KeyParseError if failed to load the certificate.
CertificatesChain LoadCertficatesChainFromString(std::string_view certificatesChain);
Copy link
Member

@apolukhin apolukhin Jan 6, 2025

Choose a reason for hiding this comment

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

std::string_view chain to suppress annoying warnings about missmatch of parameter names

@aklyuchev
Copy link
Author

addressed comments and created for another MR for sure
#823
for checking CI
current might be closed most probably

@aklyuchev aklyuchev requested a review from apolukhin January 8, 2025 11:07
@apolukhin
Copy link
Member

@aklyuchev many thanks for the PR!

It is a good thing that you've added the test. Our debug build noted an issue with certificate ownership, X509_up_ref(cert_it->GetNative()); was missing. Merged with fix in f9dd97a

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.

4 participants