Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: chrome/browser/ui/webui/certificate_viewer_webui.cc

Issue 376753002: Fix webui cert viewer showing wrong cert chain on NSS and no chain on OpenSSL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/certificate_viewer_webui.h" 5 #include "chrome/browser/ui/webui/certificate_viewer_webui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/i18n/time_formatting.h" 9 #include "base/i18n/time_formatting.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 24 matching lines...) Expand all
35 dialog->Show(web_contents, parent); 35 dialog->Show(web_contents, parent);
36 } 36 }
37 37
38 //////////////////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////////////////
39 // CertificateViewerDialog 39 // CertificateViewerDialog
40 40
41 CertificateViewerModalDialog::CertificateViewerModalDialog( 41 CertificateViewerModalDialog::CertificateViewerModalDialog(
42 net::X509Certificate* cert) 42 net::X509Certificate* cert)
43 : cert_(cert), webui_(NULL), window_(NULL) { 43 : cert_(cert), webui_(NULL), window_(NULL) {
44 // Construct the dialog title from the certificate. 44 // Construct the dialog title from the certificate.
45 net::X509Certificate::OSCertHandles cert_chain; 45 title_ = l10n_util::GetStringFUTF16(
46 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), 46 IDS_CERT_INFO_DIALOG_TITLE,
47 &cert_chain); 47 base::UTF8ToUTF16(
48 title_ = l10n_util::GetStringFUTF16(IDS_CERT_INFO_DIALOG_TITLE, 48 x509_certificate_model::GetTitle(cert_->os_cert_handle())));
49 base::UTF8ToUTF16(x509_certificate_model::GetTitle(cert_chain.front())));
50 } 49 }
51 50
52 CertificateViewerModalDialog::~CertificateViewerModalDialog() { 51 CertificateViewerModalDialog::~CertificateViewerModalDialog() {
53 } 52 }
54 53
55 void CertificateViewerModalDialog::Show(content::WebContents* web_contents, 54 void CertificateViewerModalDialog::Show(content::WebContents* web_contents,
56 gfx::NativeWindow parent) { 55 gfx::NativeWindow parent) {
57 window_ = chrome::ShowWebDialog(parent, 56 window_ = chrome::ShowWebDialog(parent,
58 web_contents->GetBrowserContext(), 57 web_contents->GetBrowserContext(),
59 this); 58 this);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 std::string CertificateViewerModalDialog::GetDialogArgs() const { 95 std::string CertificateViewerModalDialog::GetDialogArgs() const {
97 std::string data; 96 std::string data;
98 97
99 // Certificate information. The keys in this dictionary's general key 98 // Certificate information. The keys in this dictionary's general key
100 // correspond to the IDs in the Html page. 99 // correspond to the IDs in the Html page.
101 base::DictionaryValue cert_info; 100 base::DictionaryValue cert_info;
102 net::X509Certificate::OSCertHandle cert_hnd = cert_->os_cert_handle(); 101 net::X509Certificate::OSCertHandle cert_hnd = cert_->os_cert_handle();
103 102
104 // Get the certificate chain. 103 // Get the certificate chain.
105 net::X509Certificate::OSCertHandles cert_chain; 104 net::X509Certificate::OSCertHandles cert_chain;
106 x509_certificate_model::GetCertChainFromCert(cert_hnd, &cert_chain); 105 cert_->GetCertificateChain(&cert_chain);
107 106
108 // Certificate usage. 107 // Certificate usage.
109 std::vector<std::string> usages; 108 std::vector<std::string> usages;
110 x509_certificate_model::GetUsageStrings(cert_hnd, &usages); 109 x509_certificate_model::GetUsageStrings(cert_hnd, &usages);
111 std::string usagestr; 110 std::string usagestr;
112 for (std::vector<std::string>::iterator it = usages.begin(); 111 for (std::vector<std::string>::iterator it = usages.begin();
113 it != usages.end(); ++it) { 112 it != usages.end(); ++it) {
114 if (usagestr.length() > 0) { 113 if (usagestr.length() > 0) {
115 usagestr += "\n"; 114 usagestr += "\n";
116 } 115 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 243
245 ui::ModalType CertificateViewerDialog::GetDialogModalType() const { 244 ui::ModalType CertificateViewerDialog::GetDialogModalType() const {
246 return ui::MODAL_TYPE_NONE; 245 return ui::MODAL_TYPE_NONE;
247 } 246 }
248 247
249 //////////////////////////////////////////////////////////////////////////////// 248 ////////////////////////////////////////////////////////////////////////////////
250 // CertificateViewerDialogHandler 249 // CertificateViewerDialogHandler
251 250
252 CertificateViewerDialogHandler::CertificateViewerDialogHandler( 251 CertificateViewerDialogHandler::CertificateViewerDialogHandler(
253 CertificateViewerModalDialog* dialog, 252 CertificateViewerModalDialog* dialog,
254 net::X509Certificate* cert) : cert_(cert), dialog_(dialog) { 253 net::X509Certificate* cert)
255 x509_certificate_model::GetCertChainFromCert(cert_->os_cert_handle(), 254 : cert_(cert), dialog_(dialog) {
256 &cert_chain_); 255 cert_->GetCertificateChain(&cert_chain_);
257 } 256 }
258 257
259 CertificateViewerDialogHandler::~CertificateViewerDialogHandler() { 258 CertificateViewerDialogHandler::~CertificateViewerDialogHandler() {
260 } 259 }
261 260
262 void CertificateViewerDialogHandler::RegisterMessages() { 261 void CertificateViewerDialogHandler::RegisterMessages() {
263 web_ui()->RegisterMessageCallback("exportCertificate", 262 web_ui()->RegisterMessageCallback("exportCertificate",
264 base::Bind(&CertificateViewerDialogHandler::ExportCertificate, 263 base::Bind(&CertificateViewerDialogHandler::ExportCertificate,
265 base::Unretained(this))); 264 base::Unretained(this)));
266 web_ui()->RegisterMessageCallback("requestCertificateFields", 265 web_ui()->RegisterMessageCallback("requestCertificateFields",
267 base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields, 266 base::Bind(&CertificateViewerDialogHandler::RequestCertificateFields,
268 base::Unretained(this))); 267 base::Unretained(this)));
269 } 268 }
270 269
271 void CertificateViewerDialogHandler::ExportCertificate( 270 void CertificateViewerDialogHandler::ExportCertificate(
272 const base::ListValue* args) { 271 const base::ListValue* args) {
273 int cert_index = GetCertificateIndex(args); 272 int cert_index = GetCertificateIndex(args);
274 if (cert_index < 0) 273 if (cert_index < 0)
275 return; 274 return;
276 275
277 NativeWebContentsModalDialog window = 276 NativeWebContentsModalDialog window =
278 platform_util::GetTopLevel(dialog_->GetNativeWebContentsModalDialog()); 277 platform_util::GetTopLevel(dialog_->GetNativeWebContentsModalDialog());
279 ShowCertExportDialog(web_ui()->GetWebContents(), 278 ShowCertExportDialog(web_ui()->GetWebContents(),
280 window, 279 window,
281 cert_chain_[cert_index]); 280 cert_chain_.begin() + cert_index,
281 cert_chain_.end());
282 } 282 }
283 283
284 void CertificateViewerDialogHandler::RequestCertificateFields( 284 void CertificateViewerDialogHandler::RequestCertificateFields(
285 const base::ListValue* args) { 285 const base::ListValue* args) {
286 int cert_index = GetCertificateIndex(args); 286 int cert_index = GetCertificateIndex(args);
287 if (cert_index < 0) 287 if (cert_index < 0)
288 return; 288 return;
289 289
290 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index]; 290 net::X509Certificate::OSCertHandle cert = cert_chain_[cert_index];
291 291
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 const base::ListValue* args) const { 440 const base::ListValue* args) const {
441 int cert_index; 441 int cert_index;
442 double val; 442 double val;
443 if (!(args->GetDouble(0, &val))) 443 if (!(args->GetDouble(0, &val)))
444 return -1; 444 return -1;
445 cert_index = static_cast<int>(val); 445 cert_index = static_cast<int>(val);
446 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size())) 446 if (cert_index < 0 || cert_index >= static_cast<int>(cert_chain_.size()))
447 return -1; 447 return -1;
448 return cert_index; 448 return cert_index;
449 } 449 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698