Bug 1267229 - Handle wrong system time when kinto clock skew is not available. r=MattN

MozReview-Commit-ID: Ko2Rq6PLfoX

--HG--
extra : rebase_source : 80df8fe6dafe6fb7ed4e363364ce5e5282b37b0c
This commit is contained in:
Heejong Ahn 2016-04-28 22:43:56 +02:00
Родитель e489d92457
Коммит f6c730db1e
5 изменённых файлов: 71 добавлений и 20 удалений

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

@ -598,6 +598,10 @@
&certerror.wrongSystemTime;
</div>
<div id="wrongSystemTimeWithoutReferencePanel" style="display: none;">
&certerror.wrongSystemTimeWithoutReference;
</div>
<!-- Long Description (Note: See netError.dtd for used XHTML tags) -->
<div id="errorLongDesc" />

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

@ -305,8 +305,8 @@ var AboutNetAndCertErrorListener = {
learnMoreLink.href = baseURL + "security-error";
break;
// in case the certificate expired we make sure the system clock
// matches settings server (kinto) time
// In case the certificate expired we make sure the system clock
// matches the blocklist ping (Kinto) time and is not before the build date.
case SEC_ERROR_EXPIRED_CERTIFICATE:
case SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE:
case SEC_ERROR_OCSP_FUTURE_RESPONSE:
@ -314,27 +314,55 @@ var AboutNetAndCertErrorListener = {
case MOZILLA_PKIX_ERROR_NOT_YET_VALID_CERTIFICATE:
case MOZILLA_PKIX_ERROR_NOT_YET_VALID_ISSUER_CERTIFICATE:
// use blocklist stats if available
// 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)) {
let difference = Services.prefs.getIntPref(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS);
difference = Services.prefs.getIntPref(PREF_BLOCKLIST_CLOCK_SKEW_SECONDS);
}
// if the difference is more than a day
if (Math.abs(difference) > 60 * 60 * 24) {
// If the difference is more than a day.
if (Math.abs(difference) > 60 * 60 * 24) {
let formatter = new Intl.DateTimeFormat();
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));
content.document.getElementById("wrongSystemTime_URL")
.textContent = content.document.location.hostname;
content.document.getElementById("wrongSystemTime_systemDate")
.textContent = systemDate;
content.document.getElementById("wrongSystemTime_actualDate")
.textContent = actualDate;
content.document.getElementById("errorShortDesc")
.style.display = "none";
content.document.getElementById("wrongSystemTimePanel")
.style.display = "block";
// If there is no clock skew with Kinto servers, check against the build date.
// (The Kinto ping could have happened when the time was still right, or not at all)
} else {
let appBuildID = Services.appinfo.appBuildID;
let year = parseInt(appBuildID.substr(0, 4), 10);
let month = parseInt(appBuildID.substr(4, 2), 10) - 1;
let day = parseInt(appBuildID.substr(6, 2), 10);
let buildDate = new Date(year, month, day);
let systemDate = new Date();
if (buildDate > systemDate) {
let formatter = new Intl.DateTimeFormat();
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));
content.document.getElementById("wrongSystemTime_URL")
content.document.getElementById("wrongSystemTimeWithoutReference_URL")
.textContent = content.document.location.hostname;
content.document.getElementById("wrongSystemTime_systemDate")
.textContent = systemDate;
content.document.getElementById("wrongSystemTime_actualDate")
.textContent = actualDate;
content.document.getElementById("wrongSystemTimeWithoutReference_systemDate")
.textContent = formatter.format(systemDate);
content.document.getElementById("errorShortDesc")
.style.display = "none";
content.document.getElementById("wrongSystemTimePanel")
content.document.getElementById("wrongSystemTimeWithoutReferencePanel")
.style.display = "block";
}
}

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

