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

Side by Side Diff: chrome/browser/ui/views/platform_keys_certificate_selector_chromeos.cc

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: missing include Created 3 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/platform_keys_certificate_selector_chromeos.h" 5 #include "chrome/browser/ui/views/platform_keys_certificate_selector_chromeos.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/ui/browser_dialogs.h" 15 #include "chrome/browser/ui/browser_dialogs.h"
15 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
17 #include "net/ssl/client_cert_identity.h"
18 #include "net/ssl/ssl_private_key.h"
16 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/font.h" 20 #include "ui/gfx/font.h"
18 #include "ui/views/controls/styled_label.h" 21 #include "ui/views/controls/styled_label.h"
19 22
20 namespace chromeos { 23 namespace chromeos {
21 24
25 namespace {
26
27 // Fake ClientCertIdentity that does not support retrieving the private key.
28 // platformKeys API currently only deals in certificates, not identities.
29 // Looking up the private key by the certificate is done as a separate step.
30 class ClientCertIdentityPlatformKeys : public net::ClientCertIdentity {
31 public:
32 explicit ClientCertIdentityPlatformKeys(
33 scoped_refptr<net::X509Certificate> cert)
34 : net::ClientCertIdentity(std::move(cert)) {}
35 ~ClientCertIdentityPlatformKeys() override = default;
36
37 void AcquirePrivateKey(
38 const base::Callback<void(scoped_refptr<net::SSLPrivateKey>)>&
39 private_key_callback) override;
40 };
41
42 void ClientCertIdentityPlatformKeys::AcquirePrivateKey(
43 const base::Callback<void(scoped_refptr<net::SSLPrivateKey>)>&
44 private_key_callback) {
45 NOTREACHED();
46 private_key_callback.Run(nullptr);
47 }
48
49 net::ClientCertIdentityList CertificateListToIdentityList(
50 const net::CertificateList& certs) {
davidben 2017/06/07 23:06:17 Optional: Same question about whether this should
mattm 2017/06/08 21:47:56 Done.
51 net::ClientCertIdentityList identities;
52 for (const auto& cert : certs) {
53 identities.push_back(
54 base::MakeUnique<ClientCertIdentityPlatformKeys>(cert));
55 }
56 return identities;
57 }
58
59 } // namespace
60
22 PlatformKeysCertificateSelector::PlatformKeysCertificateSelector( 61 PlatformKeysCertificateSelector::PlatformKeysCertificateSelector(
23 const net::CertificateList& certificates, 62 const net::CertificateList& certificates,
24 const std::string& extension_name, 63 const std::string& extension_name,
25 const CertificateSelectedCallback& callback, 64 const CertificateSelectedCallback& callback,
26 content::WebContents* web_contents) 65 content::WebContents* web_contents)
27 : CertificateSelector(certificates, web_contents), 66 : CertificateSelector(CertificateListToIdentityList(certificates),
67 web_contents),
28 extension_name_(extension_name), 68 extension_name_(extension_name),
29 callback_(callback) { 69 callback_(callback) {
30 DCHECK(!callback_.is_null()); 70 DCHECK(!callback_.is_null());
31 chrome::RecordDialogCreation( 71 chrome::RecordDialogCreation(
32 chrome::DialogIdentifier::PLATFORM_KEYS_CERTIFICATE_SELECTOR); 72 chrome::DialogIdentifier::PLATFORM_KEYS_CERTIFICATE_SELECTOR);
33 } 73 }
34 74
35 PlatformKeysCertificateSelector::~PlatformKeysCertificateSelector() { 75 PlatformKeysCertificateSelector::~PlatformKeysCertificateSelector() {
36 // Ensure to call back even if the dialog was closed because of the views 76 // Ensure to call back even if the dialog was closed because of the views
37 // hierarchy being destroyed. 77 // hierarchy being destroyed.
(...skipping 18 matching lines...) Expand all
56 } 96 }
57 97
58 bool PlatformKeysCertificateSelector::Cancel() { 98 bool PlatformKeysCertificateSelector::Cancel() {
59 DCHECK(!callback_.is_null()); 99 DCHECK(!callback_.is_null());
60 base::ResetAndReturn(&callback_).Run(nullptr); 100 base::ResetAndReturn(&callback_).Run(nullptr);
61 return true; 101 return true;
62 } 102 }
63 103
64 bool PlatformKeysCertificateSelector::Accept() { 104 bool PlatformKeysCertificateSelector::Accept() {
65 DCHECK(!callback_.is_null()); 105 DCHECK(!callback_.is_null());
66 scoped_refptr<net::X509Certificate> cert = GetSelectedCert(); 106 net::ClientCertIdentity* identity = GetSelectedCert();
67 if (!cert) 107 if (!identity)
68 return false; 108 return false;
69 base::ResetAndReturn(&callback_).Run(cert); 109 base::ResetAndReturn(&callback_)
110 .Run(make_scoped_refptr(identity->certificate()));
70 return true; 111 return true;
71 } 112 }
72 113
73 void ShowPlatformKeysCertificateSelector( 114 void ShowPlatformKeysCertificateSelector(
74 content::WebContents* web_contents, 115 content::WebContents* web_contents,
75 const std::string& extension_name, 116 const std::string& extension_name,
76 const net::CertificateList& certificates, 117 const net::CertificateList& certificates,
77 const base::Callback<void(const scoped_refptr<net::X509Certificate>&)>& 118 const base::Callback<void(const scoped_refptr<net::X509Certificate>&)>&
78 callback) { 119 callback) {
79 PlatformKeysCertificateSelector* selector = 120 PlatformKeysCertificateSelector* selector =
80 new PlatformKeysCertificateSelector(certificates, extension_name, 121 new PlatformKeysCertificateSelector(certificates, extension_name,
81 callback, web_contents); 122 callback, web_contents);
82 selector->Init(); 123 selector->Init();
83 selector->Show(); 124 selector->Show();
84 } 125 }
85 126
86 } // namespace chromeos 127 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698