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

Side by Side Diff: chrome/browser/ui/certificate_dialogs.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: re-do comment change Created 6 years, 4 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/certificate_dialogs.h" 5 #include "chrome/browser/ui/certificate_dialogs.h"
6 6
7 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "chrome/browser/ui/chrome_select_file_policy.h" 15 #include "chrome/browser/ui/chrome_select_file_policy.h"
16 #include "chrome/common/net/x509_certificate_model.h" 16 #include "chrome/common/net/x509_certificate_model.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return "-----BEGIN CERTIFICATE-----\r\n" + 58 return "-----BEGIN CERTIFICATE-----\r\n" +
59 WrapAt64(base64) + 59 WrapAt64(base64) +
60 "-----END CERTIFICATE-----\r\n"; 60 "-----END CERTIFICATE-----\r\n";
61 } 61 }
62 62
63 //////////////////////////////////////////////////////////////////////////////// 63 ////////////////////////////////////////////////////////////////////////////////
64 // General utility functions. 64 // General utility functions.
65 65
66 class Exporter : public ui::SelectFileDialog::Listener { 66 class Exporter : public ui::SelectFileDialog::Listener {
67 public: 67 public:
68 Exporter(WebContents* web_contents, gfx::NativeWindow parent, 68 Exporter(WebContents* web_contents,
69 net::X509Certificate::OSCertHandle cert); 69 gfx::NativeWindow parent,
70 net::X509Certificate::OSCertHandles::iterator certs_begin,
71 net::X509Certificate::OSCertHandles::iterator certs_end);
70 virtual ~Exporter(); 72 virtual ~Exporter();
71 73
72 // SelectFileDialog::Listener implemenation. 74 // SelectFileDialog::Listener implemenation.
73 virtual void FileSelected(const base::FilePath& path, 75 virtual void FileSelected(const base::FilePath& path,
74 int index, void* params) OVERRIDE; 76 int index, void* params) OVERRIDE;
75 virtual void FileSelectionCanceled(void* params) OVERRIDE; 77 virtual void FileSelectionCanceled(void* params) OVERRIDE;
76 private: 78 private:
77 scoped_refptr<ui::SelectFileDialog> select_file_dialog_; 79 scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
78 80
79 // The certificate hierarchy (leaf cert first). 81 // The certificate hierarchy (leaf cert first).
80 net::X509Certificate::OSCertHandles cert_chain_list_; 82 net::X509Certificate::OSCertHandles cert_chain_list_;
81 }; 83 };
82 84
83 Exporter::Exporter(WebContents* web_contents, 85 Exporter::Exporter(WebContents* web_contents,
84 gfx::NativeWindow parent, 86 gfx::NativeWindow parent,
85 net::X509Certificate::OSCertHandle cert) 87 net::X509Certificate::OSCertHandles::iterator certs_begin,
88 net::X509Certificate::OSCertHandles::iterator certs_end)
86 : select_file_dialog_(ui::SelectFileDialog::Create( 89 : select_file_dialog_(ui::SelectFileDialog::Create(
87 this, new ChromeSelectFilePolicy(web_contents))) { 90 this,
88 x509_certificate_model::GetCertChainFromCert(cert, &cert_chain_list_); 91 new ChromeSelectFilePolicy(web_contents))) {
92 DCHECK(certs_begin != certs_end);
93 for (net::X509Certificate::OSCertHandles::iterator i = certs_begin;
94 i != certs_end;
95 ++i) {
96 cert_chain_list_.push_back(net::X509Certificate::DupOSCertHandle(*i));
97 }
89 98
90 // TODO(mattm): should this default to some directory? 99 // TODO(mattm): should this default to some directory?
91 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.) 100 // Maybe SavePackage::GetSaveDirPreference? (Except that it's private.)
92 std::string cert_title = x509_certificate_model::GetTitle(cert); 101 std::string cert_title = x509_certificate_model::GetTitle(*certs_begin);
93 base::FilePath suggested_path = 102 base::FilePath suggested_path =
94 net::GenerateFileName(GURL::EmptyGURL(), // url 103 net::GenerateFileName(GURL::EmptyGURL(), // url
95 std::string(), // content_disposition 104 std::string(), // content_disposition
96 std::string(), // referrer_charset 105 std::string(), // referrer_charset
97 cert_title, // suggested_name 106 cert_title, // suggested_name
98 std::string(), // mime_type 107 std::string(), // mime_type
99 "certificate"); // default_name 108 "certificate"); // default_name
100 109
101 ShowCertSelectFileDialog(select_file_dialog_.get(), 110 ShowCertSelectFileDialog(select_file_dialog_.get(),
102 ui::SelectFileDialog::SELECT_SAVEAS_FILE, 111 ui::SelectFileDialog::SELECT_SAVEAS_FILE,
103 suggested_path, 112 suggested_path,
104 parent, 113 parent,
105 NULL); 114 NULL);
106 } 115 }
107 116
108 Exporter::~Exporter() { 117 Exporter::~Exporter() {
109 // There may be pending file dialogs, we need to tell them that we've gone 118 // There may be pending file dialogs, we need to tell them that we've gone
110 // away so they don't try and call back to us. 119 // away so they don't try and call back to us.
111 if (select_file_dialog_.get()) 120 if (select_file_dialog_.get())
112 select_file_dialog_->ListenerDestroyed(); 121 select_file_dialog_->ListenerDestroyed();
113 122
114 x509_certificate_model::DestroyCertChain(&cert_chain_list_); 123 std::for_each(cert_chain_list_.begin(),
124 cert_chain_list_.end(),
125 &net::X509Certificate::FreeOSCertHandle);
115 } 126 }
116 127
117 void Exporter::FileSelected(const base::FilePath& path, int index, 128 void Exporter::FileSelected(const base::FilePath& path, int index,
118 void* params) { 129 void* params) {
119 std::string data; 130 std::string data;
120 switch (index) { 131 switch (index) {
121 case 2: 132 case 2:
122 for (size_t i = 0; i < cert_chain_list_.size(); ++i) 133 for (size_t i = 0; i < cert_chain_list_.size(); ++i)
123 data += GetBase64String(cert_chain_list_[i]); 134 data += GetBase64String(cert_chain_list_[i]);
124 break; 135 break;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 select_file_dialog->SelectFile( 189 select_file_dialog->SelectFile(
179 type, base::string16(), 190 type, base::string16(),
180 suggested_path, &file_type_info, 191 suggested_path, &file_type_info,
181 1, // 1-based index for |file_type_info.extensions| to specify default. 192 1, // 1-based index for |file_type_info.extensions| to specify default.
182 FILE_PATH_LITERAL("crt"), 193 FILE_PATH_LITERAL("crt"),
183 parent, params); 194 parent, params);
184 } 195 }
185 196
186 void ShowCertExportDialog(WebContents* web_contents, 197 void ShowCertExportDialog(WebContents* web_contents,
187 gfx::NativeWindow parent, 198 gfx::NativeWindow parent,
188 net::X509Certificate::OSCertHandle cert) { 199 const scoped_refptr<net::X509Certificate>& cert) {
189 new Exporter(web_contents, parent, cert); 200 net::X509Certificate::OSCertHandles cert_chain;
201 cert_chain.push_back(cert->os_cert_handle());
202 const net::X509Certificate::OSCertHandles& certs =
203 cert->GetIntermediateCertificates();
204 cert_chain.insert(cert_chain.end(), certs.begin(), certs.end());
205 new Exporter(web_contents, parent, cert_chain.begin(), cert_chain.end());
190 } 206 }
207
208 void ShowCertExportDialog(
209 content::WebContents* web_contents,
210 gfx::NativeWindow parent,
211 net::X509Certificate::OSCertHandles::iterator certs_begin,
212 net::X509Certificate::OSCertHandles::iterator certs_end) {
213 new Exporter(web_contents, parent, certs_begin, certs_end);
214 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/certificate_dialogs.h ('k') | chrome/browser/ui/webui/certificate_viewer_webui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698