Skip to content

Add OpenSSL::SSL::SSLContext#client_hello_cb= (binding for SSL_CTX_set_client_hello_cb()) #1125

Open

Description

@kou

How about adding OpenSSL::SSL::SSLContext#client_hello_cb=, a binding for SSL_CTX_set_client_hello_cb()?

Motivation

Apache httpd and nginx use the ClientHello callback for SNI-based virtual host selection:

OpenSSL::SSL::SSLContext#servername_cb= uses the servername callback (SSL_CTX_set_tlsext_servername_callback()) for the same purpose.

The ClientHello callback is invoked at the beginning of ClientHello processing, before the protocol version is negotiated. The servername callback is invoked after that. So settings of the SSLContext selected by SNI, such as min_version and max_version, can take effect only when the context is switched in the ClientHello callback. Both commits above describe this as the reason for the change.

Compatibility

  • OpenSSL 1.1.1 or later: supported
  • AWS-LC: supported (SSL_CTX_set_client_hello_cb() is available)
  • LibreSSL: not supported (the API isn't available)

Activity

  1. kou commented on Oct 13, 2026

    @kou
    MemberAuthor

    #1126 is an implementation of this.

  2. added a commit that references this issue on Oct 13, 2026
    00e2617
  3. rhenium commented on Oct 13, 2026

    @rhenium
    Member

    This seems useful. However, I would prefer not to allow it to replace the SSLContext. SSL_set_SSL_CTX() has very strange and inconsistent semantics, and I expect it will eventually go away, since I don't see how it could be made to behave in a sane way. A related discussion on OpenSSL's issue tracker is openssl/openssl#6109.

    My understanding is that the recommendation is to configure SSL object directly instead. We should first add more configuration accessors to SSLSocket, such as SSLSocket#add_certificate or #min_version= so they can be called from within client_hello_cb, which currently exist only on SSLContext.

    I think a remaining question is which accessors SSLSocket should get. Maybe all?

    Unrelated, but some existing callbacks such as servername_cb and client_cert_cb (which currently has no way to return intermediate CA certificates) could also benefit from those new accessors.

  4. kou commented on Oct 13, 2026

    @kou
    MemberAuthor

    It makes sense. Let's use the approach. We can do it step by step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions