Firefox安装证书的几种方式

Firefox安装证书的几种方式。

关于bat脚本

bat脚本中的变量类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@echo off

set regPath=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
set regKey=ProgramFilesDir
set regValue=
set Value1="ww"

reg query %regPath% >nul 2>nul
if %errorlevel%==0 (
echo Registry key %regPath% exists.
for /f "tokens=2*" %%a in ('reg query %regPath% /v %regKey% ^| findstr /i %regKey%') do (
if "%regValue%"=="" (
echo value not exists
) else (
set Value1=%%b
echo %%b
echo !Value1! 1
)
)
) else (
echo Registry key %regPath% does not exist.
)

在这个示例脚本中,首先使用set命令给变量Value1赋初值为"ww"。然后,脚本使用reg query命令检查注册表中是否存在指定的注册表目录,如果存在,则使用for /f命令和reg query命令的输出来解析注册表值的名称和数据,并将其存储在变量Value1中。最后,脚本输出变量Value1的值,以及一个附加的字符串1

请注意,在使用echo命令输出变量Value1的值之前,需要在变量名前加上%字符。否则,输出的将是变量名本身,而不是其存储的值。另外,变量Value1的值在if语句中被设置,因此需要在该语句块中使用!字符来代替%字符,以启用延迟变量扩展。这样,才能在语句块中正确地引用变量Value1的值。

我刚开始用%%输出变量值,发现跟预期不一致,万能的GPT帮我纠正了这个错误。

关于引用变量:

在 Windows 中,批处理脚本中使用变量时,有两种方式来引用变量的值:%var%!var!。这两种方式的主要区别在于变量的扩展方式和生命周期。

%var% 表示立即扩展变量,也称为百分号变量。在批处理脚本中,使用 %var% 可以将变量扩展为其当前值。变量在整个批处理脚本的生命周期内都是有效的,但是在某些情况下,它们可能不会像预期那样扩展。例如,如果要在一个代码块中使用变量,而该变量在该代码块之前已被更改,则百分号变量可能会扩展为旧值,而不是新值。

!var! 表示延迟扩展变量,也称为感叹号变量。在批处理脚本中,使用 !var! 可以将变量扩展为其当前值,但是它是在运行时进行扩展的,而不是在解析时进行扩展的。因此,变量的生命周期仅限于它们在脚本中使用的代码块。如果需要在代码块中使用变量,并且该变量在代码块之前已被更改,则可以使用感叹号变量来确保变量扩展为其当前值。

在批处理脚本中,使用 setlocal enabledelayedexpansion 命令可以启用感叹号变量。启用延迟扩展后,可以使用 !var! 来引用变量的值。

因此,%% 表示百分号变量,!! 表示感叹号变量。在批处理脚本中,使用 %% 来引用百分号变量的值,使用 !! 来引用感叹号变量的值。

脚本闪退怎么办

脚本执行后马上闪退可能是由于脚本中的某个命令出错导致的。您可以尝试添加 pause 命令到脚本的末尾,这样脚本执行完毕后会暂停,以便您查看执行结果和错误信息。

如果您希望在脚本发生错误时能够看到错误信息,可以将 @echo off 命令注释掉,这样脚本在执行时会输出命令的执行结果和错误信息,以便您查看。

另外,您还可以尝试在命令行中执行脚本,而不是双击脚本文件来执行,这样如果脚本发生错误,错误信息将会一直显示在命令行中,直到您手动关闭命令行窗口。

最后,如果您仍然无法解决问题,可以尝试逐步注释掉脚本中的命令,直到找到引起问题的命令为止。

关于Firefox证书

firefox使用自己的证书库,其他浏览器如Chrome,使用操作系统的证书库。

主要参考资料

https://wiki.mozilla.org/CA/AddRootToFirefox (官方说法,最全。)

https://stackoverflow.com/questions/1435000/programmatically-install-certificate-into-mozilla

方法1:certutil.exe

使用nss,下载nss包(官方已删除已仓库连接,没有编译好的版本,需重新编译)好像还需要NSPR,使用certutil.exe(和windows自带的certutil是两种不同的东西。)
参考地址:https://stackoverflow.com/questions/1435000/programmatically-install-certificate-into-mozilla
https://stackoverflow.com/questions/50159193/how-to-add-certificate-programmatically-into-firefox-version-59-cannot-find-cer
文件下载路径:
https://ftp.mozilla.org/pub/security/nss/releases/NSS_3_13_5_RTM/src/
https://ftp.mozilla.org/pub/nspr/releases/

构建方法:https://brpoblog.wordpress.com/2015/10/02/add-certificates-to-firefox-installation-with-certutil/

