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
|
// Copyright (c) 2010 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/page_info_model.h"
#include <string>
#include "base/command_line.h"
#include "base/i18n/time_formatting.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ssl/ssl_error_info.h"
#include "chrome/browser/ssl/ssl_manager.h"
#include "content/browser/cert_store.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "net/base/cert_status_flags.h"
#include "net/base/ssl_connection_status_flags.h"
#include "net/base/ssl_cipher_suite_names.h"
#include "net/base/x509_certificate.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
PageInfoModel::PageInfoModel(Profile* profile,
const GURL& url,
const NavigationEntry::SSLStatus& ssl,
bool show_history,
PageInfoModelObserver* observer)
: observer_(observer) {
Init();
SectionStateIcon icon_id = ICON_STATE_OK;
string16 headline;
string16 description;
scoped_refptr<net::X509Certificate> cert;
// Identity section.
string16 subject_name(UTF8ToUTF16(url.host()));
bool empty_subject_name = false;
if (subject_name.empty()) {
subject_name.assign(
l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
empty_subject_name = true;
}
// Some of what IsCertStatusError classifies as errors we want to show as
// warnings instead.
static const int cert_warnings =
net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION |
net::CERT_STATUS_NO_REVOCATION_MECHANISM;
int status_with_warnings_removed = ssl.cert_status() & ~cert_warnings;
if (ssl.cert_id() &&
CertStore::GetInstance()->RetrieveCert(ssl.cert_id(), &cert) &&
!net::IsCertStatusError(status_with_warnings_removed)) {
// No error found so far, check cert_status warnings.
int cert_status = ssl.cert_status();
if (cert_status & cert_warnings) {
string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
if (issuer_name.empty()) {
issuer_name.assign(l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
}
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
description += ASCIIToUTF16("\n\n");
if (cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
description += l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
} else if (cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
description += l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
} else {
NOTREACHED() << "Need to specify string for this warning";
}
icon_id = ICON_STATE_WARNING_MINOR;
} else if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) != 0) {
// EV HTTPS page.
DCHECK(!cert->subject().organization_names.empty());
headline =
l10n_util::GetStringFUTF16(IDS_PAGE_INFO_EV_IDENTITY_TITLE,
UTF8ToUTF16(cert->subject().organization_names[0]),
UTF8ToUTF16(url.host()));
// An EV Cert is required to have a city (localityName) and country but
// state is "if any".
DCHECK(!cert->subject().locality_name.empty());
DCHECK(!cert->subject().country_name.empty());
string16 locality;
if (!cert->subject().state_or_province_name.empty()) {
locality = l10n_util::GetStringFUTF16(
IDS_PAGEINFO_ADDRESS,
UTF8ToUTF16(cert->subject().locality_name),
UTF8ToUTF16(cert->subject().state_or_province_name),
UTF8ToUTF16(cert->subject().country_name));
} else {
locality = l10n_util::GetStringFUTF16(
IDS_PAGEINFO_PARTIAL_ADDRESS,
UTF8ToUTF16(cert->subject().locality_name),
UTF8ToUTF16(cert->subject().country_name));
}
DCHECK(!cert->subject().organization_names.empty());
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
UTF8ToUTF16(cert->subject().organization_names[0]),
locality,
UTF8ToUTF16(cert->issuer().GetDisplayName())));
} else if ((ssl.cert_status() & net::CERT_STATUS_IS_DNSSEC) != 0) {
// DNSSEC authenticated page.
if (empty_subject_name)
headline.clear(); // Don't display any title.
else
headline.assign(subject_name);
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, UTF8ToUTF16("DNSSEC")));
} else {
// Non-EV OK HTTPS page.
if (empty_subject_name)
headline.clear(); // Don't display any title.
else
headline.assign(subject_name);
string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
if (issuer_name.empty()) {
issuer_name.assign(l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
}
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
}
} else {
// HTTP or HTTPS with errors (not warnings).
description.assign(l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
icon_id = ssl.security_style() == SECURITY_STYLE_UNAUTHENTICATED ?
ICON_STATE_WARNING_MAJOR : ICON_STATE_ERROR;
const string16 bullet = UTF8ToUTF16("\n • ");
std::vector<SSLErrorInfo> errors;
SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id(), ssl.cert_status(),
url, &errors);
for (size_t i = 0; i < errors.size(); ++i) {
description += bullet;
description += errors[i].short_description();
}
if (ssl.cert_status() & net::CERT_STATUS_NON_UNIQUE_NAME) {
description += ASCIIToUTF16("\n\n");
description += l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
}
}
sections_.push_back(SectionInfo(
icon_id,
headline,
description,
SECTION_INFO_IDENTITY));
// Connection section.
// We consider anything less than 80 bits encryption to be weak encryption.
// TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
// weakly encrypted connections.
icon_id = ICON_STATE_OK;
headline.clear();
description.clear();
if (!ssl.cert_id()) {
// Not HTTPS.
DCHECK_EQ(ssl.security_style(), SECURITY_STYLE_UNAUTHENTICATED);
icon_id = ssl.security_style() == SECURITY_STYLE_UNAUTHENTICATED ?
ICON_STATE_WARNING_MAJOR : ICON_STATE_ERROR;
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
subject_name));
} else if (ssl.security_bits() < 0) {
// Security strength is unknown. Say nothing.
icon_id = ICON_STATE_ERROR;
} else if (ssl.security_bits() == 0) {
DCHECK_NE(ssl.security_style(), SECURITY_STYLE_UNAUTHENTICATED);
icon_id = ICON_STATE_ERROR;
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
subject_name));
} else if (ssl.security_bits() < 80) {
icon_id = ICON_STATE_ERROR;
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
subject_name));
} else {
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
subject_name,
base::IntToString16(ssl.security_bits())));
if (ssl.displayed_insecure_content() || ssl.ran_insecure_content()) {
icon_id = ssl.ran_insecure_content() ?
ICON_STATE_ERROR : ICON_STATE_WARNING_MINOR;
description.assign(l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
description,
l10n_util::GetStringUTF16(ssl.ran_insecure_content() ?
IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
}
}
uint16 cipher_suite =
net::SSLConnectionStatusToCipherSuite(ssl.connection_status());
if (ssl.security_bits() > 0 && cipher_suite) {
int ssl_version =
net::SSLConnectionStatusToVersion(ssl.connection_status());
const char* ssl_version_str;
net::SSLVersionToString(&ssl_version_str, ssl_version);
description += ASCIIToUTF16("\n\n");
description += l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
ASCIIToUTF16(ssl_version_str));
bool did_fallback = (ssl.connection_status() &
net::SSL_CONNECTION_SSL3_FALLBACK) != 0;
bool no_renegotiation =
(ssl.connection_status() &
net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
const char *key_exchange, *cipher, *mac;
net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
description += ASCIIToUTF16("\n\n");
description += l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
description += ASCIIToUTF16("\n\n");
uint8 compression_id =
net::SSLConnectionStatusToCompression(ssl.connection_status());
if (compression_id) {
const char* compression;
net::SSLCompressionToString(&compression, compression_id);
description += l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS,
ASCIIToUTF16(compression));
} else {
description += l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION);
}
if (did_fallback) {
// For now, only SSLv3 fallback will trigger a warning icon.
if (icon_id < ICON_STATE_WARNING_MINOR)
icon_id = ICON_STATE_WARNING_MINOR;
description += ASCIIToUTF16("\n\n");
description += l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
}
if (no_renegotiation) {
description += ASCIIToUTF16("\n\n");
description += l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
}
}
if (!description.empty()) {
sections_.push_back(SectionInfo(
icon_id,
headline,
description,
SECTION_INFO_CONNECTION));
}
// Request the number of visits.
HistoryService* history = profile->GetHistoryService(
Profile::EXPLICIT_ACCESS);
if (show_history && history) {
history->GetVisitCountToHost(
url,
&request_consumer_,
NewCallback(this, &PageInfoModel::OnGotVisitCountToHost));
}
}
PageInfoModel::~PageInfoModel() {}
int PageInfoModel::GetSectionCount() {
return sections_.size();
}
PageInfoModel::SectionInfo PageInfoModel::GetSectionInfo(int index) {
DCHECK(index < static_cast<int>(sections_.size()));
return sections_[index];
}
gfx::Image* PageInfoModel::GetIconImage(SectionStateIcon icon_id) {
if (icon_id == ICON_NONE)
return NULL;
// The bubble uses new, various icons.
return icons_[icon_id];
}
void PageInfoModel::OnGotVisitCountToHost(HistoryService::Handle handle,
bool found_visits,
int count,
base::Time first_visit) {
if (!found_visits) {
// This indicates an error, such as the page wasn't http/https; do nothing.
return;
}
bool visited_before_today = false;
if (count) {
base::Time today = base::Time::Now().LocalMidnight();
base::Time first_visit_midnight = first_visit.LocalMidnight();
visited_before_today = (first_visit_midnight < today);
}
string16 headline = l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_INFO_TITLE);
if (!visited_before_today) {
sections_.push_back(SectionInfo(
ICON_STATE_WARNING_MAJOR,
headline,
l10n_util::GetStringUTF16(
IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY),
SECTION_INFO_FIRST_VISIT));
} else {
sections_.push_back(SectionInfo(
ICON_STATE_INFO,
headline,
l10n_util::GetStringFUTF16(
IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
base::TimeFormatShortDate(first_visit)),
SECTION_INFO_FIRST_VISIT));
}
observer_->ModelChanged();
}
PageInfoModel::PageInfoModel() : observer_(NULL) {
Init();
}
void PageInfoModel::Init() {
// Loads the icons into the vector. The order must match the SectionStateIcon
// enum.
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_GOOD));
icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MINOR));
icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_WARNING_MAJOR));
icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_BAD));
icons_.push_back(&rb.GetNativeImageNamed(IDR_PAGEINFO_INFO));
}
|