利用SSL/TLS中的SNI同一ip不同域名的F5vs配置解决方案

简介: 前言:在搭建支持HTTPS的前端代理服务器时候,通常会遇到让人头痛的证书问题。根据HTTPS的工作原理,浏览器在访问一个HTTPS站点时,先与服务器建立SSL连接,建立连接的第一步就是请求服务器的证书。

前言:

在搭建支持HTTPS的前端代理服务器时候,通常会遇到让人头痛的证书问题。根据HTTPS的工作原理,浏览器在访问一个HTTPS站点时,先与服务器建立SSL连接,建立连接的第一步就是请求服务器的证书。而服务器在发送证书的时候,是不知道浏览器访问的是哪个域名的,所以不能根据不同域名发送不同的证书。用过GoAgent的人都知道需要给浏览器导入证书才能使用HTTPS正常登录Twitter等网站。

SNI(Server Name Indication)是为了解决一个服务器使用多个域名和证书的SSL/TLS扩展。一句话简述它的工作原理就是,在连接到服务器建立SSL链接之前先发送要访问站点的域名(Hostname),这样服务器根据这个域名返回一个合适的证书。目前,大多数操作系统和浏览器都已经很好地支持SNI扩展,OpenSSL 0.9.8已经内置这一功能,据说新版的nginx也支持SNI。

HTTPS与SNI扩展,一个IP绑定多个SSL证书

早期的SSLv2根据经典的公钥基础设施PKI(Public Key Infrastructure)设计,它默认认为:一台服务器(或者说一个IP)只会提供一个服务,所以在SSL握手时,服务器端可以确信客户端申请的是哪张证书。

但是让人万万没有想到的是,虚拟主机大力发展起来了,这就造成了一个IP会对应多个域名的情况。解决办法有一些,例如申请泛域名证书,对所有*.yourdomain.com的域名都可以认证,但如果你还有一个yourdomain.net的域名,那就不行了。

在HTTP协议中,请求的域名作为主机头(Host)放在HTTP Header中,所以服务器端知道应该把请求引向哪个域名,但是早期的SSL做不到这一点,因为在SSL握手的过程中,根本不会有Host的信息,所以服务器端通常返回的是配置中的第一个可用证书。因而一些较老的环境,可能会产生多域名分别配好了证书,但返回的始终是同一个。

既然问题的原因是在SSL握手时缺少主机头信息,那么补上就是了。

SNI(Server Name Indication)定义在RFC 4366,是一项用于改善SSL/TLS的技术,在SSLv3/TLSv1中被启用。它允许客户端在发起SSL握手请求时(具体说来,是客户端发出SSL请求中的ClientHello阶段),就提交请求的Host信息,使得服务器能够切换到正确的域并返回相应的证书。

[warning]要使用SNI,需要客户端和服务器端同时满足条件,幸好对于现代浏览器来说,大部分都支持SSLv3/TLSv1,所以都可以享受SNI带来的便利。[/warning]

二. nginx / apache 服务器端实现
nginx和apache服务端支持SNI参见:
《nginx 同一个IP上配置多个HTTPS主机》
《apache mod_gnutls实现多HTTPS虚拟主机》

三. 支持SNI的浏览器、服务器、库
Internet Explorer 7 or later, on Windows Vista or higher. Does not work on Windows XP, even Internet Explorer 8.
Mozilla Firefox 2.0 or later
Opera 8.0 or later (the TLS 1.1 protocol must be enabled)
Opera Mobile at least version 10.1 beta on Android[citation needed]
Google Chrome (Vista or higher. XP on Chrome 6 or newer. OS X 10.5.7 or higher on Chrome 5.0.342.1 or newer)
Safari 2.1 or later (Mac OS X 10.5.6 or higher and Windows Vista or higher)
Konqueror/KDE 4.7 or later
MobileSafari in Apple iOS 4.0 or later
Android default browser on Honeycomb or newer
Windows Phone 7[citation needed]
MicroB on Maemo

四. 支持SNI的服务器
Apache 2.2.12 or later using mod_ssl(or alternatively with experimental mod_gnutls)
Cherokee if compiled with TLS support
Versions of lighttpd 1.4.x and 1.5.x with patch, or 1.4.24+ without patch
Nginx with an accompanying OpenSSL built with SNI support
LiteSpeed 4.1 or later
Pound 2.6 or later
Apache Tomcat on Java 7 or later
Microsoft Internet Information Server IIS 8