@ -105,6 +105,19 @@ add_task(function* checkBadStsCert() {
yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
// This checks that the appinfo.appBuildID starts with a date string,
// which is required for the misconfigured system time check.
add_task(function* checkAppBuildIDIsDate() {
let appBuildID = Services.appinfo.appBuildID;
let year = parseInt(appBuildID.substr(0, 4), 10);
let month = parseInt(appBuildID.substr(4, 2), 10);
let day = parseInt(appBuildID.substr(6, 2), 10);
ok(year >= 2016 && year <= 2100, "appBuildID contains a valid year");
ok(month >= 1 && month <= 12, "appBuildID contains a valid month");
ok(day >= 1 && day <= 31, "appBuildID contains a valid day");
});
const PREF_BLOCKLIST_CLOCK_SKEW_SECONDS = "services.blocklist.clock_skew_seconds";
add_task(function* checkWrongSystemTimeWarning() {
@ -151,7 +164,7 @@ add_task(function* checkWrongSystemTimeWarning() {
let message = yield Task.spawn(setUpPage);
isnot(message.divDisplay, "none", "Wrong time message information is visible");
ok(message.text.includes("because your clock appears to show the wrong time"),
ok(message.text.includes("clock appears to show the wrong time"),
"Correct error message found");
ok(message.text.includes("expired.example.com"), "URL found in error message");
ok(message.systemDate.includes(localDateFmt), "correct local date displayed");
@ -172,7 +185,7 @@ add_task(function* checkWrongSystemTimeWarning() {
message = yield Task.spawn(setUpPage);
isnot(message.divDisplay, "none", "Wrong time message information is visible");
ok(message.text.includes("because your clock appears to show the wrong time"),
ok(message.text.includes("clock appears to show the wrong time"),
"Correct error message found");
ok(message.text.includes("expired.example.com"), "URL found in error message");
ok(message.systemDate.includes(localDateFmt), "correct local date displayed");

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

@ -32,6 +32,10 @@ let gWhitelist = [{
file: "netError.dtd",
key: "certerror.wrongSystemTime",
type: "single-quote"
}, {
file: "netError.dtd",
key: "certerror.wrongSystemTimeWithoutReference",
type: "single-quote"
}, {
file: "phishing-afterload-warning-message.dtd",
key: "safeb.blocked.malwarePage.shortDesc",

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

@ -197,9 +197,11 @@ was trying to connect. -->
<!ENTITY weakCryptoAdvanced.longDesc "<span class='hostname'></span> uses security technology that is outdated and vulnerable to attack. An attacker could easily reveal information which you thought to be safe.">
<!ENTITY weakCryptoAdvanced.override "(Not secure) Try loading <span class='hostname'></span> using outdated security">
<!-- LOCALIZATION NOTE (certerror.wrongSystemTime) - The <span id='..' /> tags will be injected with actual values,
please leave them unchanged. -->
<!ENTITY certerror.wrongSystemTime "<p>A secure connection to <span id='wrongSystemTime_URL'/> isnt possible because your clock appears to show the wrong time.</p> <p>Your computer thinks it is <span id='wrongSystemTime_systemDate'/>, when it should be <span id='wrongSystemTime_actualDate'/>. To fix this problem, change your date and time settings to match the correct time.</p>">
<!-- LOCALIZATION NOTE (certerror.wrongSystemTime,
certerror.wrongSystemTimeWithoutReference) - The <span id='..' />
tags will be injected with actual values, please leave them unchanged. -->
<!ENTITY certerror.wrongSystemTime "<p> &brandShortName; did not connect to <span id='wrongSystemTime_URL'/> because your computers clock appears to show the wrong time and this is preventing a secure connection.</p> <p>Your computer is set to <span id='wrongSystemTime_systemDate'/>, when it should be <span id='wrongSystemTime_actualDate'/>. To fix this problem, change your date and time settings to match the correct time.</p>">
<!ENTITY certerror.wrongSystemTimeWithoutReference "<p>&brandShortName; did not connect to <span id='wrongSystemTimeWithoutReference_URL'/> because your computers clock appears to show the wrong time and this is preventing a secure connection.</p> <p>Your computer is set to <span id='wrongSystemTimeWithoutReference_systemDate'/>. To fix this problem, change your date and time settings to match the correct time.</p>">
<!ENTITY certerror.pagetitle1 "Insecure Connection">
<!ENTITY certerror.whatShouldIDo.badStsCertExplanation "This site uses HTTP