From 75a787ff2a26a01276b5426f626cd6847532fac2 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Thu, 23 May 2013 17:52:05 +0200 Subject: [PATCH] Bug 855543 - Opening app content that generates a certificate error results in the 'app not loading properly' modal dialog on top of the cert error handling page, making it impossible to provide a cert exception to the web content. r=jlebar --- .../BrowserElementChildPreload.js | 64 +++++++++++++++++++ .../mochitest/browserElement_ErrorSecurity.js | 42 ++++++++++-- 2 files changed, 101 insertions(+), 5 deletions(-) diff --git a/dom/browser-element/BrowserElementChildPreload.js b/dom/browser-element/BrowserElementChildPreload.js index 443bcc8b1b35..eace72965035 100644 --- a/dom/browser-element/BrowserElementChildPreload.js +++ b/dom/browser-element/BrowserElementChildPreload.js @@ -41,6 +41,52 @@ function sendAsyncMsg(msg, data) { sendAsyncMessage('browser-element-api:call', data); } +let CERTIFICATE_ERROR_PAGE_PREF = 'security.alternate_certificate_error_page'; + +let NS_ERROR_MODULE_BASE_OFFSET = 0x45; +let NS_ERROR_MODULE_SECURITY= 21; +function NS_ERROR_GET_MODULE(err) { + return ((((err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff) +} + +function NS_ERROR_GET_CODE(err) { + return ((err) & 0xffff); +} + +let SEC_ERROR_BASE = Ci.nsINSSErrorsService.NSS_SEC_ERROR_BASE; +let SEC_ERROR_UNKNOWN_ISSUER = (SEC_ERROR_BASE + 13); +let SEC_ERROR_CA_CERT_INVALID = (SEC_ERROR_BASE + 36); +let SEC_ERROR_UNTRUSTED_ISSUER = (SEC_ERROR_BASE + 20); +let SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE = (SEC_ERROR_BASE + 30); +let SEC_ERROR_UNTRUSTED_CERT = (SEC_ERROR_BASE + 21); +let SEC_ERROR_INADEQUATE_KEY_USAGE = (SEC_ERROR_BASE + 90); +let SEC_ERROR_EXPIRED_CERTIFICATE = (SEC_ERROR_BASE + 11); +let SEC_ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED = (SEC_ERROR_BASE + 176); + +let SSL_ERROR_BASE = Ci.nsINSSErrorsService.NSS_SSL_ERROR_BASE; +let SSL_ERROR_BAD_CERT_DOMAIN = (SSL_ERROR_BASE + 12); + +function getErrorClass(errorCode) { + let NSPRCode = -1 * NS_ERROR_GET_CODE(errorCode); + + switch (NSPRCode) { + case SEC_ERROR_UNKNOWN_ISSUER: + case SEC_ERROR_CA_CERT_INVALID: + case SEC_ERROR_UNTRUSTED_ISSUER: + case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE: + case SEC_ERROR_UNTRUSTED_CERT: + case SEC_ERROR_INADEQUATE_KEY_USAGE: + case SSL_ERROR_BAD_CERT_DOMAIN: + case SEC_ERROR_EXPIRED_CERTIFICATE: + case SEC_ERROR_CERT_SIGNATURE_ALGORITHM_DISABLED: + return Ci.nsINSSErrorsService.ERROR_CLASS_BAD_CERT; + default: + return Ci.nsINSSErrorsService.ERROR_CLASS_SSL_PROTOCOL; + } + + return null; +} + /** * The BrowserElementChild implements one half of