Bug 1339329 - cert error time warnings should only appear for recent blocklists and if clock skew is sufficient to make cert valid, r=johannh

MozReview-Commit-ID: 6HvOnc54edi

--HG--
extra : rebase_source : 3f718d045cc344eb72d65940df011f201ad1d0fb
This commit is contained in:
Gijs Kruitbosch 2017-03-28 11:35:27 +01:00
Родитель 2db78e3fcd
Коммит 06d549b62e
2 изменённых файлов: 37 добавлений и 10 удалений

Просмотреть файл

@ -85,6 +85,7 @@ const MOZILLA_PKIX_ERROR_NOT_YET_VALID_CERTIFICATE = MOZILLA_PKIX_ERROR_BASE + 5
const MOZILLA_PKIX_ERROR_NOT_YET_VALID_ISSUER_CERTIFICATE = MOZILLA_PKIX_ERROR_BASE + 6;
const PREF_BLOCKLIST_CLOCK_SKEW_SECONDS = "services.blocklist.clock_skew_seconds";
const PREF_BLOCKLIST_LAST_FETCHED = "services.blocklist.last_update_seconds";
const PREF_SSL_IMPACT_ROOTS = ["security.tls.version.", "security.ssl3."];
@ -262,6 +263,24 @@ var AboutNetAndCertErrorListener = {
}
},
_getCertValidityRange() {
let {securityInfo} = docShell.failedChannel;
securityInfo.QueryInterface(Ci.nsITransportSecurityInfo);
let certs = securityInfo.failedCertChain.getEnumerator();
let notBefore = 0;
let notAfter = Number.MAX_SAFE_INTEGER;
while (certs.hasMoreElements()) {
let cert = certs.getNext();
cert.QueryInterface(Ci.nsIX509Cert);
notBefore = Math.max(notBefore, cert.validity.notBefore);
notAfter = Math.min(notAfter, cert.validity.notAfter);
}
// nsIX509Cert reports in PR_Date terms, which uses microseconds. Convert:
notBefore /= 1000;
notAfter /= 1000;
return {notBefore, notAfter};
},
onCertErrorDetails(msg) {
let div = content.document.getElementById("certificateErrorText");
div.textContent = msg.data.info;
@ -284,26 +303,30 @@ var AboutNetAndCertErrorListener = {
// We check against Kinto time first if available, because that allows us
// to give the user an approximation of what the correct time is.
let difference = 0;
if (Services.prefs.getPrefType(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS)) {
difference = Services.prefs.getIntPref(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS);
}
let difference = Services.prefs.getIntPref(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS, 0);
let lastFetched = Services.prefs.getIntPref(PREF_BLOCKLIST_LAST_FETCHED, 0) * 1000;
// If the difference is more than a day.
if (Math.abs(difference) > 60 * 60 * 24) {
let now = Date.now();
let certRange = this._getCertValidityRange();
let approximateDate = now - difference * 1000;
// If the difference is more than a day, we last fetched the date in the last 5 days,
// and adjusting the date per the interval would make the cert valid, warn the user:
if (Math.abs(difference) > 60 * 60 * 24 && (now - lastFetched) <= 60 * 60 * 24 * 5 &&
certRange.notBefore < approximateDate && certRange.notAfter > approximateDate) {
let formatter = Services.intl.createDateTimeFormat(undefined, {
dateStyle: "short"
});
let systemDate = formatter.format(new Date());
// negative difference means local time is behind server time
let actualDate = formatter.format(new Date(Date.now() - difference * 1000));
approximateDate = formatter.format(new Date(approximateDate));
content.document.getElementById("wrongSystemTime_URL")
.textContent = content.document.location.hostname;
content.document.getElementById("wrongSystemTime_systemDate")
.textContent = systemDate;
content.document.getElementById("wrongSystemTime_actualDate")
.textContent = actualDate;
.textContent = approximateDate;
content.document.getElementById("errorShortDesc")
.style.display = "none";
@ -322,7 +345,11 @@ var AboutNetAndCertErrorListener = {
let buildDate = new Date(year, month, day);
let systemDate = new Date();
if (buildDate > systemDate) {
// We don't check the notBefore of the cert with the build date,
// as it is of course almost certain that it is now later than the build date,
// so we shouldn't exclude the possibility that the cert has become valid
// since the build date.
if (buildDate > systemDate && new Date(certRange.notAfter) > buildDate) {
let formatter = Services.intl.createDateTimeFormat(undefined, {
dateStyle: "short"
});

Просмотреть файл

@ -217,7 +217,7 @@ add_task(async function checkWrongSystemTimeWarning() {
is(message.divDisplay, "none", "Wrong time message information is not visible");
await BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
}).skip(); // Skipping because of bug 1414804.
add_task(async function checkAdvancedDetails() {
info("Loading a bad cert page and verifying the main error and advanced details section");