报错,提示缺少MSVCR71.DLL。下载此dll文件,放到bin文件夹。
https://cn.dll-files.com/download/837b1e310f2aa8b20f07a9b1ce90ac4f/msvcr71.dll.html?c=d3JyZEIva1QwMm1IbFpwVGhQK1kwQT09

1
2
3
4
5
6
7
8
9
10
11
12
13
显示证书:

certutil.exe -L -d "%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\urvqiw6e.default"

安装证书:

certutil.exe -A -n "SomeNametest" -t "u,u,u" -i D:\UserData\h4m5tdesktop\Fortinet_CA_SSL.cer -d "%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\urvqiw6e.default"

安装之后再查看:

certutil.exe -L -d "%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\urvqiw6e.default"

发现已经在列表中了。

certutil.exe使用方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
C:\Users\h4m5t\Downloads\nss-3.11\nss-3.11\bin>certutil.exe -H
-A Add a certificate to the database (create if needed)
-E Add an Email certificate to the database (create if needed)
-n cert-name Specify the nickname of the certificate to add
-t trustargs Set the certificate trust attributes:
p valid peer
P trusted peer (implies p)
c valid CA
T trusted CA to issue client certs (implies c)
C trusted CA to issue server certs (implies c)
u user cert
w send warning
g make step-up cert
-f pwfile Specify the password file
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-a The input certificate is encoded in ASCII (RFC1113)
-i input Specify the certificate file (default is stdin)

-C Create a new binary certificate from a BINARY cert request
-c issuer-name The nickname of the issuer cert
-i cert-request The BINARY certificate request file
-o output-cert Output binary cert to this file (default is stdout)
-x Self sign
-m serial-number Cert serial number
-w warp-months Time Warp
-v months-valid Months valid (default is 3)
-f pwfile Specify the password file
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-1 Create key usage extension
-2 Create basic constraint extension
-3 Create authority key ID extension
-4 Create crl distribution point extension
-5 Create netscape cert type extension
-6 Create extended key usage extension
-7 Create an email subject alt name extension
-8 Create an dns subject alt name extension

-G Generate a new key pair
-h token-name Name of token in which to generate key (default is internal)
-k key-type Type of key pair to generate ("dsa", "rsa" (default))
-g key-size Key size in bits, (min 512, max 2048, default 1024)
-y exp Set the public exponent value (3, 17, 65537) (rsa only)
-f password-file Specify the password file
-z noisefile Specify the noise file to be used
-q pqgfile read PQG value from pqgfile (dsa only)
-d keydir Key database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix

-D Delete a certificate from the database
-n cert-name The nickname of the cert to delete
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix

-U List all modules
-d moddir Module database directory (default is '~/.netscape')
-P dbprefix Cert & Key database prefix
-X force the database to open R/W

-K List all keys
-h token-name Name of token in which to look for keys (default is internal, use "all" to list keys on all tokens)
-k key-type Type of key pair to list ("all", "dsa", "rsa" (default))
-f password-file Specify the password file
-d keydir Key database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-X force the database to open R/W

-L List all certs, or print out a single named cert
-n cert-name Pretty print named cert (list all if unspecified)
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-X force the database to open R/W
-r For single cert, print binary DER encoding
-a For single cert, print ASCII encoding (RFC1113)

-M Modify trust attributes of certificate
-n cert-name The nickname of the cert to modify
-t trustargs Set the certificate trust attributes (see -A above)
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix

-N Create a new certificate database
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix

-T Reset the Key database or token
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-h token-name Token to reset (default is internal)


-O Print the chain of a certificate
-n cert-name The nickname of the cert to modify
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-X force the database to open R/W

-R Generate a certificate request (stdout)
-s subject Specify the subject name (using RFC1485)
-o output-req Output the cert request to this file
-k key-type Type of key pair to generate ("dsa", "rsa" (default))
-h token-name Name of token in which to generate key (default is internal)
-g key-size Key size in bits, RSA keys only (min 512, max 2048, default 1024)
-q pqgfile Name of file containing PQG parameters (dsa only)
-f pwfile Specify the password file
-d keydir Key database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-p phone Specify the contact phone number ("123-456-7890")
-a Output the cert request in ASCII (RFC1113); default is binary

-V Validate a certificate
-n cert-name The nickname of the cert to Validate
-b time validity time ("YYMMDDHHMMSS[+HHMM|-HHMM|Z]")
-e Check certificate signature
-u certusage Specify certificate usage:
C SSL Client
V SSL Server
S Email signer
R Email Recipient
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-X force the database to open R/W