五. 支持SNI的库
Mozilla NSS 3.11.1 client-side only
OpenSSL
0.9.8f (released 11 Oct 2007) – not compiled in by default, can be compiled in with config option ‘–enable-tlsext’
0.9.8j (released 07 Jan 2009) through 1.0.0 (released 29 March 2010) – compiled in by default
GNU TLS
libcurl / cURL since 7.18.1 (released 30 Mar 2008) when compiled against an SSL/TLS toolkit with SNI support
Python 3.2 (ssl, urllib and httplib modules)
Qt 4.8
Oracle Java 7 JSSE


-------------------------------F5-----------------------

K13452: Configuring a virtual server to serve multiple HTTPS sites using the TLS Server Name Indication feature

Non-Diagnostic

   

Original Publication Date
Updated Date:

Applies to (see versions):

Topic

Purpose

You should consider using this procedure under the following condition:

  • You want to configure a single virtual server to serve multiple HTTPS sites using the Transport Layer Security (TLS) Server Name Indication (SNI) feature.

Prerequisites

You must meet the following prerequisite to use this procedure:

  • The certificate and key pairs for each of the HTTPS sites must be hosted on the virtual server.

Description

Prior to the introduction of TLS SNI as part of the TLS extensions, a single virtual server could not host multiple secure websites. This was the case because the destination server name can be decoded from the HTTP request header only after the Secure Sockets Layer (SSL) connection has been established.

With the introduction of TLS SNI, the client that supports TLS SNI can indicate the name of the server to which the client is attempting to connect, in the ClientHello packet, during the SSL handshake process. The server that supports TLS SNI can use this information to select the appropriate SSL certificate to return to the client in the ServerHello packet during the SSL handshake. As a result, the client can establish secure connections to the desired secure website from the list of multiple secure websites that are hosted on a single virtual server.

To support the TLS SNI feature, a virtual server must be assigned a default SSL profile for fallback and one SSL profile per HTTPS site. The fallback SSL profile is used when the server name does not match or when the client does not support the TLS SNI extensions. The following list is an example of the sequence of events that may occur when two clients, clientA (which supports the TLS SNI extension) and clientB (which does not support the TLS SNI extension), attempt to establish secure connections with the HTTPS site my.site1.com that is hosted on the TLS SNI virtual server:

  1. clientA establishes a TCP connection to the TLS SNI virtual server.

  2. clientA indicates the server name my.site1.com in its ClientHello packet and forwards the ClientHello packet to the TLS SNI virtual server.

  3. The TLS SNI virtual server observes that the server name my.site1.com is indicated in the received ClientHello packet.

  4. The TLS SNI virtual server checks its list of assigned SSL profiles and selects the SSL profile mysite1profile that has the server name my.site1.comconfigured.

  5. The TLS SNI virtual server returns mysite1profile's SSL certificate in its ServerHello packet to clientA.

  6. clientA establishes a secure connection to the TLS SNI virtual server after it successfully negotiates the remaining SSL options during the SSL handshake.

  7. clientB establishes a TCP connection to the TLS SNI virtual server.

  8. clientB does not support TLS SNI extension, hence there is no server name indicated in its ClientHello packet to the TLS SNI virtual server.

  9. The TLS SNI virtual server observes no SNI extension in the received ClientHello packet and selects the fallback SSL profile mydefaultprofile.

  10. The TLS SNI virtual server returns mydefaultprofile's SSL certificate (with CN my.default.com) in its ServerHello packet to clientB.

  11. clientB warns of a possible certificate mismatch when it receives the SSL certificate (with CN my.default.com) from the ServerHello packet.

For security purposes, F5 recommends that you configure the following settings with the same values for all of the SSL/TLS SNI profiles associated with the same virtual server:

  • Ciphers

  • Client Authentication

    • Client Certificate

    • Frequency

    • Certificate Chain Traversal Depth

    • Advertised Certificate Authorities

    • Certificate Revocation List (CRL)

In BIG-IP 11.2.0 and later, the BIG-IP system will display an error message that appears similar to the following example if any of the settings are non-matching:

0107157c:3: Selected client SSL profiles do not match security policies for Virtual Server /Common/<virtual server>

Additionally, the BIG-IP system displays this error message if you attempt to reconfigure the previously mentioned settings in any of the SSL/TLS SNI profiles associated with the same virtual server. To avoid this error message in subsequent attempts to reconfigure the previously mentioned settings, F5 recommends that you configure a base SSL/TLS SNI profile and use this base profile as the parent profile for the SSL/TLS SNI profiles associated to the same virtual server.

