user1179510
user1179510

Reputation: 1023

accesing a https site using firefox addon

I am using a self signed ssl certificate to set up a https site and using the request package to access the contents on this site. However the program seems to get stuck and it is not printing the contents of the site. Is there any way to overcome this issue.

Upvotes: 0

Views: 349

Answers (1)

Wladimir Palant
Wladimir Palant

Reputation: 57681

Warning: This should only be used for debugging. Automatically adding an override for a wrong SSL certificate compromises the entire connection - if you do that then you can just skip using SSL in the first place. When you release this extension for other people you should use a valid certificate.


You probably want to add a certificate override manually. That's something you would use nsICertOverrideService.rememberValidityOverride() for (chrome authority required). The only problem is getting the certificate that you want to add an override for. But trying to contact the server and calling nsIRecentBadCertsService.getRecentBadCert() then should do. Something like this:

var Request = require("request").Request;
var host = "example.com";
var port = "443";
Request({
  url: "https://" + host + ":" + port + "/foo",
  onComplete: function(response)
  {
    var status = null;
    try
    {
      status = response.status;
    } catch(e) {}

    if (!status)
    {
      // There was a connection error, probably a bad certificate
      var {Cc, Ci} = require("chrome");

      var badCerts = Cc["@mozilla.org/security/recentbadcerts;1"]
                       .getService(Ci.nsIRecentBadCertsService);
      var status = badCerts.getRecentBadCert(host + ":" + port);
      if (status)
      {
        var overrideService = Cc["@mozilla.org/security/certoverride;1"]
                                .getService(Ci.nsICertOverrideService);
        overrideService.rememberValidityOverride(host, port, status.serverCert,
                                Ci.nsICertOverrideService.ERROR_UNTRUSTED, false);

        // Override added, now you should re-do the request
        ...
      }
    }
  }
});

Note: This code hasn't been tested, in particular I'm not sure whether detecting connection errors will really work by checking response.status (my guess is that it should throw if there was a connection error but the documentation doesn't say anything).

Upvotes: 2

Related Questions