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

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: rebase 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.
Peter Kasting 2017/06/15 22:13:41 Nit: Leading "The"
mattm 2017/06/16 03:30:42 Done.
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 NOTREACHED();
41 private_key_callback.Run(nullptr);
Peter Kasting 2017/06/15 22:13:41 It doesn't make sense to me to execute any code af
mattm 2017/06/16 03:30:42 Done.
42 }
43 };
44
45 net::ClientCertIdentityList CertificateListToIdentityList(
46 const net::CertificateList& certs) {
47 net::ClientCertIdentityList identities;
48 for (const auto& cert : certs) {
49 identities.push_back(
50 base::MakeUnique<ClientCertIdentityPlatformKeys>(cert));
51 }
52 return identities;
53 }
54
55 } // namespace
56
22 PlatformKeysCertificateSelector::PlatformKeysCertificateSelector( 57 PlatformKeysCertificateSelector::PlatformKeysCertificateSelector(
23 const net::CertificateList& certificates, 58 const net::CertificateList& certificates,
24 const std::string& extension_name, 59 const std::string& extension_name,
25 const CertificateSelectedCallback& callback, 60 const CertificateSelectedCallback& callback,
26 content::WebContents* web_contents) 61 content::WebContents* web_contents)
27 : CertificateSelector(certificates, web_contents), 62 : CertificateSelector(CertificateListToIdentityList(certificates),
63 web_contents),
28 extension_name_(extension_name), 64 extension_name_(extension_name),
29 callback_(callback) { 65 callback_(callback) {
30 DCHECK(!callback_.is_null()); 66 DCHECK(!callback_.is_null());
31 chrome::RecordDialogCreation( 67 chrome::RecordDialogCreation(
32 chrome::DialogIdentifier::PLATFORM_KEYS_CERTIFICATE_SELECTOR); 68 chrome::DialogIdentifier::PLATFORM_KEYS_CERTIFICATE_SELECTOR);
33 } 69 }
34 70
35 PlatformKeysCertificateSelector::~PlatformKeysCertificateSelector() { 71 PlatformKeysCertificateSelector::~PlatformKeysCertificateSelector() {
36 // Ensure to call back even if the dialog was closed because of the views 72 // Ensure to call back even if the dialog was closed because of the views
37 // hierarchy being destroyed. 73 // hierarchy being destroyed.
(...skipping 18 matching lines...) Expand all
56 } 92 }
57 93
58 bool PlatformKeysCertificateSelector::Cancel() { 94 bool PlatformKeysCertificateSelector::Cancel() {
59 DCHECK(!callback_.is_null()); 95 DCHECK(!callback_.is_null());
60 base::ResetAndReturn(&callback_).Run(nullptr); 96 base::ResetAndReturn(&callback_).Run(nullptr);
61 return true; 97 return true;
62 } 98 }
63 99
64 bool PlatformKeysCertificateSelector::Accept() { 100 bool PlatformKeysCertificateSelector::Accept() {
65 DCHECK(!callback_.is_null()); 101 DCHECK(!callback_.is_null());
66 scoped_refptr<net::X509Certificate> cert = GetSelectedCert(); 102 net::ClientCertIdentity* identity = GetSelectedCert();
67 if (!cert) 103 if (!identity)
68 return false; 104 return false;
69 base::ResetAndReturn(&callback_).Run(cert); 105 base::ResetAndReturn(&callback_)
106 .Run(make_scoped_refptr(identity->certificate()));
70 return true; 107 return true;
71 } 108 }
72 109
73 void ShowPlatformKeysCertificateSelector( 110 void ShowPlatformKeysCertificateSelector(
74 content::WebContents* web_contents, 111 content::WebContents* web_contents,
75 const std::string& extension_name, 112 const std::string& extension_name,
76 const net::CertificateList& certificates, 113 const net::CertificateList& certificates,
77 const base::Callback<void(const scoped_refptr<net::X509Certificate>&)>& 114 const base::Callback<void(const scoped_refptr<net::X509Certificate>&)>&
78 callback) { 115 callback) {
79 PlatformKeysCertificateSelector* selector = 116 PlatformKeysCertificateSelector* selector =
80 new PlatformKeysCertificateSelector(certificates, extension_name, 117 new PlatformKeysCertificateSelector(certificates, extension_name,
81 callback, web_contents); 118 callback, web_contents);
82 selector->Init(); 119 selector->Init();
83 selector->Show(); 120 selector->Show();
84 } 121 }
85 122
86 } // namespace chromeos 123 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698