Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Server Name Indication (SNI)

Tags:

c

ssl

openssl

sni

How to implement Server Name Indication(SNI) on OpenSSL in C or C++?

Are there any real world examples available?

like image 777
2.8a8a_G Avatar asked Feb 25 '11 03:02

2.8a8a_G


People also ask

How do you set up SNI?

Enable SNI feature on the SSL virtual server. Navigate to Traffic Management > Load Balancing > Virtual Servers > Select the virtual server and click Edit >SSL Parameters and check SNI Enable.

Why do we need Server Name Indication SNI )?

Server Name Indication (SNI) is an extension to the TLS protocol. It allows a client or browser to indicate which hostname it is trying to connect to at the start of the TLS handshake. This allows the server to present multiple certificates on the same IP address and port number.

What is SNI when you need to use SNI?

On Windows Server 2012, IIS supports Server Name Indication (SNI), which is a TLS extension to include a virtual domain as a part of SSL negotiation. What this effectively means is that the virtual domain name, or a hostname, can now be used to identify the network end point.

Can SNI be an IP address?

Server Name Indication (SNI) allows the server to safely host multiple TLS Certificates for multiple sites, all under a single IP address. It adds the hostname of the server (website) in the TLS handshake as an extension in the CLIENT HELLO message.


1 Answers

On the client side, you use SSL_set_tlsext_host_name(ssl, servername) before initiating the SSL connection.

On the server side, it's a little more complicated:

  • Set up an additional SSL_CTX() for each different certificate;
  • Add a servername callback to each SSL_CTX() using SSL_CTX_set_tlsext_servername_callback();
  • In the callback, retrieve the client-supplied servername with SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name). Figure out the right SSL_CTX to go with that host name, then switch the SSL object to that SSL_CTX with SSL_set_SSL_CTX().

The s_client.c and s_server.c files in the apps/ directory of the OpenSSL source distribution implement this functionality, so they're a good resource to see how it should be done.

like image 96
caf Avatar answered Sep 20 '22 14:09

caf