早就聽說有TLS1.3了,一直心癢癢,想折騰折騰試試。以前瀏覽器支持的不多,網(wǎng)上也沒太多人試過,不太敢趟雷?,F(xiàn)在有一些大型網(wǎng)站網(wǎng)站已經(jīng)弄上了TLS1.3,也有不少博主給自己的博客升級了TLS1.3了,留下了寶貴的經(jīng)驗。我也忍不住了,今天就來折騰一下看看。Openssl 1.1.1 LTS已經(jīng)發(fā)布,更新一下TLS1.3正式版。
軟件版本
?Nginx: nginx-1.15.4
?OpenSSL: openssl-1.1.1(LTS)
教程
安裝依賴
sudo apt update
sudo apt install -y build-essential libpcre3 libpcre3-dev zlib1g-dev liblua5.1-dev libluajit-5.1-dev libgeoip-dev google-perftools libgoogle-perftools-dev
下載并解壓所需軟件
wget https://nginx.org/download/nginx-1.15.4.tar.gz
tar zxf nginx-1.15.4.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1.tar.gz
tar zxf openssl-1.1.1.tar.gz
OpenSSL打補丁
pushd openssl-1.1.1
#打TLS1.3 Draft 23, 26, 28, Final補丁
curl https://raw.githubusercontent.com/hakasenyang/openssl-patch/master/openssl-equal-1.1.1_ciphers.patch | patch -p1
#打ignore Strict-SNI log補丁
curl https://raw.githubusercontent.com/hakasenyang/openssl-patch/master/openssl-ignore_log_strict-sni.patch | patch -p1
popd
Nginx補丁
pushd nginx-1.15.4
#打SPDY, HTTP2 HPACK, Dynamic TLS Record, Fix Http2 Push Error, PRIORITIZE_CHACHA補丁
curl https://raw.githubusercontent.com/kn007/patch/43f2d869b209756b442cfbfa861d653d993f16fe/nginx.patch | patch -p1
curl https://raw.githubusercontent.com/kn007/patch/c59592bc1269ba666b3bb471243c5212b50fd608/nginx_auto_using_PRIORITIZE_CHACHA.patch | patch -p1
#打Strict-SNI補丁
curl https://raw.githubusercontent.com/hakasenyang/openssl-patch/master/nginx_strict-sni.patch | patch -p1
popd
編譯安裝Nginx
如果原本編譯安裝過Nginx,可以輸入nginx -V,查看以前的configure配置。在后面加上所需參數(shù)進行編譯。
關(guān)鍵參數(shù):
?添加–with-openssl=../openssl-1.1.1來指定OpenSSL路徑
?HTTP2 HPACK需要加入–with-http_v2_hpack_enc參數(shù)。
?SPDY需要加入–with-http_spdy_module
注意將–with-openssl參數(shù)改為自己的OpenSSL文件夾地址。
我的完整configure命令如下,請類比進行。
cd nginx-1.15.4
./configure
–user=www
–group=www
–prefix=/usr/local/nginx
–with-http_stub_status_module
–with-threads
–with-file-aio
–with-pcre-jit
–with-http_ssl_module
–with-http_v2_module
–with-http_gzip_static_module
–with-http_sub_module
–with-http_flv_module
–with-http_mp4_module
–with-http_gunzip_module
–with-http_realip_module
–with-http_addition_module
–with-stream
–with-stream_ssl_module
–with-stream_ssl_preread_module
–with-stream_realip_module
–with-http_slice_module
–with-http_geoip_module
–with-google_perftools_module
–with-openssl=../openssl-1.1.1
–with-http_v2_hpack_enc
–with-http_spdy_module
configure完成后,輸入以下語句開始編譯。
make
編譯完成后,如果沒有報錯,輸入以下內(nèi)容進行安裝。
make install
配置Nginx虛擬主機
將以下內(nèi)容加入你的conf文件的相應位置,替換掉原本的相應內(nèi)容。由于安全性升級的考慮,我刪除了TLS1和TLS1.1。除此以外,TLS1.3的新加密套件只能在TLS1.3中使用,舊的加密套件不能用于TLS1.3。似乎所有虛擬主機都要配置才能使用TLS1.3。
ssl_early_data on;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers [TLS13+AESGCM+AES128|TLS13+AESGCM+AES256|TLS13+CHACHA20]:[EECDH+ECDSA+AESGCM+AES128|EECDH+ECDSA+CHACHA20]:EECDH+ECDSA+AESGCM+AES256:EECDH+ECDSA+AES128+SHA:EECDH+ECDSA+AES256+SHA:[EECDH+aRSA+AESGCM+AES128|EECDH+aRSA+CHACHA20]:EECDH+aRSA+AESGCM+AES256:EECDH+aRSA+AES128+SHA:EECDH+aRSA+AES256+SHA:RSA+AES128+SHA:RSA+AES256+SHA:RSA+3DES;
ssl_ecdh_curve X25519:P-256:P-384;
ssl_prefer_server_ciphers on;
最后使用nginx -t測試nginx配置的正確性。
成功
重啟Nginx,你會發(fā)現(xiàn)你的網(wǎng)站已經(jīng)是TLS1.3連接了。
一點問題
我原本使用的是Nginx 1.14.0,現(xiàn)在升級到了1.15.4,配置文件可能會報以下警告。當然,由于只是警告,并不會影響運行,只是我強迫癥受不了。
nginx: [warn] the “ssl” directive is deprecated, use the “listen … ssl” directive instead in /usr/local/nginx/conf/vhost/www.iszy.me.conf:22
這是由于在主線版本v1.15.0以后,棄用了ssl標識。官方原話是這樣的:
The “ssl” directive is deprecated; the “ssl” parameter of the “listen” directive should be used instead.
解決方案很簡單,只需要刪除配置文件中的ssl on語句,采用listen語句替代,如listen 443 ssl。原本就使用listen 443 ssl語句的就更簡單了,直接刪除ssl on語句即可。
后話
好了,到這里,教程算是結(jié)束了。OpenSSL 1.1.1 LTS已經(jīng)正式發(fā)布了,TLS1.3也已經(jīng)正式公布?,F(xiàn)階段,Nginx、Apache等主流web服務器還沒有官方支持,還需要通過打補丁的方式進行支持。期待TLS1.3全面鋪開后對網(wǎng)絡(luò)隱私和抗審查作出的貢獻。