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

Side by Side Diff: chrome/browser/views/ssl_client_certificate_selector_win.cc

Issue 2823038: Refactor SSLClientAuthHandler and certificate selection (Closed)
Patch Set: Rebase the patch Created 10 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
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_ssl_helper.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ssl/ssl_client_auth_handler.h" 5 #include "chrome/browser/ssl_client_certificate_selector.h"
6 6
7 #include <cryptuiapi.h> 7 #include <cryptuiapi.h>
8 #pragma comment(lib, "cryptui.lib") 8 #pragma comment(lib, "cryptui.lib")
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "chrome/browser/browser_list.h" 12 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/browser.h" 13 #include "chrome/browser/browser.h"
14 #include "chrome/browser/browser_window.h" 14 #include "chrome/browser/browser_window.h"
15 #include "chrome/browser/chrome_thread.h" 15 #include "chrome/browser/chrome_thread.h"
16 #include "chrome/browser/ssl/ssl_client_auth_handler.h"
16 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
17 #include "net/url_request/url_request.h" 18 #include "net/url_request/url_request.h"
18 19
19 void SSLClientAuthHandler::DoSelectCertificate() { 20 namespace browser {
21
22 void ShowSSLClientCertificateSelector(
23 gfx::NativeWindow parent,
24 net::SSLCertRequestInfo* cert_request_info,
25 SSLClientAuthHandler* delegate) {
20 net::X509Certificate* cert = NULL; 26 net::X509Certificate* cert = NULL;
21 // TODO(jcampan): replace this with our own cert selection dialog. 27 // TODO(jcampan): replace this with our own cert selection dialog.
22 // CryptUIDlgSelectCertificateFromStore is blocking (but still processes 28 // CryptUIDlgSelectCertificateFromStore is blocking (but still processes
23 // Windows messages), which is scary. 29 // Windows messages), which is scary.
24 HCERTSTORE client_certs = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, 30 HCERTSTORE client_certs = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL,
25 0, NULL); 31 0, NULL);
26 BOOL ok; 32 BOOL ok;
27 for (size_t i = 0; i < cert_request_info_->client_certs.size(); ++i) { 33 for (size_t i = 0; i < cert_request_info->client_certs.size(); ++i) {
28 PCCERT_CONTEXT cc = cert_request_info_->client_certs[i]->os_cert_handle(); 34 PCCERT_CONTEXT cc = cert_request_info->client_certs[i]->os_cert_handle();
29 ok = CertAddCertificateContextToStore(client_certs, cc, 35 ok = CertAddCertificateContextToStore(client_certs, cc,
30 CERT_STORE_ADD_ALWAYS, NULL); 36 CERT_STORE_ADD_ALWAYS, NULL);
31 DCHECK(ok); 37 DCHECK(ok);
32 } 38 }
33 39
34 HWND browser_hwnd = NULL;
35 Browser* browser = BrowserList::GetLastActive();
36 if (browser)
37 browser_hwnd = browser->window()->GetNativeHandle();
38
39 std::wstring title = l10n_util::GetString(IDS_CLIENT_CERT_DIALOG_TITLE); 40 std::wstring title = l10n_util::GetString(IDS_CLIENT_CERT_DIALOG_TITLE);
40 std::wstring text = l10n_util::GetStringF( 41 std::wstring text = l10n_util::GetStringF(
41 IDS_CLIENT_CERT_DIALOG_TEXT, 42 IDS_CLIENT_CERT_DIALOG_TEXT,
42 ASCIIToWide(cert_request_info_->host_and_port)); 43 ASCIIToWide(cert_request_info->host_and_port));
43 PCCERT_CONTEXT cert_context = CryptUIDlgSelectCertificateFromStore( 44 PCCERT_CONTEXT cert_context = CryptUIDlgSelectCertificateFromStore(
44 client_certs, browser_hwnd, title.c_str(), text.c_str(), 0, 0, NULL); 45 client_certs, parent, title.c_str(), text.c_str(), 0, 0, NULL);
45 46
46 if (cert_context) { 47 if (cert_context) {
47 cert = net::X509Certificate::CreateFromHandle( 48 cert = net::X509Certificate::CreateFromHandle(
48 cert_context, 49 cert_context,
49 net::X509Certificate::SOURCE_LONE_CERT_IMPORT, 50 net::X509Certificate::SOURCE_LONE_CERT_IMPORT,
50 net::X509Certificate::OSCertHandles()); 51 net::X509Certificate::OSCertHandles());
51 net::X509Certificate::FreeOSCertHandle(cert_context); 52 net::X509Certificate::FreeOSCertHandle(cert_context);
52 } 53 }
53 54
54 ok = CertCloseStore(client_certs, CERT_CLOSE_STORE_CHECK_FLAG); 55 ok = CertCloseStore(client_certs, CERT_CLOSE_STORE_CHECK_FLAG);
55 DCHECK(ok); 56 DCHECK(ok);
56 57
57 CertificateSelected(cert); 58 delegate->CertificateSelected(cert);
58 } 59 }
60
61 } // namespace browser
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_ssl_helper.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698