0

I'm trying to develop a FF extension that calls nsIX509CertDB.nsIX509CertDB. When calling this function from a xpcshell I alwas receive a error 0x80004005 (NS_ERROR_FAILURE). I suspect it to be failing since in a xpcshell environment I can not be prompted for the password. Is there any way to provide it from the command line?

My code:

if(nsIFile != null && nsIFile.exists()) {
        var certDB = Cc["@mozilla.org/security/x509certdb;1"]
                                        .getService(Ci.nsIX509CertDB);
        certDB.importPKCS12File(null, nsIFile);
}
David Feurle
  • 2,687
  • 22
  • 38

1 Answers1

1

This would most likely involve writing code to replace @mozilla.org/nsCertificateDialogs;1 component (implementing nsICertificateDialogs interface). Then you could implement getPKCS12FilePassword method any way you like.

The simpler approach would be using pk12util tool included in NSS. Unless this really needs to be done via xpcshell of course.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • It's a unit test of a firefox plugin. So i really would like to have it in there.... Thanks for your answer so far! I try to override the nsICertificateDialogs. Could you give me any hints on how to register my implementation? – David Feurle May 16 '12 at 21:25
  • You would use [nsIComponentRegistrar.registerFactory()](https://developer.mozilla.org/en/nsIComponentRegistrar) (use `Components.manager.nsIComponentRegistrar` to get the service). You will need to unregister the old factory first (use `nsIComponentRegistrar.unregisterFactory`) - for that you will need the CID of the existing implementation (use `nsIComponentRegistrar.contractIDToCID`) and its factory (use [`Components.manager.getClassObject(..., Components.interfaces.nsIFactory)`](https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIComponentManager#getClassObjectByContractID%28%29). – Wladimir Palant May 17 '12 at 09:11
  • This does not seem to work for me, see: http://stackoverflow.com/questions/11988107/replace-nsicertificatedialogs-from-firefox-extension – David Feurle Aug 20 '12 at 06:35