Procedures

To configure multiple HTTPS sites using TLS SNI, you must perform the following procedures:

Importing the SSL certificate and key pairs for each server name

Before you begin configuring the BIG-IP objects for TLS SNI, you must import, to the BIG-IP system, all of the SSL certificate and key pairs that belong to the multiple HTTPS sites. To do so, perform the following procedure:

Impact of procedure: Performing the following procedure should not have a negative impact on your system.

  1. Log in to the Configuration utility.

  2. Click System.

  3. Click File Management.

  4. Click SSL Certificate List.

  5. Click Import.

  6. From the Import Type menu, select Key.

  7. In the Key Name box, type a name for the certificate and key pair.

  8. To locate the key file, click Browse.

  9. To upload the key file to the BIG-IP system, click Import.

  10. Click the name of the certificate and key pair from the SSL Certificate List.

  11. Click Import.

  12. To locate the certificate file, click Browse.

  13. To upload the certificate file to the BIG-IP system, click Import.

  14. To import each SSL certificate and key pair, repeat steps 5 through 13.

Configuring the base client SSL profile

To facilitate subsequent reconfiguration of the Cipher and/or Client Authentication settings described in the earlier part of this article, you should create a base client SSL profile to serve as the parent profile of the SSL/TLS SNI profiles associated with the same virtual server. To do so, perform the following procedure:

Impact of procedure: Performing the following procedure should not have a negative impact on your system.

  1. If you have not done so, log in to the Configuration utility.

  2. Click Local Traffic.

  3. Click Profiles.

  4. Click SSL.

  5. Click Client.

  6. Click Create.

  7. In the Name box, type a name for the base client SSL profile.

  8. Optional: Configure the remaining client SSL profile options, as desired.

  9. Click Finished.

Configuring the fallback (default) client SSL profile

The system uses the fallback client SSL profile as the default SSL profile when there is no match to the server name, or when the client provides no SNI extension support. You can assign only one fallback SSL profile to each TLS SNI virtual server. To configure the fallback client SSL profile, perform the following procedure:

Note: For clients that do not support TLS SNI, if the requested server name does not match the certificate and key pair for the fallback profile, clients receive certificate warnings.

Impact of procedure: Performing the following procedure should not have a negative impact on your system.

  1. If you have not done so, log in to the Configuration utility.

  2. Click Local Traffic.

  3. Click Profiles.

  4. Click SSL.

  5. Click Client.

  6. Click Create.

  7. In the Name box, type a name for the fallback client SSL profile.

  8. For the Parent Profile setting, select the base client SSL profile you have created in the Configuring the base client SSL profile procedure.

  9. From the Configuration menu, select Advanced.

  10. Select the Certificate Key Chain check box, select the desired certificate and key for fallback, and click Add.

    Note: For BIG-IP versions earlier than 11.5.0, select the individual Certificate and Key checkboxes, and then select the desired certificates and keys for fallback.

  11. Check both the boxes for Default SSL Profile for SNI.

  12. Optional: Configure the remaining client SSL profile options, as desired.

  13. Click Finished.

Configuring the client SSL profiles for TLS SNI

To support TLS SNI, you must configure one client SSL profile per HTTPS site. To do so, perform the following procedure:

Note: Beginning in BIG-IP 11.6.0, if you leave the Server Name field blank, the BIG-IP system reads the Subject Alternative Name (SAN) from the certificate. You can skip steps 10 and 11 of this section if Hostname is used for SAN.

Impact of procedure: Performing the following procedure should not have a negative impact on your system.

  1. Log in to the Configuration utility.

  2. Click Local Traffic.

  3. Click Profiles.

  4. Click SSL.

  5. Click Client.

  6. Click Create.

  7. In the Name box, type a name for a HTTPS site’s client SSL profile.

  8. For the Parent Profile setting, select the base client SSL profile you have created in the Configuring the base client SSL profile procedure.

  9. From the Configuration menu, select Advanced.

  10. Select the Certificate Key Chain check box, select the desired certificate and key for the HTTPS site, and click Add.

    Note: For BIG-IP versions earlier than 11.5.0, select the individual Certificate and Key check boxes, and then select the desired certificate and key for the HTTPS site.

  11. Select the Server Name check box.

  12. Type the name of the HTTPS site in the Server Name box.

    Note: Beginning in BIG-IP 11.6.0, if you leave the Server Name box blank, the BIG-IP system reads the Subject Alternative Name (SAN) from the certificate. For versions prior to BIG-IP 11.6.0, if you leave the Server Name box blank, the BIG-IP system reads the Common Name (CN) from the certificate.

  13. Optional: Configure the remaining client SSL profile options, as desired.

  14. Click Finished.

  15. Repeat steps 7 through 13 for each HTTPS site.

