OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/gtk/certificate_viewer.h" | 5 #include "chrome/browser/gtk/certificate_viewer.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #include <hasht.h> | 9 #include <hasht.h> |
10 #include <sechash.h> | 10 #include <sechash.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 | 13 |
14 #include "app/l10n_util.h" | 14 #include "app/l10n_util.h" |
15 #include "base/i18n/time_formatting.h" | 15 #include "base/i18n/time_formatting.h" |
16 #include "base/nss_util.h" | 16 #include "base/nss_util.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/time.h" | 18 #include "base/time.h" |
19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
20 #include "chrome/browser/cert_store.h" | 20 #include "chrome/browser/cert_store.h" |
21 #include "chrome/browser/gtk/gtk_util.h" | 21 #include "chrome/browser/gtk/gtk_util.h" |
22 #include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h" | 22 #include "chrome/third_party/mozilla_security_manager/nsNSSCertHelper.h" |
23 #include "chrome/third_party/mozilla_security_manager/nsNSSCertificate.h" | 23 #include "chrome/third_party/mozilla_security_manager/nsNSSCertificate.h" |
| 24 #include "chrome/third_party/mozilla_security_manager/nsUsageArrayHelper.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 | 26 |
26 // PSM = Mozilla's Personal Security Manager. | 27 // PSM = Mozilla's Personal Security Manager. |
27 namespace psm = mozilla_security_manager; | 28 namespace psm = mozilla_security_manager; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 const char kDetailsFontFamily[] = "monospace"; | 32 const char kDetailsFontFamily[] = "monospace"; |
32 | 33 |
33 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 gtk_util::kContentAreaBorder); | 249 gtk_util::kContentAreaBorder); |
249 | 250 |
250 GtkWidget* uses_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | 251 GtkWidget* uses_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
251 gtk_box_pack_start(GTK_BOX(general_page_vbox_), uses_vbox, FALSE, FALSE, 0); | 252 gtk_box_pack_start(GTK_BOX(general_page_vbox_), uses_vbox, FALSE, FALSE, 0); |
252 gtk_box_pack_start( | 253 gtk_box_pack_start( |
253 GTK_BOX(uses_vbox), | 254 GTK_BOX(uses_vbox), |
254 gtk_util::CreateBoldLabel( | 255 gtk_util::CreateBoldLabel( |
255 l10n_util::GetStringUTF8(IDS_CERT_INFO_VERIFIED_USAGES_GROUP)), | 256 l10n_util::GetStringUTF8(IDS_CERT_INFO_VERIFIED_USAGES_GROUP)), |
256 FALSE, FALSE, 0); | 257 FALSE, FALSE, 0); |
257 | 258 |
258 SECCertificateUsage usages = 0; | 259 std::vector<std::string> usages; |
259 // TODO(wtc): See if we should use X509Certificate::Verify instead. | 260 psm::GetCertUsageStrings(cert, &usages); |
260 if (CERT_VerifyCertificateNow(CERT_GetDefaultCertDB(), cert, PR_TRUE, | 261 for (size_t i = 0; i < usages.size(); ++i) |
261 certificateUsageCheckAllUsages, | 262 gtk_box_pack_start( |
262 NULL, &usages) == SECSuccess) { | 263 GTK_BOX(uses_vbox), |
263 // List of usages to display is borrowed from | 264 gtk_util::IndentWidget(gtk_util::LeftAlignMisc(gtk_label_new( |
264 // mozilla/source/security/manager/ssl/src/nsUsageArrayHelper.cpp | 265 usages[i].c_str()))), |
265 static const struct { | 266 FALSE, FALSE, 0); |
266 SECCertificateUsage usage; | |
267 int string_id; | |
268 } usage_string_map[] = { | |
269 {certificateUsageSSLClient, IDS_CERT_USAGE_SSL_CLIENT}, | |
270 {certificateUsageSSLServer, IDS_CERT_USAGE_SSL_SERVER}, | |
271 {certificateUsageSSLServerWithStepUp, | |
272 IDS_CERT_USAGE_SSL_SERVER_WITH_STEPUP}, | |
273 {certificateUsageEmailSigner, IDS_CERT_USAGE_EMAIL_SIGNER}, | |
274 {certificateUsageEmailRecipient, IDS_CERT_USAGE_EMAIL_RECEIVER}, | |
275 {certificateUsageObjectSigner, IDS_CERT_USAGE_OBJECT_SIGNER}, | |
276 {certificateUsageSSLCA, IDS_CERT_USAGE_SSL_CA}, | |
277 {certificateUsageStatusResponder, IDS_CERT_USAGE_STATUS_RESPONDER}, | |
278 }; | |
279 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(usage_string_map); ++i) { | |
280 if (usages & usage_string_map[i].usage) | |
281 gtk_box_pack_start( | |
282 GTK_BOX(uses_vbox), | |
283 gtk_util::IndentWidget(gtk_util::LeftAlignMisc(gtk_label_new( | |
284 l10n_util::GetStringUTF8( | |
285 usage_string_map[i].string_id).c_str()))), | |
286 FALSE, FALSE, 0); | |
287 } | |
288 } | |
289 | 267 |
290 gtk_box_pack_start(GTK_BOX(general_page_vbox_), gtk_hseparator_new(), | 268 gtk_box_pack_start(GTK_BOX(general_page_vbox_), gtk_hseparator_new(), |
291 FALSE, FALSE, 0); | 269 FALSE, FALSE, 0); |
292 | 270 |
293 const int num_rows = 21; | 271 const int num_rows = 21; |
294 GtkTable* table = GTK_TABLE(gtk_table_new(num_rows, 2, FALSE)); | 272 GtkTable* table = GTK_TABLE(gtk_table_new(num_rows, 2, FALSE)); |
295 gtk_table_set_col_spacing(table, 0, gtk_util::kLabelSpacing); | 273 gtk_table_set_col_spacing(table, 0, gtk_util::kLabelSpacing); |
296 gtk_table_set_row_spacings(table, gtk_util::kControlSpacing); | 274 gtk_table_set_row_spacings(table, gtk_util::kControlSpacing); |
297 | 275 |
298 gtk_box_pack_start(GTK_BOX(general_page_vbox_), GTK_WIDGET(table), | 276 gtk_box_pack_start(GTK_BOX(general_page_vbox_), GTK_WIDGET(table), |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 void ShowCertificateViewer(gfx::NativeWindow parent, int cert_id) { | 695 void ShowCertificateViewer(gfx::NativeWindow parent, int cert_id) { |
718 scoped_refptr<net::X509Certificate> cert; | 696 scoped_refptr<net::X509Certificate> cert; |
719 CertStore::GetSharedInstance()->RetrieveCert(cert_id, &cert); | 697 CertStore::GetSharedInstance()->RetrieveCert(cert_id, &cert); |
720 if (!cert.get()) { | 698 if (!cert.get()) { |
721 // The certificate was not found. Could be that the renderer crashed before | 699 // The certificate was not found. Could be that the renderer crashed before |
722 // we displayed the page info. | 700 // we displayed the page info. |
723 return; | 701 return; |
724 } | 702 } |
725 ShowCertificateViewer(parent, cert->os_cert_handle()); | 703 ShowCertificateViewer(parent, cert->os_cert_handle()); |
726 } | 704 } |
OLD | NEW |