-
Notifications
You must be signed in to change notification settings - Fork 296
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
[757] https tls cert chains #758
Conversation
It it possible to add tests for it? |
tests for what? |
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 |
There was a problem hiding this 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
eba1ffc
to
0b6e98c
Compare
There was a problem hiding this 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 | - |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not std::vector ?
There was a problem hiding this comment.
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
universal/src/crypto/certificate.cpp
Outdated
CertificatesChain LoadCertficatesChainFromString(std::string_view chain) | ||
{ | ||
CertificatesChain certificates; | ||
const std::string beginMarker = "-----BEGIN CERTIFICATE-----"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr std::string_view
universal/src/crypto/certificate.cpp
Outdated
{ | ||
CertificatesChain certificates; | ||
const std::string beginMarker = "-----BEGIN CERTIFICATE-----"; | ||
const std::string endMarker = "-----END CERTIFICATE-----"; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
addressed comments and created for another MR for sure |
@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, |
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.