可搜索,可注册,可登录,致敬逗比大佬!尽在救援版逗比根据地 dbgjd.com
投稿文章 | 广告合作 | Telegram 群组 / 公告频道 / 使用教程

Nginx 启用 OCSP Stapling(补充章)

News mlone11978 626℃ 0评论

前文 中已介绍过 Nginx 启用 OCSP Stapling 的方法。而本文进行一点补充。

ssl_stapling_file

Nginx 中有一个 OCSP Stapling 相关的参数: ssl_stapling_file

Syntax:     ssl_stapling_file file; Default:     — Context:     http, server  When set, the stapled OCSP response will be taken from the specified file instead of querying the OCSP responder specified in the server certificate.  The file should be in the DER format as produced by the “openssl ocsp” command. 

这个 directive 用于指定一个文件,当 webserver 需要返回 OCSP response 时,webserver 将不再发起 OCSP 查询行为,而是直接将 ssl_stapling_file 记录的 response 返回给 client。

正如前文所述,开启 OCSP Stapling 所需要的文件只有 ssl_trusted_certificate 所指定的 CA 记录。如果仅使用 ssl_trusted_certificate,刚开始的几个访问是不会有 OCSP response 返回的。

而这个 directive 作为 OCSP Stapling 的可选项,好处在于,如果指定了 ssl_stapling_file,那么 webserver 从第一个访问开始就会有 OCSP response 的返回,从这个文件中读取 response 并立即返回给客户。

ssl_stapling_file 通过以下步骤生成:

openssl x509 -in website.pem -noout -ocsp_uri 

使用这个命令返回你证书对应的 OCSP 地址。例如 Let’s Encrypt 的 OCSP 地址是 http://ocsp.int-x3.letsencrypt.org/。

然后,获取站点证书的 OCSP Response 并输出到 stapled.der 文件:

openssl ocsp -no_nonce /     -issuer  intermediate.pem /     -cert    website.pem /     -CAfile  bundle.pem /     -VAfile  bundle.pem /     -url     http://ocsp.int-x3.letsencrypt.org /     -respout stapled.der 

其中 stapled.der 就是我们需要的 OCSP Response 文件。根据 OCSP 协议,这个文件只有 7 天有效期,所以服务端需要及时更新该文件。

将它定义给 ssl_stapling_file 指定,作为 OCSP Stapling 缓存依据。与前文中所述不同的是,使用 ssl_stapling_file 的情况下,不再需要 ssl_trusted_certificate 等参数。

ssl_stapling on; ssl_stapling_file .../stapled.der; 

no issuer certificate specified

这是我自己踩的一个大坑。

no issuer certificate specified 

看这句子都知道是中间没有被指定的意思,这时我是一脸懵比的。

因为,我明明有写中间的:

openssl ocsp -no_nonce /     -cert    website.pem /     -issuer  intermediate.pem /     -CAfile  bundle.pem /     -VAfile  bundle.pem /     -url     http://ocsp.int-x3.letsencrypt.org /     -respout stapled.der 

WTF,我心中这样想着。

然后我去问谷歌爸爸,他是这样回复我的:

-issuer filename     This specifies the current issuer certificate.      This option MUST come before any -cert options. 

划重点:before

我丢你妹,搞半天还有顺序要求的?你让我这强迫症怎么受得了。

好,你赢了,我屈服还不行吗:

localhost#: openssl ocsp -no_nonce /     -issuer  intermediate.pem /     -cert    website.pem /     -CAfile  bundle.pem /     -VAfile  bundle.pem /     -url     http://ocsp.int-x3.letsencrypt.org /     -respout stapled.der  OCSP response: OCSP Response Data:     OCSP Response Status: successful (0x0)     Response Type: Basic OCSP Response 

转载请注明:逗比根据地 » Nginx 启用 OCSP Stapling(补充章)

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址