1

我开始进入 NSS 并设法构建它。结果被放置在一个名为的文件夹dist中,并且有几个子文件夹,其中包含几个 exe 的 dll 等。

dist  
    /WINNT6.0_DBG.OBJ  
         /bin  
         /include  
         /lib   

我正在尝试尝试,但我不确定nssLibraryDirectoryand是什么nssSecmodDirectory

对于nssLibraryDirectory我应该将所有内容复制dist到一个文件中并从中引用它nssLibraryDirectory吗?怎么样nssSecmodDirectory?我不确定我应该如何配置以开始使用 sun 的 pkcs11。

例如这个微不足道的:

String configName = "nss.cfg";
Provider p = new sun.security.pkcs11.SunPKCS11(configName );

其中 nss.cfg 是:

 name = NSS  
 nssLibraryDirectory = E:\NSS\nss-3.12.4-with-nspr-4.8\mozilla\dist\WINNT6.0_DBG.OBJ\lib 
 nssDbMode = noDb  

给出异常

原因:java.io.IOException:找不到指定的模块。在 sun.security.pkcs11.Secmod.nssLoadLibrary(本机方法)

4

2 回答 2

0

nssLibraryDirectory 应该只包含 lib 子目录。它还必须出现在 PATH 中 - 通过修改环境变量或在 JVM 参数中指定它。

于 2011-11-15T08:00:37.193 回答
0

我努力尝试的一些笔记....我认为它会帮助任何想要使用 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 配置文件所在的位置。如果您使用modutilNSS/NSPR 附带的,您可以看到已安装的安全模块存储在secmod.db此文件夹中。如果您找不到它们,您可能拿错了文件。

有关如何填充这些值的更多信息:

NSS PKCS#11 规范

于 2016-11-10T08:35:05.220 回答