如何使用Mkchain構建一個有效的SSL證書鏈
關于Mkchain
Mkchain是一款功能強大的開源安全工具,在該工具的幫助下,廣大研究人員可以輕松構建一個有效的SSL證書鏈。除此之外,該工具還可以幫助我們修復不完整的SSL證書鏈或下載所有缺失的CA證書。我們甚至還可以利用該工具從遠程服務器下載所有的證書,以修復你自己的證書鏈。
工具要求
當前版本的Mkchain需要使用到下列外部實用工具:
OpenSSL(v1.10g/h)
GNU/Linux(Debian或CentOS)
Bash(v4.4.19)
工具下載
首先,廣大研究人員可以使用下列命令將該項目源碼克隆至本地:
git clone https://github.com/trimstray/mkchain然后切換到項目目錄中,執行工具安裝腳本:
./setup.sh install將指向bin/mkchain的符號連接移動到/usr/local/bin。
工具使用手冊可以在/usr/local/man/man8中找到。
最后,使用下列命令即可開始使用Mkchain:
mkchain -i /data/certs -o /data/chain.crt工具參數
該工具提供了下列運行參數選項:
Usage:
mkchain <option|long-option>
Options:
--help 顯示工具幫助信息和退出
--debug 在屏幕上顯示調試信息(調試模式)
-i, --in 添加要整合的證書(單/多文件、包含SSL證書的目錄或遠程域名)
-o, --out 將所有的結果(證書鏈)存儲到文件中
--with-root 將根證書添加到證書鏈工具運行機制
我們以ssllabs證書鏈為例,mkchain項目中提供了一個example/ssllabs.com目錄,其中有一個all目錄(該目錄中包含了構建證書鏈所需要的全部證書)和server_certificate目錄(僅包含服務器證書)。
ssllabs.com域名的正確證書鏈(openssl命令結果):
Certificate chain
0 s:/C=US/ST=California/L=Redwood City/O=Qualys, Inc./CN=ssllabs.com
i:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K
1 s:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2012 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1K
i:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2009 Entrust, Inc. - for authorized use only/CN=Entrust Root Certification Authority - G2
2 s:/C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2009 Entrust, Inc. - for authorized use only/CN=Entrust Root Certification Authority - G2
i:/C=US/O=Entrust, Inc./OU=www.entrust.net/CPS is incorporated by reference/OU=(c) 2006 Entrust, Inc./CN=Entrust Root Certification Authority場景一
在這個場景中,我們將鏈接所有證書:

場景二
在這個場景中,我們只會使用服務器證書,并用它來獲取剩余所需的證書,然后將所有的證書鏈接:

證書路徑
Mkchain允許使用兩種證書路徑:

工具使用樣例
mkchain --in Root.crt --in Intermediate1.crt --in Server.crt --out bundle_chain_certs.crtmkchain --in /tmp/certs --out bundle_chain_certs.crt --with-rootmkchain -i Server.crt -o bundle_chain_certs.crtmkchain -i https://incomplete-chain.badssl.com/ --with-root許可證協議
本項目的開發與發布遵循GPL-3.0開源許可證協議。
項目地址
Mkchain:【GitHub傳送門】
參考資料
https://medium.com/@superseb/get-your-certificate-chain-right-4b117a9c0fce
https://support.dnsimple.com/articles/what-is-ssl-certificate-chain/
本文作者:Alpha_h4ck, 轉載請注明來自FreeBuf.COM































