Skip to content

ssl: Add an SslCtxCb hook to Ssl::HandshakerFactory.#15179

Merged
htuch merged 13 commits intoenvoyproxy:mainfrom
ambuc:sslctx_cb_01
Mar 3, 2021
Merged

ssl: Add an SslCtxCb hook to Ssl::HandshakerFactory.#15179
htuch merged 13 commits intoenvoyproxy:mainfrom
ambuc:sslctx_cb_01

Conversation

@ambuc
Copy link
Copy Markdown
Contributor

@ambuc ambuc commented Feb 24, 2021

Commit Message: Add an SslCtxCb hook to Ssl::HandshakerFactory.
Additional Description: This lets a custom handshaker configure the SSL_CTX object after creation, but before it is used to create any SSL objects.

Per the BoringSSL docs, "|SSL_CTX| are reference-counted and may be shared by connections across multiple threads. Once shared, functions which change the |SSL_CTX|'s configuration may not be used." Additionally, the SSL_CTX object is complex enough and has enough methods that, rather than expose each of them via another method on some wrapper class, it is convenient to just allow mutating access via a callback during socket creation (as in tls/context_impl.cc` in this PR).

This PR also provides a reference to the HandshakerFactoryContext to this sslctx_cb callback at runtime so that a custom handshaker can further inject SSL_CTX configuration behavior.

Risk Level: Low
Testing: n/a
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: James Buckland <jbuckland@google.com>
Copy link
Copy Markdown
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

What is this PR trying to fix, exactly? This is the issue with exposing interfaces, but not having consumers for them in public. It's impossiible to review this PR without context.

Also, why are you quoting OpenSSL documentation? We don't use OpenSSL, and I cannot find such statements in BoringSSL documenation.

@ambuc
Copy link
Copy Markdown
Contributor Author

ambuc commented Feb 24, 2021

Re the second point: sorry for the link to the wrong docs. I updated the description with the BoringSSL docs' mention of the same notion, that it is invalid to modify SSL_CTX's configuration after it is shared.

Re the first point: I have a private implementation of the custom handshaker interface which needs to call SSL_CTX_* methods on the SSL_CTX object. I'm going to write a test which exercises this callsite to regression-proof it and re-request review on this PR.

Signed-off-by: James Buckland <jbuckland@google.com>
@ambuc ambuc requested a review from PiotrSikora February 25, 2021 15:56
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Copy link
Copy Markdown
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

/wait

Network::TransportSocketCallbacks* transportSocketCallbacks() override { return callbacks_; }

protected:
friend class SslSocketFriend;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This class doesn't exist, I don't think? Delete.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's used in handshaker_factory_test.cc as a way to peek at an SslSocket's underlying SSL*. I thought briefly about just making the rawSsl() accessor public instead of protected but decided that it would expose the internal SSL* too much.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The pattern used elsewhere for this is to create a method rawSslForTest().

@ggreenway ggreenway self-assigned this Feb 26, 2021
Signed-off-by: James Buckland <jbuckland@google.com>
ambuc added 2 commits March 1, 2021 11:36
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
@ambuc ambuc requested a review from PiotrSikora March 1, 2021 20:15
PiotrSikora
PiotrSikora previously approved these changes Mar 1, 2021
Copy link
Copy Markdown
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Copy Markdown
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

Looks good overall; just a few minor things

/wait

Network::TransportSocketCallbacks* transportSocketCallbacks() override { return callbacks_; }

protected:
friend class SslSocketFriend;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The pattern used elsewhere for this is to create a method rawSslForTest().

ambuc added 2 commits March 2, 2021 14:15
…fig.

Signed-off-by: James Buckland <jbuckland@google.com>
Signed-off-by: James Buckland <jbuckland@google.com>
@ambuc
Copy link
Copy Markdown
Contributor Author

ambuc commented Mar 2, 2021

Re #15179 (comment): I changed this PR to introduce rawSslForTest() instead of SslSocketFriend to be more aligned with the pattern used elsewhere.

@ambuc ambuc requested review from PiotrSikora and ggreenway March 2, 2021 19:26
@ambuc
Copy link
Copy Markdown
Contributor Author

ambuc commented Mar 3, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #15179 (comment) was created by @ambuc.

see: more, trace.

@htuch htuch merged commit 565e97d into envoyproxy:main Mar 3, 2021
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