我需要获取/列出安装在Mozilla Firefox上的所有证书。我想知道是否可以用Selenium webdriver来管理它。是否可以在Firefox上列出已安装的证书?
我发现this answer并在证书存储在文件:
%appdata%/Mozilla/Firefox/<user.profile>/cert8.db
但我不能解析此文件格式。那么,是否有可能使用Selenium在Firefox上安装所有证书?
我需要获取/列出安装在Mozilla Firefox上的所有证书。我想知道是否可以用Selenium webdriver来管理它。是否可以在Firefox上列出已安装的证书?
我发现this answer并在证书存储在文件:
%appdata%/Mozilla/Firefox/<user.profile>/cert8.db
但我不能解析此文件格式。那么,是否有可能使用Selenium在Firefox上安装所有证书?
您可以使用Mozilla的certutil工具读取数据库。请注意,如果在命令提示符下运行certutil
,您将运行Windows certutil,而不是Mozilla。
要运行Mozilla的的certutil你将需要从库下载网络安全服务(NSS),在这里:
https://ftp.mozilla.org/pub/security/nss/releases/
但NSS包需要NSPR dll的正常运行。不知道为什么从NSPR v4.6.2提前,所有的软件包都只有源码包,没有所需的DLL,所以直接进入v4.6.1链接并下载缺失的dll。
http://ftp.mozilla.org/pub/nspr/releases/v4.6.1/
一旦你在同一文件夹放certutil.exe
和dll的同时运行以下命令:
certutil.exe -L -d %appdata%\Mozilla\Firefox\Profiles\<profile_folder_name_here>
其中:
有关更多的certutil命令在这里看到:
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/tools/NSS_Tools_certutil
Python脚本例子是这样的:
import subprocess
import os
ff_prof_path = '{}\\Mozilla\\Firefox\\Profiles\\'.format(os.environ['APPDATA'])
ff_prof_path = '{}{}'.format(ff_prof_path, os.listdir(ff_prof_path)[0])
result = subprocess.run('certutil -L -d {}'.format(ff_prof_path), stdout=subprocess.PIPE)
print(result.stdout.decode('utf-8'))