关注网络安全
和行业未来

手把手教你在HSTS预加载列表中添加Expect-C和Expect-Staple条目

本文由Scott Helme发布在个人博客

笔者注:本文需要读者对HSTS预加载的相关概念有基本理解。想了解什么是HSTS预加载,可以移步这篇文章。文中针对的预加载列表请参考此链接。

添加Expect-CT和/或Expect-Staple

想要更改预加载列表,你必须对Chromium源提交一个更改,以根据需要添加或更新条目。 首先,您需要检查Chromium源,但为了避免拉下整个代码库,可以使用此脚本来拉下所需的部分。 我正在创建一个新目录以解决问题,但您可以随时随地进行此操作。

mkdir ~/chromium
cd ~/chromium
wget https://gist.githubusercontent.com/lgarron/73cf22ed381ef9786739ee5abd816c59/raw/241c176168d9cbec8c2b5e9e90a81da77d518f76/checkout-chromium-preload-list.sh
chmod +x checkout-chromium-preload-list.sh

现在脚本已经准备就绪,我们可以检出Chromium源并更改到文件夹中。

./checkout-chromium-preload-list.sh 
cd chromium-hsts

我们需要更改的文件现在可以编辑了,您可以使用您选择的任何编辑器。

nano net/http/transport_security_state_static.json

该文件非常大,您需要进行的更改将取决于您在预加载列表中的当前列表(如果有)。 如果您已有条目并且已通过HSTS预装站点提交,则需要找到该条目并将其剪切出来以将其粘贴到手动条目部分。 如果您还没有条目,您可以继续关注并创建新条目以放入手动条目部分。 这是现有的条目的样子,以及如果已经有,则需要删除的内容。

{ "name": "scotthelme.co.uk", "include_subdomains": true, "mode": "force-https" },

无论是构建现有条目还是创建新条目,都需要为要启用的功能添加适当的字段。 以下是需要分别为Expect-CT和Expect-Staple添加的值。

"expect_ct": true, "expect_ct_report_uri": "https://scotthelme.report-uri.com/r/d/ct/reportOnly", "include_subdomains_for_expect_ct": true
"expect_staple": true, "expect_staple_report_uri": "https://scotthelme.report-uri.io/r/d/staple/reportOnly", "include_subdomains_for_expect_staple": true

如果你像我这样做了一个现有的HSTS预加载入口,且同时包含Expect-CT和Expect-Staple,你将会得到以下类似的结果。

{ "name": "scotthelme.co.uk", "include_subdomains": true, "mode": "force-https", "expect_ct": true, "expect_ct_report_uri": "https://scotthelme.report-uri.com/r/d/ct/reportOnly", "include_subdomains_for_expect_ct": true, "expect_staple": true, "expect_staple_report_uri": "https://scotthelme.report-uri.com/r/d/staple/reportOnly", "include_subdomains_for_expect_staple": true},

这个新条目将需要放在手动输入部分。你可以通过搜索//START OF MANUAL ENTRIES来查找整个部分的初始内容,也可以搜//END OF MANUAL ENTRIES找到末尾信息。请将新条目放在末尾。一旦保存了更改,如果你没有全局设置或者想要再度更改,则需要在Git中操作。

git config user.name "Scott Helme"
git config user.email "scotthelme@hotmail.com"
git config core.autocrlf false
git config core.filemode false
git config branch.autosetuprebase always
git config gerrit.host true

email地址必须使用谷歌账号且在验证过后才能起效。转到此链接并选择合适的Google帐户(如果您有多个帐户),它会向您显示运行配置git所需的命令,我在此处列出了这些命令:

touch .gitcookies 
chmod 0600 .gitcookies 
git config http.cookiefile .gitcookies 
tr , \\t <<\__END__ >>.gitcookies 
*stuff here*
__END__

我修改了这里的命令以删除全局设置,并将.cookies文件放在本地目录中而非用户主目录。

git commit -a

最后一步是下载depot_tools:

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"

现在你就可以上传更改了!

git cl upload -r lgarron@chromium.org

该命令将上传您的更改,并将其标记为当前HSTS预压列表维护人Lucas Garron审核。 该命令还会为您提供一个地址,您可以查看您提交的更改。 您需要转到链接,使用您使用的Google帐户登录,然后点击“开始审核”,否则您的更改无法进行。 随着更改提交并等待审核,您现在需要证明此请求来自域的真正所有者/管理员。 这很容易实现,只需要一个简单的DNS TXT记录来批准请求。 格式在HSTS预加载列表Wiki上的报告URI客户部分中概述,如下所示。

example.com. ... "Please preload example.com for [Expect-CT/Expect-Staple/Expect-CT and Expect-Staple] using [subdomain].report-uri.com"

然后你会收到长这样的记录:

scotthelme.co.uk. 299 IN TXT "Please preload scotthelme.co.uk for Expect-CT and Expect-Staple using scotthelme.report-uri.com"

为你的域名以及想要启用的功能更新这个记录。然后待审核员(Lucas)过目后,你的域名就可以出现在下一版Chrome中的预加载列表中啦!

稿源: Scott Helme

评论 抢沙发