我需要獲取/列出安裝在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'))