1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ssl/bad_clock_blocking_page.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/build_time.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "base/i18n/time_formatting.h"
#include "base/process/launch.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/interstitials/chrome_metrics_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_preferences_util.h"
#include "chrome/browser/ssl/ssl_error_classification.h"
#include "chrome/browser/ssl/ssl_error_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/google/core/browser/google_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/cert_store.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/interstitial_page_delegate.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/signed_certificate_timestamp_store.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/renderer_preferences.h"
#include "content/public/common/ssl_status.h"
#include "grit/browser_resources.h"
#include "grit/components_strings.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/intent_helper.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/common/url_constants.h"
#endif
#if defined(OS_WIN)
#include "base/base_paths_win.h"
#include "base/path_service.h"
#include "base/strings/string16.h"
#include "base/win/windows_version.h"
#endif
using base::ASCIIToUTF16;
using base::TimeTicks;
using content::InterstitialPage;
using content::InterstitialPageDelegate;
using content::NavigationController;
using content::NavigationEntry;
namespace {
const char kMetricsName[] = "bad_clock";
void LaunchDateAndTimeSettings() {
DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
// The code for each OS is completely separate, in order to avoid bugs like
// https://crbug.com/430877 .
#if defined(OS_ANDROID)
chrome::android::OpenDateAndTimeSettings();
#elif defined(OS_CHROMEOS)
std::string sub_page =
std::string(chrome::kSearchSubPage) + "#" +
l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME);
chrome::ShowSettingsSubPageForProfile(ProfileManager::GetActiveUserProfile(),
sub_page);
#elif defined(OS_IOS)
// iOS does not have a way to launch the date and time settings.
NOTREACHED();
#elif defined(OS_LINUX)
struct ClockCommand {
const char* pathname;
const char* argument;
};
static const ClockCommand kClockCommands[] = {
// Unity
{"/usr/bin/unity-control-center", "datetime"},
// GNOME
//
// NOTE: On old Ubuntu, naming control panels doesn't work, so it
// opens the overview. This will have to be good enough.
{"/usr/bin/gnome-control-center", "datetime"},
{"/usr/local/bin/gnome-control-center", "datetime"},
{"/opt/bin/gnome-control-center", "datetime"},
// KDE
{"/usr/bin/kcmshell4", "clock"},
{"/usr/local/bin/kcmshell4", "clock"},
{"/opt/bin/kcmshell4", "clock"},
};
base::CommandLine command(base::FilePath(""));
for (const ClockCommand& cmd : kClockCommands) {
base::FilePath pathname(cmd.pathname);
if (base::PathExists(pathname)) {
command.SetProgram(pathname);
command.AppendArg(cmd.argument);
break;
}
}
if (command.GetProgram().empty()) {
// Alas, there is nothing we can do.
return;
}
base::LaunchOptions options;
options.wait = false;
options.allow_new_privs = true;
base::LaunchProcess(command, options);
#elif defined(OS_MACOSX)
base::CommandLine command(base::FilePath("/usr/bin/open"));
command.AppendArg("/System/Library/PreferencePanes/DateAndTime.prefPane");
base::LaunchOptions options;
options.wait = false;
base::LaunchProcess(command, options);
#elif defined(OS_WIN)
base::FilePath path;
PathService::Get(base::DIR_SYSTEM, &path);
static const base::char16 kControlPanelExe[] = L"control.exe";
path = path.Append(base::string16(kControlPanelExe));
base::CommandLine command(path);
command.AppendArg(std::string("/name"));
command.AppendArg(std::string("Microsoft.DateAndTime"));
base::LaunchOptions options;
options.wait = false;
base::LaunchProcess(command, options);
#else
NOTREACHED();
#endif
// Don't add code here! (See the comment at the beginning of the function.)
}
} // namespace
// static
InterstitialPageDelegate::TypeID BadClockBlockingPage::kTypeForTesting =
&BadClockBlockingPage::kTypeForTesting;
// Note that we always create a navigation entry with SSL errors.
// No error happening loading a sub-resource triggers an interstitial so far.
// Creating an interstitial without showing (e.g. from chrome://interstitials)
// it leaks memory, so don't create it here.
BadClockBlockingPage::BadClockBlockingPage(
content::WebContents* web_contents,
int cert_error,
const net::SSLInfo& ssl_info,
const GURL& request_url,
const base::Time& time_triggered,
const base::Callback<void(bool)>& callback)
: SecurityInterstitialPage(web_contents, request_url),
callback_(callback),
cert_error_(cert_error),
ssl_info_(ssl_info),
time_triggered_(time_triggered) {
security_interstitials::MetricsHelper::ReportDetails reporting_info;
reporting_info.metric_prefix = kMetricsName;
set_metrics_helper(new ChromeMetricsHelper(web_contents, request_url,
reporting_info, kMetricsName));
metrics_helper()->RecordUserInteraction(
security_interstitials::MetricsHelper::TOTAL_VISITS);
// TODO(felt): Separate the clock statistics from the main ssl statistics.
scoped_ptr<SSLErrorClassification> classifier(
new SSLErrorClassification(web_contents, time_triggered_, request_url,
cert_error_, *ssl_info_.cert.get()));
classifier->RecordUMAStatistics(false);
}
bool BadClockBlockingPage::ShouldCreateNewNavigation() const {
return true;
}
InterstitialPageDelegate::TypeID BadClockBlockingPage::GetTypeForTesting()
const {
return BadClockBlockingPage::kTypeForTesting;
}
BadClockBlockingPage::~BadClockBlockingPage() {
if (!callback_.is_null()) {
// Deny when the page is closed.
NotifyDenyCertificate();
}
}
void BadClockBlockingPage::PopulateInterstitialStrings(
base::DictionaryValue* load_time_data) {
CHECK(load_time_data);
base::string16 url(GetFormattedHostName());
// Values that are currently still shared with the SSL interstitial.
load_time_data->SetString("type", "SSL");
load_time_data->SetString("errorCode", net::ErrorToString(cert_error_));
load_time_data->SetString(
"openDetails", l10n_util::GetStringUTF16(IDS_SSL_OPEN_DETAILS_BUTTON));
load_time_data->SetString(
"closeDetails",
l10n_util::GetStringUTF16(IDS_SSL_CLOSE_DETAILS_BUTTON));
// Strings for the bad clock warning specifically.
load_time_data->SetBoolean("bad_clock", true);
load_time_data->SetBoolean("overridable", false);
#if defined(OS_IOS)
load_time_data->SetBoolean("hide_primary_button", true);
#else
load_time_data->SetBoolean("hide_primary_button", false);
#endif
int heading_string =
SSLErrorClassification::IsUserClockInTheFuture(time_triggered_)
? IDS_CLOCK_ERROR_AHEAD_HEADING
: IDS_CLOCK_ERROR_BEHIND_HEADING;
load_time_data->SetString("tabTitle",
l10n_util::GetStringUTF16(IDS_CLOCK_ERROR_TITLE));
load_time_data->SetString("heading",
l10n_util::GetStringUTF16(heading_string));
load_time_data->SetString(
"primaryParagraph",
l10n_util::GetStringFUTF16(
IDS_CLOCK_ERROR_PRIMARY_PARAGRAPH, url,
base::TimeFormatFriendlyDateAndTime(time_triggered_)));
load_time_data->SetString(
"primaryButtonText",
l10n_util::GetStringUTF16(IDS_CLOCK_ERROR_UPDATE_DATE_AND_TIME));
load_time_data->SetString(
"explanationParagraph",
l10n_util::GetStringUTF16(IDS_CLOCK_ERROR_EXPLANATION));
// The interstitial template expects this string, but we're not using it.
load_time_data->SetString("finalParagraph", std::string());
// Set debugging information at the bottom of the warning.
load_time_data->SetString("subject",
ssl_info_.cert->subject().GetDisplayName());
load_time_data->SetString("issuer",
ssl_info_.cert->issuer().GetDisplayName());
load_time_data->SetString(
"expirationDate",
base::TimeFormatShortDate(ssl_info_.cert->valid_expiry()));
load_time_data->SetString("currentDate",
base::TimeFormatShortDate(time_triggered_));
std::vector<std::string> encoded_chain;
ssl_info_.cert->GetPEMEncodedChain(&encoded_chain);
load_time_data->SetString(
"pem", base::JoinString(encoded_chain, base::StringPiece()));
}
void BadClockBlockingPage::OverrideEntry(NavigationEntry* entry) {
const int process_id = web_contents()->GetRenderProcessHost()->GetID();
const int cert_id = content::CertStore::GetInstance()->StoreCert(
ssl_info_.cert.get(), process_id);
DCHECK(cert_id);
content::SignedCertificateTimestampStore* sct_store(
content::SignedCertificateTimestampStore::GetInstance());
content::SignedCertificateTimestampIDStatusList sct_ids;
for (const auto& sct_and_status : ssl_info_.signed_certificate_timestamps) {
const int sct_id(sct_store->Store(sct_and_status.sct.get(), process_id));
DCHECK(sct_id);
sct_ids.push_back(content::SignedCertificateTimestampIDAndStatus(
sct_id, sct_and_status.status));
}
entry->GetSSL() =
content::SSLStatus(content::SECURITY_STYLE_AUTHENTICATION_BROKEN, cert_id,
sct_ids, ssl_info_);
}
// This handles the commands sent from the interstitial JavaScript.
// DO NOT reorder or change this logic without also changing the JavaScript!
void BadClockBlockingPage::CommandReceived(const std::string& command) {
if (command == "\"pageLoadComplete\"") {
// content::WaitForRenderFrameReady sends this message when the page
// load completes. Ignore it.
return;
}
int cmd = 0;
bool retval = base::StringToInt(command, &cmd);
DCHECK(retval);
switch (cmd) {
case CMD_DONT_PROCEED:
interstitial_page()->DontProceed();
break;
case CMD_DO_REPORT:
SetReportingPreference(true);
break;
case CMD_DONT_REPORT:
SetReportingPreference(false);
break;
case CMD_SHOW_MORE_SECTION:
metrics_helper()->RecordUserInteraction(
security_interstitials::MetricsHelper::SHOW_ADVANCED);
break;
case CMD_OPEN_DATE_SETTINGS:
metrics_helper()->RecordUserInteraction(
security_interstitials::MetricsHelper::OPEN_TIME_SETTINGS);
content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
base::Bind(&LaunchDateAndTimeSettings));
break;
case CMD_OPEN_REPORTING_PRIVACY:
OpenExtendedReportingPrivacyPolicy();
break;
case CMD_PROCEED:
case CMD_OPEN_HELP_CENTER:
case CMD_RELOAD:
case CMD_OPEN_DIAGNOSTIC:
// Not supported for the bad clock interstitial.
NOTREACHED() << "Unexpected command: " << command;
}
}
void BadClockBlockingPage::OverrideRendererPrefs(
content::RendererPreferences* prefs) {
Profile* profile =
Profile::FromBrowserContext(web_contents()->GetBrowserContext());
renderer_preferences_util::UpdateFromSystemSettings(prefs, profile,
web_contents());
}
void BadClockBlockingPage::OnDontProceed() {
NotifyDenyCertificate();
}
void BadClockBlockingPage::NotifyDenyCertificate() {
// It's possible that callback_ may not exist if the user clicks "Proceed"
// followed by pressing the back button before the interstitial is hidden.
// In that case the certificate will still be treated as allowed.
if (callback_.is_null())
return;
base::ResetAndReturn(&callback_).Run(false);
}
|