-S Make a certificate and add to database
-n key-name Specify the nickname of the cert
-s subject Specify the subject name (using RFC1485)
-c issuer-name The nickname of the issuer cert
-t trustargs Set the certificate trust attributes (see -A above)
-k key-type Type of key pair to generate ("dsa", "rsa" (default))
-h token-name Name of token in which to generate key (default is internal)
-g key-size Key size in bits, RSA keys only (min 512, max 2048, default 1024)
-q pqgfile Name of file containing PQG parameters (dsa only)
-x Self sign
-m serial-number Cert serial number
-w warp-months Time Warp
-v months-valid Months valid (default is 3)
-f pwfile Specify the password file
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-p phone Specify the contact phone number ("123-456-7890")
-1 Create key usage extension
-2 Create basic constraint extension
-3 Create authority key ID extension
-4 Create crl distribution point extension
-5 Create netscape cert type extension
-6 Create extended key usage extension
-7 Create an email subject alt name extension
-8 Create an dns subject alt name extension

方法2:用GitHub脚本更新cert8.db

使用https://github.com/christian-korneck/firefox_add-certs (The release download includes a build of the NSS certutil.exe.)

方法3:启用security.enterprise_roots.enabled

适用于Firefox49版本及以上

https://support.mozilla.org/en-US/kb/setting-certificate-authorities-firefox

https://community.fortinet.com/t5/FortiGate/Technical-Note-Differences-between-SSL-Certificate-Inspection/ta-p/192301

手动启用

替换firefox configuration

https://support.umbrella.com/hc/en-us/articles/115000669728-Configuring-Firefox-to-use-the-Windows-Certificate-Store

https://docs.trendmicro.com/all/ent/ddwi/2.5/en-us/ddwi_2.5_olh/Deploy-the-Default-C_001.html

cfg配置文件启用

创建ddwi.cfg,内容如下。复制到文件夹:

C:\Program Files\Mozilla Firefox\ddwi.cfg

C:\Program Files (x86)\Mozilla Firefox\ddwi.cfg

1
2
   //
lockPref("security.enterprise_roots.enabled", true);

创建local-settings.js,内容如下。复制到文件夹:

C:\Program Files\Mozilla Firefox\defaults\pref\local-settings.js

C:\Program Files (x86)\Mozilla Firefox\defaults\pref\local-settings.js

1
2
pref("general.config.obscure_value", 0);
pref("general.config.filename", "ddwi.cfg");

注意,通过上述启用此选项后,会出现过几分钟又变成false的现象,过一会儿又自动变成True,没查到为什么会有这种现象,暂未解决。所以建议手动更改此配置选项。或使用下面的另一种方法:修改user.js配置文件。

user.js配置文件启用

参考:http://www.360doc.com/content/19/1031/22/73478_870350348.shtml

https://kb.mozillazine.org/User.js_file

pic

FireFox搜索框输入about:profiles,找到配置文件路径,一般情况下有两个配置文件目录。在如下路径:

1
%APPDATA%\Mozilla\Firefox\Profiles

创建user.js文件,复制到此配置文件目录下。

1
user_pref("security.enterprise_roots.enabled", true);

重启浏览器,发现此选项已经变成True

pic

安装脚本

准备好证书文件,各种配置文件,以及用NSS库构建的certutil.exe文件和安装脚本。全部放到C盘根目录下的firefoxinstallcert文件夹。

建议使用脚本2

脚本1

通过cfg配置文件lockPref启用security.enterprise_roots.enabled。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@echo off
::开启变量延迟扩展
setlocal EnableExtensions EnableDelayedExpansion

echo ###checking new_version###
echo --------------------------
set regPath1="HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox"
set regPath2="HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Mozilla\Mozilla Firefox"
set regKey="CurrentVersion"
set regValue=""

set Value1="checkversion"

rem 检查新版本注册表是否存在
reg query %regPath1% >nul 2>nul
echo %errorlevel%
echo !errorlevel!
if %errorlevel%==0 (
echo new_version Registry key %regkey% exists.
for /f "tokens=2*" %%a in ('reg query %regPath1% /v %regKey% ^| findstr /i %regKey%') do (
if "%regValue%"=="" (
echo value not exists
) else (
set Value1=%%b
)
)
) else (
echo new_version Registry key %regkey% does not exist.
echo --------------------------
::检查旧版本注册表路径是否存在
echo ###checking old_version###
reg query %regPath2% >nul 2>nul
if !errorlevel!==0 (
echo old_version Registry key %regkey% exists.
for /f "tokens=2*" %%a in ('reg query %regPath2% /v %regKey% ^| findstr /i %regKey%') do (
if "%regValue%"=="" (
echo value not exists
) else (
set Value1=%%b
)
)
) else (
echo old_version Registry key %regkey% does not exist.
set Value1=0.0.0
)

echo !Value1!
echo %Value1%

set "Major=%Value1:.=" & set /A "Minor=Revision, Revision=Subrev, Subrev=%"
echo Majorold: %Major%
)

