【已过时】如何:配置HPKP(Public Key Pinning Extension for HTTP)

【已过时】如何:配置HPKP(Public Key Pinning Extension for HTTP)

HPKP 目前是一项 IETF 草案。与 HSTS 类似,它的作用是减少与 TLS 有关的安全风险。

遗憾的是,这个行业完蛋了,启用它导致了过多的人间惨剧,因此从Chrome 72开始这个功能已经不再支持。故而本文档已经成为了历史文件,不再具有现实意义。

具体来说,HPKP 是在 HTTPS 回应中加入一个 Public-Key-Pins: 响应头,并给出若干指定的公钥的fingerprint值和过期时间。

从已知的密钥对(*.key)生成:

openssl rsa -in example.com.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64

从已知的证书申请文件(*.csr)生成:

openssl req -in example.com.csr -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

从已知的证书(*.crt)生成:

openssl x509 -in example.com.crt -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64

nginx配置:

add_header Public-Key-Pins 'pin-sha256="第一个base64"; pin-sha256="第二个base64"; max-age=时长; includeSubDomains';

一般来说,应至少提供两个fingerprint(其中一个留做备用),而max-age应该尽量地长。

notes/t/hpkp_howto.txt · 最后更改: 2023/01/07 05:51