我設法讓SunPKCS11
與Windows下的Firefox ESR 52.0一起使用,但我無法在MacOS中加載它。我已經嘗試了幾種不同的配置,並通過PKCS11
直接加載,但沒有任何工作,任何人都可以給我一些指針?MacOS的SunPKCS11提供商適用於Firefox
pkcs11.cfg配置如下:
name = FirefoxKeyStore
library = "/Applications/Firefox.app/Contents/MacOS/fixed-for-java-runtime/libsoftokn3.dylib"
attributes = compatibility
nssArgs = "configdir='/Users/helloworld/Library/Application Support/Firefox/Profiles/wasdwasd.default-1453211557245' certPrefix='' keyPrefix='' secmod='secmod.db' flags='readOnly' "
slot = 2
然後在Java中,我試圖加載它是這樣的:
FileInputStream fis = new FileInputStream("pkcs11.cfg");
Provider provider = new SunPKCS11(fis);
Security.addProvider(provider);
然而,這立即使我有以下錯誤:
sunpkcs11: Initializing PKCS#11 library /Applications/Firefox.app/Contents/MacOS/fixed-for-java-runtime/libsoftokn3.dylib
sunpkcs11: Multi-threaded initialization failed: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_DEVICE_ERROR
Exception in thread "main" java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:376)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:107)
您可能會問爲什麼我要加載奇怪文件夾中的.dylib
,這是beca使用我在MacOS中使用install_name_tool
將@executable_path
更改爲@loader_path
,以便獲得庫依賴性(因爲我試圖在Eclipse中而不是從Firefox本身運行它)。
我也嘗試使用這裏建議的解決方案:How to finalize SunPKCS11 Provider after it is initialized?,這是一個不行的...我得到同樣的錯誤。這裏提到
除了嘗試各種不同的配置設置:https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/PKCS11/Module_Specs#Softoken_Specific_Parameters
EDIT1
我試圖通過@FaithReaper提到的方法,但它仍然拋出了同樣的錯誤。我嘗試將槽值更改爲0
,1
或-1
,結果相同。看起來像加載下層PKCS11
對象時出現問題。
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_DEVICE_ERROR
at sun.security.pkcs11.wrapper.PKCS11.C_Initialize(Native Method)
at sun.security.pkcs11.wrapper.PKCS11$SynchronizedPKCS11.C_Initialize(PKCS11.java:1545)
at sun.security.pkcs11.wrapper.PKCS11.getInstance(PKCS11.java:157)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:330)
我不知道這是否會幫助,但我跑在Firefox的配置文件modutil
並傾倒這個信息:
modutil -dbdir "/Users/eto/Library/Application Support/Firefox/Profiles/ew2g332o.default-1453211557245" -rawlist
library= name="NSS Internal PKCS #11 Module"
parameters="configdir=/Users/eto/Library/Application Support/Firefox/Profiles/ew2g332o.default-1453211557245 certPrefix= keyPrefix= secmod=secmod.db flags=readOnly "
NSS="Flags=internal,critical trustOrder=75 cipherOrder=100 slotParams=(1={slotFlags=[RSA,DSA,DH,RC2,RC4,DES,RANDOM,SHA1,MD5,MD2,SSL,TLS,AES,Camellia,SEED,SHA256,SHA512] askpw=any timeout=30})"
Listing of PKCS #11 Modules
NSS Internal PKCS #11 Module uri: pkcs11:library-manufacturer=Mozilla%20Foundation;library-description=NSS%20Internal%20Crypto%20Services;library-version=3.33 slots: 2 slots attached status: loaded
slot: NSS Internal Cryptographic Services token: NSS Generic Crypto Services uri: pkcs11:token=NSS%20Generic%20Crypto%20Services;manufacturer=Mozilla%20Foundation;serial=0000000000000000;model=NSS%203
slot: NSS User Private Key and Certificate Services token: NSS Certificate DB uri: pkcs11:token=NSS%20Certificate%20DB;manufacturer=Mozilla%20Foundation;serial=0000000000000000;model=NSS%203
首先,感謝您的幫助。但問題似乎是在初始化'SunPKCS11'級別,它甚至在'insertProviderAt'或'addProvider'之前拋出'CKR_DEVICE_ERROR'。 ''CKR_DEVICE_ERROR'正在被'sun.security.pkcs11.wrapper.PKCS11.C_Initialize(Native Method)引發'見我在帖子中更新。 – codenamezero