SNI: 实现多域名虚拟主机的SSL/TLS认证

默北 web应用335,7806字数 2163阅读7分12秒阅读模式

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

但是让人万万没有想到的是,虚拟主机大力发展起来了,这就造成了一个IP会对应多个域名的情况。解决办法有一些,例如申请泛域名证书,对所有*.yourdomain.com的域名都可以认证,但如果你还有一个yourdomain.net的域名,那就不行了。文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

在HTTP协议中,请求的域名作为主机头(Host)放在HTTP Header中,所以服务器端知道应该把请求引向哪个域名,但是早期的SSL做不到这一点,因为在SSL握手的过程中,根本不会有Host的信息,所以服务器端通常返回的是配置中的第一个可用证书。因而一些较老的环境,可能会产生多域名分别配好了证书,但返回的始终是同一个。文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

既然问题的原因是在SSL握手时缺少主机头信息,那么补上就是了。文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

SNI(Server Name Indication)定义在RFC 4366,是一项用于改善SSL/TLS的技术,在SSLv3/TLSv1中被启用。它允许客户端在发起SSL握手请求时(具体说来,是客户端发出SSL请求中的ClientHello阶段),就提交请求的Host信息,使得服务器能够切换到正确的域并返回相应的证书。文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

[warning]要使用SNI,需要客户端和服务器端同时满足条件,幸好对于现代浏览器来说,大部分都支持SSLv3/TLSv1,所以都可以享受SNI带来的便利。[/warning]文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

二. nginx / apache 服务器端实现
nginx和apache服务端支持SNI参见:
《nginx 同一个IP上配置多个HTTPS主机》
《apache mod_gnutls实现多HTTPS虚拟主机》文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

三. 支持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文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

四. 支持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文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

五. 支持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
参考文档:http://blog.hesey.net/2012/02/sni-for-multi-domain-ssl-tls.html
http://serverfault.com/questions/109800/multiple-ssl-domains-on-the-same-ip-address-and-same-port文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/ 文章源自运维生存时间-https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 19/01/2014 09:57:05
  • 转载请务必保留本文链接:https://www.ttlsa.com/web/sni-multi-domain-virtual-host-ssl-tls-authentication/
评论  3  访客  2
    • ★Extreme★
      ★Extreme★ 1

      我一直以为SSL都是可以共享IP的,看了此文章才知道原来以前是只能独立IP。

        • 烈火君
          烈火君 0

          @ ★Extreme★ 这就是为什么server 2016 IIS10不能设置https域名绑定的原因

      评论已关闭!