echo !Value1!
echo %Value1%

set "Major=%Value1:.=" & set /A "Minor=Revision, Revision=Subrev, Subrev=%"
echo Majornew: %Major%

::显示最终版本,若为0,则表示未安装Firefox
echo --------------------------
set final_version= %Major%
echo final_version %final_version%
echo --------------------------

rem 检查版本号
if %final_version% EQU 0 (
echo Program version is 0. Exiting script...
exit /b 1
) else if %Major% LSS 49 (
call :function1
) else (
call :function2
)

rem 退出脚本
exit /b

::
:function1
echo Program version is less than 49. Executing function 1...
rem 执行函数1的代码,在49版本以下,更新cert8.db证书库。

::显示db中的现有证书
set "db_path=%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\"
set default_name=""
::判断证书数据库路径是否存在
IF EXIST %db_path% (
echo default_path exists
rem 在这里添加需要执行的命令
set "count=0"
for /d %%i in ("%db_path%\*") do (
set /a count+=1
set "folder=%%~nxi"
)
::判断是否只有*.default这一个文件夹
if !count! equ 1 (
set default_name=!folder!
set "all_path=%db_path%!default_name!"
::显示default文件夹全路径
echo !all_path!
::显示更新前证书库
C:\firefoxinstallcert\nss-3.11\bin\certutil.exe -L -d !all_path!
::更新证书库
C:\firefoxinstallcert\nss-3.11\bin\certutil.exe -A -n "SomeNametest" -t "u,u,u" -i "C:\firefoxinstallcert\TPLINKCA.cer" -d !all_path!
::显示更新后的证书库
C:\firefoxinstallcert\nss-3.11\bin\certutil.exe -L -d !all_path!
) else (
echo no or more
)
) ELSE (
echo no
)


goto :eof


:function2
echo Program version is greater than or equal to 49. Executing function 2...
rem 执行函数2的代码,在49版本以上的FireFox中启用security.enterprise_roots.enabled

set source_file_cfg=C:\firefoxinstallcert\ddwi.cfg
set "dest_dir_cfg=C:\Program Files\Mozilla Firefox\"
echo Moving %source_file_cfg% to %dest_dir_cfg%...
if exist "%source_file_cfg%" (
if exist "%dest_dir_cfg%" (
copy "%source_file_cfg%" "%dest_dir_cfg%"
) else (
echo Directory %dest_dir_cfg% does not exist! Cannot move file.
)
) else (
echo Source file %source_file_cfg% does not exist! Cannot move file.
)

set "dest_dir_cfg_x86=C:\Program Files (x86)\Mozilla Firefox\"
echo Moving %source_file_cfg% to %dest_dir_cfg_x86%...
if exist "%source_file_cfg%" (
if exist "%dest_dir_cfg_x86%" (
copy "%source_file_cfg%" "%dest_dir_cfg_x86%"
) else (
echo Directory does not exist! Cannot move file.
)
) else (
echo Source file %source_file_cfg% does not exist! Cannot move file.
)


set source_file_js=C:\firefoxinstallcert\local-settings.js
set "dest_dir_js=C:\Program Files\Mozilla Firefox\defaults\pref\"
echo Moving %source_file_js% to %dest_dir_js%...
if exist "%source_file_js%" (
if exist "%dest_dir_js%" (
copy "%source_file_js%" "%dest_dir_js%"
) else (
echo Directory does not exist! Cannot move file.
)
) else (
echo Source file %source_file_js% does not exist! Cannot move file.
)
set "dest_dir_js_x86=C:\Program Files (x86)\Mozilla Firefox\defaults\pref\"
echo Moving %source_file_js% to %dest_dir_js_x86%...
if exist "%source_file_js%" (
if exist "%dest_dir_js_x86%" (
copy "%source_file_js%" "%dest_dir_js_x86%"
) else (
echo Directory does not exist! Cannot move file.
)
) else (
echo Source file %source_file_js% does not exist! Cannot move file.
)

goto :eof

pause

脚本2

通过user.js启用security.enterprise_roots.enabled。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@echo off
::开启变量延迟扩展
setlocal EnableExtensions EnableDelayedExpansion

