我正在开发一个在 Ubuntu 上使用 Chrome 和 ChromeDriver (WebDriver) 的应用程序。
我的应用程序使用代理来传输来自浏览器的流量并支持 SSL,代理使用具有自己的证书颁发机构的自签名证书。
我知道我可以将 CA 添加到 Ubuntu 本身(
/usr/local/share/ca-certificates/
+ sudo update-ca-certificates
),这使得例如curl
使用我的自定义证书。
我还可以打开 Chrome,转到
Settings -> Privacy and security -> Security -> Manage certificates
,然后在此处添加我的自定义 CA 证书,该证书有效。
但我想自动化此操作,以便我可以创建一个脚本将我的 CA 证书添加到 Chrome。
我该怎么做?
我继续研究,结果发现 Thomas Leister 也有同样的问题,并发现 Chrome(以及 Firefox)使用他们自己的 CA 存储。
他甚至提供了一个脚本来以简单的方式安装证书:
首先确保libnss3-tools已安装
sudo apt install libnss3-tools
然后使用这个脚本:
#!/bin/bash
### Script installs root.cert.pem to certificate trust store of applications using NSS
### (e.g. Firefox, Thunderbird, Chromium)
### Mozilla uses cert8, Chromium and Chrome use cert9
###
### Requirement: apt install libnss3-tools
###
###
### CA file to install (CUSTOMIZE!)
###
certfile="root.cert.pem"
certname="My Root CA"
###
### For cert8 (legacy - DBM)
###
for certDB in $(find ~/ -name "cert8.db")
do
certdir=$(dirname ${certDB});
certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d dbm:${certdir}
done
###
### For cert9 (SQL)
###
for certDB in $(find ~/ -name "cert9.db")
do
certdir=$(dirname ${certDB});
certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d sql:${certdir}
done
https://thomas-leister.de/en/how-to-import-ca-root-certificate/