@@ -74,11 +74,37 @@ class SSLContext
7474 DEFAULT_CERT_STORE = OpenSSL ::X509 ::Store . new # :nodoc:
7575 DEFAULT_CERT_STORE . set_default_paths
7676
77- # A callback invoked at connect time to distinguish between multiple
78- # server names.
79- #
80- # The callback is invoked with an SSLSocket and a server name. The
81- # callback must return an SSLContext for the server name or nil.
77+ # A callback invoked during the server-side handshake when the client
78+ # sends the Server Name Indication (SNI) extension.
79+ #
80+ # The callback is invoked with an SSLSocket and the server name requested
81+ # by the client as a String.
82+ #
83+ # A typical use case is to select the appropriate server certificate.
84+ # The callback can use SSLSocket#add_certificate to add certificates and
85+ # their corresponding private keys. It should return +nil+ to continue
86+ # the handshake and notify the client that the server name is accepted.
87+ #
88+ # Alternatively, the callback can return an SSLContext to switch the
89+ # context used for the connection. However, doing so is discouraged
90+ # because the underlying \OpenSSL API SSL_set_SSL_CTX() has complex and
91+ # inconsistent semantics.
92+ #
93+ # See also the man page SSL_CTX_set_tlsext_servername_callback(3).
94+ #
95+ # === Example
96+ # ctx = OpenSSL::SSL::SSLContext.new
97+ # ctx.servername_cb = proc do |ssl_socket, server_name|
98+ # if server_name == "example.com"
99+ # cert = OpenSSL::X509::Certificate.new(File.read("cert.pem"))
100+ # privkey = OpenSSL::PKey.read(File.read("cert_privkey.pem"))
101+ # ssl_socket.add_certificate(cert, privkey)
102+ # else
103+ # # Aborts the handshake with an "unrecognized_name" alert.
104+ # raise "unknown SNI hostname: #{server_name}"
105+ # end
106+ # nil
107+ # end
82108 attr_accessor :servername_cb
83109
84110 # call-seq:
0 commit comments