我努力尝试的一些笔记....我认为它会帮助任何想要使用 NSS 的人。
我倾向于String
在 Java 代码中构造一个来了解错误发生在哪一行。我必须说它更好,因为 Eclipse 可以消除所有 String 构造错误。然后你注意要填写的值。
我使用这些代码:
String config = "xxxxxxx" +
"xxxxxxx" +
"xxxxxxx" +
"\n";
provider = new SunPKCS11(new ByteArrayInputStream(config.getBytes()));
Security.insertProviderAt(provider, 1);
提供者配置的所有标志:(来自http://j7a.ru/_config_8java_source.html,看起来像 openjdk 8 sun.security.pkcs11.Config.java
。)
name=xxxxxx //some text, " must be escaped with \
library=/location/of/your/.so/or/.dll/file //not compatible with NSS mode, must be quoted if contains space, and if quoted, " must be escaped
description=
slot= //not compatible with NSS mode
slotListIndex= //not compatible with NSS mode
enableMechanisms=
disableMechanisms=
attributes=
handleStartupErrors=
insertionCheckInterval=
showInfo=true/false
keyStoreCompatibilityMode=
explicitCancel=
omitInitialize=
allowSingleThreadedModules=
functionList=
nssUseSecmod=true/false //not campatible with 'library'
nssLibraryDirectory= //not campatible with 'library'
nssSecmodDirectory= //not campatible with 'library'
nssModule=some text //not campatible with 'library'
nssDbMode=readWrite, readOnly, noDb //not campatible with 'library'
nssNetscapeDbWorkaround=true/false //not campatible with 'library'
nssArgs="name1='value1' name2='value2' name3='value3' ... " //not compatible with NSS mode
nssUseSecmodTrust=true/false
示例nssArgs=
:(以空格分隔)
"nssArgs=\"configdir='" + NSS_JSS_Utils.getFireFoxProfilePath() + "' "
+ "certPrefix='' "
+ "keyPrefix='' "
+ "secmod='secmod.db' "
+ "flags='readOnly'\""
Java代码中的一些转义示例:
String config = "name=\"NSS Module\"\n" +
"......" +
"\n";
如果有空格,必须用 引用" "
。' '
无法使用。每一个都"
必须用\
.
现在,一些真实的例子。
通过 NSS 使用 Firefox 安全模块:
String config = "name=\"NSS Module\"\n"
+ "attributes=compatibility\n"
+ "showInfo=true\n"
+ "allowSingleThreadedModules=true\n"
+ "nssLibraryDirectory=" + NSS_JSS_Utils.NSS_LIB_DIR + "\n"
+ "nssUseSecmod=true\n"
+ "nssSecmodDirectory=" + NSS_JSS_Utils.getFireFoxProfilePath();
使用libsoftokn3.so
(我不知道它的用途,但我看到有人像这样使用它nssArgs
):
String config = "library=" + NSS_JSS_Utils.NSS_LIB_DIR + "/libsoftokn3.so" + "\n"
+ "name=\"Soft Token\"\n";
+ "slot=2\n"
+ "attributes=compatibility\n"
+ "allowSingleThreadedModules=true\n"
+ "showInfo=true\n"
+ "nssArgs=\"configdir='" + NSS_JSS_Utils.getFireFoxProfilePath() + "' "
+ "certPrefix='' "
+ "keyPrefix='' "
+ "secmod='secmod.db' "
+ "flags='readOnly'\""
+ "\n";
NSS_JSS_Utils.NSS_LIB_DIR
返回所有 NSS 库库所在的目录。有时它们是默认安装的(例如,在我的 RedHat 7.2 中),但有时您必须手动安装它们。
NSS_JSS_Utils.getFireFoxProfilePath()
返回您的 FireFox 配置文件所在的位置。如果您使用modutil
NSS/NSPR 附带的,您可以看到已安装的安全模块存储在secmod.db
此文件夹中。如果您找不到它们,您可能拿错了文件。
有关如何填充这些值的更多信息:
NSS PKCS#11 规范