-
Notifications
You must be signed in to change notification settings - Fork 5.4k
tls: add local certificate presented flag for mTLS detection #8464
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ SslSocket::SslSocket(Envoy::Ssl::ContextSharedPtr ctx, InitialState state, | |
| ctx_(std::dynamic_pointer_cast<ContextImpl>(ctx)), state_(SocketState::PreHandshake) { | ||
| bssl::UniquePtr<SSL> ssl = ctx_->newSsl(transport_socket_options_.get()); | ||
| ssl_ = ssl.get(); | ||
| info_ = std::make_shared<SslSocketInfo>(std::move(ssl)); | ||
| info_ = std::make_shared<SslSocketInfo>(std::move(ssl), state); | ||
| if (state == InitialState::Client) { | ||
| SSL_set_connect_state(ssl_); | ||
| } else { | ||
|
|
@@ -301,11 +301,29 @@ void SslSocket::shutdownSsl() { | |
| } | ||
| } | ||
|
|
||
| SslSocketInfo::SslSocketInfo(bssl::UniquePtr<SSL> ssl, InitialState state) : ssl_(std::move(ssl)) { | ||
| if (state == InitialState::Client) { | ||
| SSL_set_cert_cb( | ||
| ssl_.get(), | ||
| [](SSL*, void* arg) -> int { | ||
| auto info = static_cast<SslSocketInfo*>(arg); | ||
| info->local_cert_presented = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is sufficient, since it's not verifying that the client certificate is configured, and I think that this callback will be called even if it isn't (I might be wrong, so it's worth double-checking that). This should work better: Ideally,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We assume that handshake completes successfully. That means all those checks (there is a client cert, and CA trust chain, and other things) are already done. Why do we need another set of checks that duplicate the handshake? |
||
| return 1; | ||
| }, | ||
| this); | ||
| } else { | ||
| ASSERT(state == InitialState::Server); | ||
| local_cert_presented = true; | ||
| } | ||
| } | ||
|
|
||
| bool SslSocketInfo::peerCertificatePresented() const { | ||
| bssl::UniquePtr<X509> cert(SSL_get_peer_certificate(ssl_.get())); | ||
| return cert != nullptr; | ||
| } | ||
|
|
||
| bool SslSocketInfo::localCertificatePresented() const { return local_cert_presented; } | ||
|
|
||
| std::vector<std::string> SslSocketInfo::uriSanLocalCertificate() const { | ||
| if (!cached_uri_san_local_certificate_.empty()) { | ||
| return cached_uri_san_local_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.
It would be more efficient to configure this once in
ClientContextImplusingSSL_CTX_set_cert_cbinstead of here, when it's called for each connection.Also, installing it in
ClientContextImplmeans that there is access to the configuration values, so it might make sense to install this callback only when the client certificate is configured.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.
I'm not sure how to pass SSL info via context. Can you be more specific about your suggestion?