2012-05-16 101 views
0

我试图开发一个调用nsIX509CertDB.nsIX509CertDB的FF扩展。当从xpcshell调用此函数时,我收到错误0x80004005(NS_ERROR_FAILURE)。我怀疑它是失败的,因为在xpcshell环境中,我不能提示输入密码。有没有什么办法从命令行提供它?从命令行调用nsIX509CertDB.nsIX509CertDB失败

我的代码:

if(nsIFile != null && nsIFile.exists()) { 
     var certDB = Cc["@mozilla.org/security/x509certdb;1"] 
             .getService(Ci.nsIX509CertDB); 
     certDB.importPKCS12File(null, nsIFile); 
} 
+1

我猜等效的NSS命令行工具不会这样做吗? –

回答

1

这将最有可能涉及编写代码来替换@mozilla.org/nsCertificateDialogs;1组件(实施nsICertificateDialogs interface)。然后,您可以采用任何您喜欢的方式实施getPKCS12FilePassword方法。

更简单的方法是使用NSS中包含的pk12util tool。除非这个真的当然需要通过xpcshell完成。

+0

这是一个Firefox插件的单元测试。所以我真的很想在那里....感谢您的回答迄今!我尝试覆盖nsICertificateDialogs。你能否给我提示如何注册我的实施? –

+0

您可以使用[nsIComponentRegistrar.registerFactory()](https://developer.mozilla.org/en/nsIComponentRegistrar)(使用'Components.manager.nsIComponentRegistrar'获取服务)。您需要首先取消注册旧工厂(使用'nsIComponentRegistrar.unregisterFactory') - 因为您需要现有实现的CID(使用'nsIComponentRegistrar.contractIDToCID')及其工厂(使用['Components.manager.getClassObject( ...,Components.interfaces.nsIFactory)'](https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIComponentManager#getClassObjectByContractID%28%29)。 –

+0

这似乎并不适用于我,请参阅:http: //stackoverflow.com/questions/11988107/replace-nsicertificatedialogs-from-firefox-extension –