How to get a https certificate in chrome?

Talk about add-ons and extension development.
Post Reply
User avatar
PostaL2600
Posts: 20
Joined: December 8th, 2006, 2:25 am

How to get a https certificate in chrome?

Post by PostaL2600 »

I'm working on this extension that must to something like:

When a specific redirect is detected in the headers, read the certificate of that site and stop loading it (and later on send some certificate information in some other place).

All works well, except I can't read the certificate before the page is loaded. I use the fallowing code, which I traced out from the chrome:

Code: Select all

      var ui = gBrowser.securityUI;
      sp = ui.QueryInterface(Components.interfaces.nsISSLStatusProvider);
      status = sp.SSLStatus;
      status = status.QueryInterface(Components.interfaces.nsISSLStatus);
      var cert = status.serverCert;
      alert(cert.sha1Fingerprint);


This works perfectly if the page is currently loaded in the browser, but I need to do this before the page is loaded, cause I'm stopping it. I have also some other piece of code I've traced on the chrome, but something is just not right there (and I don't understand a big part of it):

Code: Select all

        var params = Components.classes["@mozilla.org/embedcomp/dialogparam;1"].createInstance(Components.interfaces.nsIDialogParamBlock);
        pkiParams    = params.QueryInterface(Components.interfaces.nsIPKIParamBlock);
        var isupport = pkiParams.getISupportAtIndex(1);
        cert = isupport.QueryInterface(Components.interfaces.nsIX509Cert);
        alert(cert.sha1Fingerprint);



The last part is not working at all, but I know that something like this I should do for my ext to work (this is from when the browser displays the unknown issuer of an certificate, and I noticed that this is done in the C++ code (nsNSSDialogs::ConfirmUnknownIssuer).

Can anyone help me make the last piece of code work (I don't manage to get right that "params" attribute (i noticed that is passed as a variable "block" in the C++ code on the openDialog method)), or can give me another pice of code wich will do the trick?
User avatar
Daifne
Moderator
Posts: 123071
Joined: July 31st, 2005, 9:17 pm
Location: Where the Waters Meet, Wisconsin

Post by Daifne »

Moving to Extension Development.
User avatar
PostaL2600
Posts: 20
Joined: December 8th, 2006, 2:25 am

Post by PostaL2600 »

Daifne wrote:Moving to Extension Development.


Sorry, new around here.. didn't know about this section :)
Post Reply