echo ###checking new_version###
echo --------------------------
set regPath1="HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox"
set regPath2="HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Mozilla\Mozilla Firefox"
set regKey="CurrentVersion"
set regValue=""

set Value1="checkversion"

rem 检查新版本注册表是否存在
reg query %regPath1% >nul 2>nul
echo %errorlevel%
echo !errorlevel!
if %errorlevel%==0 (
echo new_version Registry key %regkey% exists.
for /f "tokens=2*" %%a in ('reg query %regPath1% /v %regKey% ^| findstr /i %regKey%') do (
if "%regValue%"=="" (
echo value not exists
) else (
set Value1=%%b
)
)
) else (
echo new_version Registry key %regkey% does not exist.
echo --------------------------
::检查旧版本注册表路径是否存在
echo ###checking old_version###
reg query %regPath2% >nul 2>nul
if !errorlevel!==0 (
echo old_version Registry key %regkey% exists.
for /f "tokens=2*" %%a in ('reg query %regPath2% /v %regKey% ^| findstr /i %regKey%') do (
if "%regValue%"=="" (
echo value not exists
) else (
set Value1=%%b
)
)
) else (
echo old_version Registry key %regkey% does not exist.
set Value1=0.0.0
)

echo !Value1!
echo %Value1%

set "Major=%Value1:.=" & set /A "Minor=Revision, Revision=Subrev, Subrev=%"
echo Majorold: %Major%
)

echo !Value1!
echo %Value1%

set "Major=%Value1:.=" & set /A "Minor=Revision, Revision=Subrev, Subrev=%"
echo Majornew: %Major%

::显示最终版本,若为0,则表示未安装Firefox
echo --------------------------
set final_version= %Major%
echo final_version %final_version%
echo --------------------------

rem 检查版本号
if %final_version% EQU 0 (
echo Program version is 0. Exiting script...
exit /b 1
) else if %Major% LSS 49 (
call :function1
) else (
call :function2
)

rem 退出脚本
exit /b

::
:function1
echo Program version is less than 49. Executing function 1...
rem 执行函数1的代码,在49版本以下,更新cert8.db证书库。

::显示db中的现有证书
set "db_path=%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\"
set default_name=""
::判断证书数据库路径是否存在
IF EXIST %db_path% (
echo default_path exists
rem 在这里添加需要执行的命令
set "count=0"
for /d %%i in ("%db_path%\*") do (
set /a count+=1
set "folder=%%~nxi"
)
::判断是否只有*.default这一个文件夹
if !count! equ 1 (
set default_name=!folder!
set "all_path=%db_path%!default_name!"
::显示default文件夹全路径
echo !all_path!
::显示更新前证书库
C:\firefoxinstallcert\nss-3.11\bin\certutil.exe -L -d !all_path!
::更新证书库
C:\firefoxinstallcert\nss-3.11\bin\certutil.exe -A -n "SomeNametest" -t "u,u,u" -i "C:\firefoxinstallcert\TPLINKCA.cer" -d !all_path!
::显示更新后的证书库
C:\firefoxinstallcert\nss-3.11\bin\certutil.exe -L -d !all_path!
) else (
echo no or more
)
) ELSE (
echo no
)

goto :eof

:function2
echo Program version is greater than or equal to 49. Executing function 2...
rem 执行函数2的代码,在49版本以上的FireFox中通过增加user.js配置文件启用security.enterprise_roots.enabled

::profiles默认配置文件目录
set "parentFolder=%APPDATA%\Mozilla\Firefox\Profiles"
::搜索存在default字符串的文件夹,即profiles配置文件夹
set "searchString=default"
set source_user_js=C:\firefoxinstallcert\user.js
::将user.js文件拷贝到配置文件目录

IF EXIST %parentFolder% (
for /d %%F in ("%parentFolder%\*") do (
echo "%%~nxF" | findstr /C:"%searchString%" >nul 2>&1
if errorlevel 1 (
echo default Folder not found.
) else (
echo default Folder found.
rem 拼接全路径
set "all_default_path=%parentFolder%\%%~nxF"
echo !all_default_path!
copy "%source_user_js%" !all_default_path!
)
)
) ELSE (
echo no
)
goto :eof
pause

其他参考资料

http://www.certificate.fyicenter.com/389_Download_Mozilla_certutil_Tool_for_Windows_7.html

https://dev-tech-crypto.mozilla.narkive.com/QtN6vuxG/availability-of-certutil-on-windows

https://brpoblog.wordpress.com/2015/10/02/add-certificates-to-firefox-installation-with-certutil/