Configuring the virtual server for TLS SNI

To configure a virtual server for TLS SNI, you must assign the related client SSL profiles to the virtual server. To do so, perform the following procedure:

Impact of procedure: Performing the following procedure should not have a negative impact on your system.

  1. Log in to the Configuration utility.

  2. Click Local Traffic.

  3. Click Virtual Servers.

  4. Click Virtual Server List.

  5. Click Create.

  6. In the Name box, type the name of the virtual server.

  7. In the Address box, type the IP address of the virtual server.

  8. In the Service Port box, type the listening port number of the virtual server.

  9. From the HTTP Profile menu, select the appropriate HTTP profile.

  10. Select the backup client SSL profile created in the previous procedure from the Available box for SSL Profile (Client), and click the << button.

  11. Select the HTTPS site’s client SSL profile created in the previous procedure from the Available box for SSL Profile (Client), and click the << button.

  12. Repeat the previous step for each HTTPS site.

  13. Optional: Configure the remaining virtual server options, as desired.

  14. Click Finished.

Supplemental Information


相关实践学习
基于函数计算快速搭建Hexo博客系统
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
目录
相关文章
|
3月前
|
JSON 安全 Serverless
在使用阿里云函数计算(FC)服务时,您可以通过自定义域名来访问部署好的云函数
在使用阿里云函数计算(FC)服务时,您可以通过自定义域名来访问部署好的云函数【1月更文挑战第23天】【1月更文挑战第112篇】
222 7
|
22天前
|
存储 缓存 负载均衡
阿里云DNS常见问题之域名DNS跳转有问题如何解决
阿里云DNS(Domain Name System)服务是一个高可用和可扩展的云端DNS服务,用于将域名转换为IP地址,从而让用户能够通过域名访问云端资源。以下是一些关于阿里云DNS服务的常见问题合集:
|
22天前
|
域名解析 缓存 网络协议
阿里云DNS常见问题之新购域名阿里云DNS无法解析如何解决
阿里云DNS(Domain Name System)服务是一个高可用和可扩展的云端DNS服务,用于将域名转换为IP地址,从而让用户能够通过域名访问云端资源。以下是一些关于阿里云DNS服务的常见问题合集:
|
22天前
|
域名解析 缓存 网络协议
阿里云DNS常见问题之DNS域名一直连不上如何解决
阿里云DNS(Domain Name System)服务是一个高可用和可扩展的云端DNS服务,用于将域名转换为IP地址,从而让用户能够通过域名访问云端资源。以下是一些关于阿里云DNS服务的常见问题合集:
|
1月前
|
安全
欢迎和阿里云一起使用国家顶级域名!
中国国家顶级域名包括“.CN”和“.中国”域名,已经成为我国政府、机构、企事业单位以及重大赛事活动的主用域名
147 0
|
2月前
|
移动开发 API
阿里云cn域名续费优惠口令
2024阿里云cn域名续费优惠口令“cn注册多个价格更优”,cn域名注册优惠口令“互联网上的中国标识”
542 0
|
2月前
|
移动开发 API
阿里云com域名续费优惠口令“com批量注册更享优惠”
阿里云com域名续费优惠口令“com批量注册更享优惠”
|
2月前
|
移动开发 API
阿里云域名注册购买优惠口令,2024新版优惠口令
阿里云域名注册购买优惠口令,2024新版优惠口令,阿里云cn域名注册优惠口令“cn注册多个价格更优”
179 0
|
2月前
|
移动开发 API
阿里云com域名优惠口令,2024亲测可用
2024阿里云com域名续费优惠口令“com批量注册更享优惠”,阿里云百科分享2024年阿里云域名优惠口令更新(注册、转入、续费均可使用)
510 0
|
2月前
|
移动开发 API
阿里云域名优惠口令及优惠口令获取方法,2024新版口令
2024年阿里云域名优惠口令,com域名续费优惠口令“com批量注册更享优惠”,cn域名续费优惠口令“cn注册多个价格更优”,cn域名注册优惠口令“互联网上的中国标识”,阿里云优惠口令是域名专属的优惠码,可用于域名注册、续费和转入使用,域名优惠口令区分域名后缀,阿里云百科分享2024年阿里云域名优惠口令更新(注册、转入、续费均可使用)
325 0