私の努力からのメモ.... 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";
スペースがある場合は、で引用する必要があります" "
。' '
使用できません。every"
は でエスケープする必要があります\
。
さて、実際の例をいくつか。
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 ライブラリ libs があるディレクトリを返します。デフォルトでインストールされる場合もありますが (たとえば、私の RedHat 7.2 では)、手動でインストールする必要がある場合もあります。
NSS_JSS_Utils.getFireFoxProfilePath()
FireFox プロファイルの場所を返します。NSS/NSPR に同梱されているものを使用すると、インストールされたセキュリティ モジュールがこのフォルダにmodutil
格納されていることがわかります。secmod.db
それらが見つからない場合は、間違ったファイルを取得した可能性があります。
これらの値を埋める方法の詳細:
NSS PKCS#11 仕様