OLD | NEW |
---|---|
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/chromeos/certificate_provider/certificate_provider_serv ice.h" | 5 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv ice.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
20 #include "base/task_runner.h" | 20 #include "base/task_runner.h" |
21 #include "base/task_runner_util.h" | |
21 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
22 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" | 23 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" |
23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
24 #include "net/ssl/client_key_store.h" | |
25 | 25 |
26 namespace chromeos { | 26 namespace chromeos { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 void PostSignResultToTaskRunner( | 30 void PostSignResultToTaskRunner( |
31 const scoped_refptr<base::TaskRunner>& target_task_runner, | 31 const scoped_refptr<base::TaskRunner>& target_task_runner, |
32 const net::SSLPrivateKey::SignCallback& callback, | 32 const net::SSLPrivateKey::SignCallback& callback, |
33 net::Error error, | 33 net::Error error, |
34 const std::vector<uint8_t>& signature) { | 34 const std::vector<uint8_t>& signature) { |
35 target_task_runner->PostTask(FROM_HERE, | 35 target_task_runner->PostTask(FROM_HERE, |
36 base::Bind(callback, error, signature)); | 36 base::Bind(callback, error, signature)); |
37 } | 37 } |
38 | 38 |
39 void PostCertificatesToTaskRunner( | 39 void PostIdentitiesToTaskRunner( |
40 const scoped_refptr<base::TaskRunner>& target_task_runner, | 40 const scoped_refptr<base::TaskRunner>& target_task_runner, |
41 const base::Callback<void(const net::CertificateList&)>& callback, | 41 const base::Callback<void(net::ClientCertIdentityList)>& callback, |
42 const net::CertificateList& certs) { | 42 net::ClientCertIdentityList certs) { |
43 target_task_runner->PostTask(FROM_HERE, base::Bind(callback, certs)); | 43 target_task_runner->PostTask(FROM_HERE, |
44 base::BindOnce(callback, std::move(certs))); | |
davidben
2017/06/16 00:28:25
[The sheer amount of code in Chromium that's devot
| |
44 } | 45 } |
45 | 46 |
46 } // namespace | 47 } // namespace |
47 | 48 |
48 class CertificateProviderService::CertKeyProviderImpl | |
49 : public net::ClientKeyStore::CertKeyProvider { | |
50 public: | |
51 // |certificate_map| must outlive this provider. |service| must be | |
52 // dereferenceable on |service_task_runner|. | |
53 // This provider may be accessed from any thread. Methods and destructor must | |
54 // never be called concurrently. | |
55 CertKeyProviderImpl( | |
56 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | |
57 const base::WeakPtr<CertificateProviderService>& service, | |
58 certificate_provider::ThreadSafeCertificateMap* certificate_map); | |
59 ~CertKeyProviderImpl() override; | |
60 | |
61 bool GetCertificateKey( | |
62 const net::X509Certificate& cert, | |
63 scoped_refptr<net::SSLPrivateKey>* private_key) override; | |
64 | |
65 private: | |
66 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | |
67 // Must be dereferenced on |service_task_runner_| only. | |
68 base::WeakPtr<CertificateProviderService> service_; | |
69 certificate_provider::ThreadSafeCertificateMap* const certificate_map_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(CertKeyProviderImpl); | |
72 }; | |
73 | |
74 class CertificateProviderService::CertificateProviderImpl | 49 class CertificateProviderService::CertificateProviderImpl |
75 : public CertificateProvider { | 50 : public CertificateProvider { |
76 public: | 51 public: |
77 // Any calls back to |service| will be posted to |service_task_runner|. | 52 // Any calls back to |service| will be posted to |service_task_runner|. |
78 // |service| must be dereferenceable on |service_task_runner|. | 53 // |service| must be dereferenceable on |service_task_runner|. |
79 // This provider is not thread safe, but can be used on any thread. | 54 // This provider is not thread safe, but can be used on any thread. |
80 CertificateProviderImpl( | 55 CertificateProviderImpl( |
81 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 56 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
82 const base::WeakPtr<CertificateProviderService>& service); | 57 const base::WeakPtr<CertificateProviderService>& service); |
83 ~CertificateProviderImpl() override; | 58 ~CertificateProviderImpl() override; |
84 | 59 |
85 void GetCertificates(const base::Callback<void(const net::CertificateList&)>& | 60 void GetCertificates(const base::Callback<void(net::ClientCertIdentityList)>& |
86 callback) override; | 61 callback) override; |
87 | 62 |
88 std::unique_ptr<CertificateProvider> Copy() override; | 63 std::unique_ptr<CertificateProvider> Copy() override; |
89 | 64 |
90 private: | 65 private: |
91 static void GetCertificatesOnServiceThread( | 66 static void GetCertificatesOnServiceThread( |
92 const base::WeakPtr<CertificateProviderService>& service, | 67 const base::WeakPtr<CertificateProviderService>& service, |
93 const base::Callback<void(const net::CertificateList&)>& callback); | 68 const base::Callback<void(net::ClientCertIdentityList)>& callback); |
94 | 69 |
95 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 70 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
96 // Must be dereferenced on |service_task_runner_| only. | 71 // Must be dereferenced on |service_task_runner_| only. |
97 const base::WeakPtr<CertificateProviderService> service_; | 72 const base::WeakPtr<CertificateProviderService> service_; |
98 | 73 |
99 DISALLOW_COPY_AND_ASSIGN(CertificateProviderImpl); | 74 DISALLOW_COPY_AND_ASSIGN(CertificateProviderImpl); |
100 }; | 75 }; |
101 | 76 |
102 // Implements an SSLPrivateKey backed by the signing function exposed by an | 77 // Implements an SSLPrivateKey backed by the signing function exposed by an |
103 // extension through the certificateProvider API. | 78 // extension through the certificateProvider API. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 const CertificateInfo cert_info_; | 112 const CertificateInfo cert_info_; |
138 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 113 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
139 // Must be dereferenced on |service_task_runner_| only. | 114 // Must be dereferenced on |service_task_runner_| only. |
140 const base::WeakPtr<CertificateProviderService> service_; | 115 const base::WeakPtr<CertificateProviderService> service_; |
141 base::ThreadChecker thread_checker_; | 116 base::ThreadChecker thread_checker_; |
142 base::WeakPtrFactory<SSLPrivateKey> weak_factory_; | 117 base::WeakPtrFactory<SSLPrivateKey> weak_factory_; |
143 | 118 |
144 DISALLOW_COPY_AND_ASSIGN(SSLPrivateKey); | 119 DISALLOW_COPY_AND_ASSIGN(SSLPrivateKey); |
145 }; | 120 }; |
146 | 121 |
147 CertificateProviderService::CertKeyProviderImpl::CertKeyProviderImpl( | 122 class CertificateProviderService::ClientCertIdentity |
148 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 123 : public net::ClientCertIdentity { |
149 const base::WeakPtr<CertificateProviderService>& service, | 124 public: |
150 certificate_provider::ThreadSafeCertificateMap* certificate_map) | 125 ClientCertIdentity( |
151 : service_task_runner_(service_task_runner), | 126 scoped_refptr<net::X509Certificate> cert, |
152 service_(service), | 127 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
153 certificate_map_(certificate_map) {} | 128 base::WeakPtr<CertificateProviderService> service) |
129 : net::ClientCertIdentity(std::move(cert)), | |
130 service_task_runner_(service_task_runner), | |
131 service_(service) {} | |
132 ~ClientCertIdentity() override = default; | |
154 | 133 |
155 CertificateProviderService::CertKeyProviderImpl::~CertKeyProviderImpl() {} | 134 void AcquirePrivateKey( |
135 const base::Callback<void(scoped_refptr<net::SSLPrivateKey>)>& | |
136 private_key_callback) override; | |
156 | 137 |
157 bool CertificateProviderService::CertKeyProviderImpl::GetCertificateKey( | 138 private: |
158 const net::X509Certificate& cert, | 139 scoped_refptr<net::SSLPrivateKey> GetCertificateKeyOnServiceThread( |
159 scoped_refptr<net::SSLPrivateKey>* private_key) { | 140 net::X509Certificate* cert); |
141 | |
142 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | |
143 // Must be dereferenced on |service_task_runner_| only. | |
144 const base::WeakPtr<CertificateProviderService> service_; | |
145 | |
146 DISALLOW_COPY_AND_ASSIGN(ClientCertIdentity); | |
147 }; | |
148 | |
149 void CertificateProviderService::ClientCertIdentity::AcquirePrivateKey( | |
150 const base::Callback<void(scoped_refptr<net::SSLPrivateKey>)>& | |
151 private_key_callback) { | |
152 if (base::PostTaskAndReplyWithResult( | |
153 service_task_runner_.get(), FROM_HERE, | |
154 base::Bind(&ClientCertIdentity::GetCertificateKeyOnServiceThread, | |
155 base::Unretained(this), base::Unretained(certificate())), | |
156 private_key_callback)) { | |
157 return; | |
158 } | |
159 // If the task could not be posted, behave as if there were no certificates. | |
160 private_key_callback.Run(nullptr); | |
161 } | |
162 | |
163 scoped_refptr<net::SSLPrivateKey> CertificateProviderService:: | |
164 ClientCertIdentity::GetCertificateKeyOnServiceThread( | |
165 net::X509Certificate* cert) { | |
166 if (!service_) | |
167 return nullptr; | |
168 | |
160 bool is_currently_provided = false; | 169 bool is_currently_provided = false; |
161 CertificateInfo info; | 170 CertificateInfo info; |
162 std::string extension_id; | 171 std::string extension_id; |
163 certificate_map_->LookUpCertificate(cert, &is_currently_provided, &info, | 172 // TODO(mattm): can the ClientCertIdentity store a handle directly to the |
164 &extension_id); | 173 // extension instead of having to go through service_->certificate_map_ ? |
davidben
2017/06/16 00:28:25
Looks like you have the callback available at Upda
mattm
2017/06/16 22:34:55
Yeah I think the complication will be handling ext
| |
174 service_->certificate_map_.LookUpCertificate(*cert, &is_currently_provided, | |
175 &info, &extension_id); | |
165 if (!is_currently_provided) | 176 if (!is_currently_provided) |
166 return false; | 177 return nullptr; |
167 | 178 |
168 *private_key = | 179 return base::MakeRefCounted<SSLPrivateKey>(extension_id, info, |
169 new SSLPrivateKey(extension_id, info, service_task_runner_, service_); | 180 service_task_runner_, service_); |
170 | |
171 return true; | |
172 } | 181 } |
173 | 182 |
174 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( | 183 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( |
175 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 184 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
176 const base::WeakPtr<CertificateProviderService>& service) | 185 const base::WeakPtr<CertificateProviderService>& service) |
177 : service_task_runner_(service_task_runner), service_(service) {} | 186 : service_task_runner_(service_task_runner), service_(service) {} |
178 | 187 |
179 CertificateProviderService::CertificateProviderImpl:: | 188 CertificateProviderService::CertificateProviderImpl:: |
180 ~CertificateProviderImpl() {} | 189 ~CertificateProviderImpl() {} |
181 | 190 |
182 void CertificateProviderService::CertificateProviderImpl::GetCertificates( | 191 void CertificateProviderService::CertificateProviderImpl::GetCertificates( |
183 const base::Callback<void(const net::CertificateList&)>& callback) { | 192 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
184 const scoped_refptr<base::TaskRunner> source_task_runner = | 193 const scoped_refptr<base::TaskRunner> source_task_runner = |
185 base::ThreadTaskRunnerHandle::Get(); | 194 base::ThreadTaskRunnerHandle::Get(); |
186 const base::Callback<void(const net::CertificateList&)> | 195 const base::Callback<void(net::ClientCertIdentityList)> |
187 callback_from_service_thread = base::Bind(&PostCertificatesToTaskRunner, | 196 callback_from_service_thread = |
188 source_task_runner, callback); | 197 base::Bind(&PostIdentitiesToTaskRunner, source_task_runner, callback); |
189 | 198 |
190 service_task_runner_->PostTask( | 199 service_task_runner_->PostTask( |
191 FROM_HERE, base::Bind(&GetCertificatesOnServiceThread, service_, | 200 FROM_HERE, base::Bind(&GetCertificatesOnServiceThread, service_, |
192 callback_from_service_thread)); | 201 callback_from_service_thread)); |
193 } | 202 } |
194 | 203 |
195 std::unique_ptr<CertificateProvider> | 204 std::unique_ptr<CertificateProvider> |
196 CertificateProviderService::CertificateProviderImpl::Copy() { | 205 CertificateProviderService::CertificateProviderImpl::Copy() { |
197 return base::WrapUnique( | 206 return base::WrapUnique( |
198 new CertificateProviderImpl(service_task_runner_, service_)); | 207 new CertificateProviderImpl(service_task_runner_, service_)); |
199 } | 208 } |
200 | 209 |
201 // static | 210 // static |
202 void CertificateProviderService::CertificateProviderImpl:: | 211 void CertificateProviderService::CertificateProviderImpl:: |
203 GetCertificatesOnServiceThread( | 212 GetCertificatesOnServiceThread( |
204 const base::WeakPtr<CertificateProviderService>& service, | 213 const base::WeakPtr<CertificateProviderService>& service, |
205 const base::Callback<void(const net::CertificateList&)>& callback) { | 214 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
206 if (!service) { | 215 if (!service) { |
207 callback.Run(net::CertificateList()); | 216 callback.Run(net::ClientCertIdentityList()); |
208 return; | 217 return; |
209 } | 218 } |
210 service->GetCertificatesFromExtensions(callback); | 219 service->GetCertificatesFromExtensions(callback); |
211 } | 220 } |
212 | 221 |
213 CertificateProviderService::SSLPrivateKey::SSLPrivateKey( | 222 CertificateProviderService::SSLPrivateKey::SSLPrivateKey( |
214 const std::string& extension_id, | 223 const std::string& extension_id, |
215 const CertificateInfo& cert_info, | 224 const CertificateInfo& cert_info, |
216 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 225 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
217 const base::WeakPtr<CertificateProviderService>& service) | 226 const base::WeakPtr<CertificateProviderService>& service) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 const std::vector<uint8_t>& signature) { | 289 const std::vector<uint8_t>& signature) { |
281 DCHECK(thread_checker_.CalledOnValidThread()); | 290 DCHECK(thread_checker_.CalledOnValidThread()); |
282 callback.Run(error, signature); | 291 callback.Run(error, signature); |
283 } | 292 } |
284 | 293 |
285 CertificateProviderService::CertificateProviderService() | 294 CertificateProviderService::CertificateProviderService() |
286 : weak_factory_(this) {} | 295 : weak_factory_(this) {} |
287 | 296 |
288 CertificateProviderService::~CertificateProviderService() { | 297 CertificateProviderService::~CertificateProviderService() { |
289 DCHECK(thread_checker_.CalledOnValidThread()); | 298 DCHECK(thread_checker_.CalledOnValidThread()); |
290 | |
291 // ClientKeyStore serializes access to |cert_key_provider_|. | |
292 // Once RemoveProvider() returns, it is guaranteed that there are no more | |
293 // accesses to |cert_key_provider_| in flight and no references to | |
294 // |cert_key_provider_| are remaining. This service will hold the last | |
295 // reference to |cert_key_provider_|. | |
296 net::ClientKeyStore::GetInstance()->RemoveProvider(cert_key_provider_.get()); | |
297 cert_key_provider_.reset(); | |
298 } | 299 } |
299 | 300 |
300 void CertificateProviderService::SetDelegate( | 301 void CertificateProviderService::SetDelegate( |
301 std::unique_ptr<Delegate> delegate) { | 302 std::unique_ptr<Delegate> delegate) { |
302 DCHECK(thread_checker_.CalledOnValidThread()); | 303 DCHECK(thread_checker_.CalledOnValidThread()); |
303 DCHECK(!delegate_); | 304 DCHECK(!delegate_); |
304 DCHECK(delegate); | 305 DCHECK(delegate); |
305 | 306 |
306 delegate_ = std::move(delegate); | 307 delegate_ = std::move(delegate); |
307 cert_key_provider_.reset( | |
308 new CertKeyProviderImpl(base::ThreadTaskRunnerHandle::Get(), | |
309 weak_factory_.GetWeakPtr(), &certificate_map_)); | |
310 net::ClientKeyStore::GetInstance()->AddProvider(cert_key_provider_.get()); | |
311 } | 308 } |
312 | 309 |
313 bool CertificateProviderService::SetCertificatesProvidedByExtension( | 310 bool CertificateProviderService::SetCertificatesProvidedByExtension( |
314 const std::string& extension_id, | 311 const std::string& extension_id, |
315 int cert_request_id, | 312 int cert_request_id, |
316 const CertificateInfoList& certificate_infos) { | 313 const CertificateInfoList& certificate_infos) { |
317 DCHECK(thread_checker_.CalledOnValidThread()); | 314 DCHECK(thread_checker_.CalledOnValidThread()); |
318 | 315 |
319 bool completed = false; | 316 bool completed = false; |
320 if (!certificate_requests_.SetCertificates(extension_id, cert_request_id, | 317 if (!certificate_requests_.SetCertificates(extension_id, cert_request_id, |
321 certificate_infos, &completed)) { | 318 certificate_infos, &completed)) { |
322 DLOG(WARNING) << "Unexpected reply of extension " << extension_id | 319 DLOG(WARNING) << "Unexpected reply of extension " << extension_id |
323 << " to request " << cert_request_id; | 320 << " to request " << cert_request_id; |
324 return false; | 321 return false; |
325 } | 322 } |
326 if (completed) { | 323 if (completed) { |
327 std::map<std::string, CertificateInfoList> certificates; | 324 std::map<std::string, CertificateInfoList> certificates; |
328 base::Callback<void(const net::CertificateList&)> callback; | 325 base::Callback<void(net::ClientCertIdentityList)> callback; |
329 certificate_requests_.RemoveRequest(cert_request_id, &certificates, | 326 certificate_requests_.RemoveRequest(cert_request_id, &certificates, |
330 &callback); | 327 &callback); |
331 UpdateCertificatesAndRun(certificates, callback); | 328 UpdateCertificatesAndRun(certificates, callback); |
332 } | 329 } |
333 return true; | 330 return true; |
334 } | 331 } |
335 | 332 |
336 void CertificateProviderService::ReplyToSignRequest( | 333 void CertificateProviderService::ReplyToSignRequest( |
337 const std::string& extension_id, | 334 const std::string& extension_id, |
338 int sign_request_id, | 335 int sign_request_id, |
(...skipping 30 matching lines...) Expand all Loading... | |
369 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); | 366 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); |
370 } | 367 } |
371 | 368 |
372 void CertificateProviderService::OnExtensionUnloaded( | 369 void CertificateProviderService::OnExtensionUnloaded( |
373 const std::string& extension_id) { | 370 const std::string& extension_id) { |
374 DCHECK(thread_checker_.CalledOnValidThread()); | 371 DCHECK(thread_checker_.CalledOnValidThread()); |
375 | 372 |
376 for (const int cert_request_id : | 373 for (const int cert_request_id : |
377 certificate_requests_.DropExtension(extension_id)) { | 374 certificate_requests_.DropExtension(extension_id)) { |
378 std::map<std::string, CertificateInfoList> certificates; | 375 std::map<std::string, CertificateInfoList> certificates; |
379 base::Callback<void(const net::CertificateList&)> callback; | 376 base::Callback<void(net::ClientCertIdentityList)> callback; |
380 certificate_requests_.RemoveRequest(cert_request_id, &certificates, | 377 certificate_requests_.RemoveRequest(cert_request_id, &certificates, |
381 &callback); | 378 &callback); |
382 UpdateCertificatesAndRun(certificates, callback); | 379 UpdateCertificatesAndRun(certificates, callback); |
383 } | 380 } |
384 | 381 |
385 certificate_map_.RemoveExtension(extension_id); | 382 certificate_map_.RemoveExtension(extension_id); |
386 | 383 |
387 for (auto callback : sign_requests_.RemoveAllRequests(extension_id)) | 384 for (auto callback : sign_requests_.RemoveAllRequests(extension_id)) |
388 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 385 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
389 | 386 |
390 pin_dialog_manager_.ExtensionUnloaded(extension_id); | 387 pin_dialog_manager_.ExtensionUnloaded(extension_id); |
391 } | 388 } |
392 | 389 |
393 void CertificateProviderService::GetCertificatesFromExtensions( | 390 void CertificateProviderService::GetCertificatesFromExtensions( |
394 const base::Callback<void(const net::CertificateList&)>& callback) { | 391 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
395 DCHECK(thread_checker_.CalledOnValidThread()); | 392 DCHECK(thread_checker_.CalledOnValidThread()); |
396 | 393 |
397 const std::vector<std::string> provider_extensions( | 394 const std::vector<std::string> provider_extensions( |
398 delegate_->CertificateProviderExtensions()); | 395 delegate_->CertificateProviderExtensions()); |
399 | 396 |
400 if (provider_extensions.empty()) { | 397 if (provider_extensions.empty()) { |
401 DVLOG(2) << "No provider extensions left, clear all certificates."; | 398 DVLOG(2) << "No provider extensions left, clear all certificates."; |
402 UpdateCertificatesAndRun(std::map<std::string, CertificateInfoList>(), | 399 UpdateCertificatesAndRun(std::map<std::string, CertificateInfoList>(), |
403 callback); | 400 callback); |
404 return; | 401 return; |
405 } | 402 } |
406 | 403 |
407 const int cert_request_id = certificate_requests_.AddRequest( | 404 const int cert_request_id = certificate_requests_.AddRequest( |
408 provider_extensions, callback, | 405 provider_extensions, callback, |
409 base::Bind(&CertificateProviderService::TerminateCertificateRequest, | 406 base::Bind(&CertificateProviderService::TerminateCertificateRequest, |
410 base::Unretained(this))); | 407 base::Unretained(this))); |
411 | 408 |
412 DVLOG(2) << "Start certificate request " << cert_request_id; | 409 DVLOG(2) << "Start certificate request " << cert_request_id; |
413 delegate_->BroadcastCertificateRequest(cert_request_id); | 410 delegate_->BroadcastCertificateRequest(cert_request_id); |
414 } | 411 } |
415 | 412 |
416 void CertificateProviderService::UpdateCertificatesAndRun( | 413 void CertificateProviderService::UpdateCertificatesAndRun( |
417 const std::map<std::string, CertificateInfoList>& extension_to_certificates, | 414 const std::map<std::string, CertificateInfoList>& extension_to_certificates, |
418 const base::Callback<void(const net::CertificateList&)>& callback) { | 415 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
419 DCHECK(thread_checker_.CalledOnValidThread()); | 416 DCHECK(thread_checker_.CalledOnValidThread()); |
420 | 417 |
421 // Extensions are removed from the service's state when they're unloaded. | 418 // Extensions are removed from the service's state when they're unloaded. |
422 // Any remaining extension is assumed to be enabled. | 419 // Any remaining extension is assumed to be enabled. |
423 certificate_map_.Update(extension_to_certificates); | 420 certificate_map_.Update(extension_to_certificates); |
424 | 421 |
425 net::CertificateList all_certs; | 422 net::ClientCertIdentityList all_certs; |
426 for (const auto& entry : extension_to_certificates) { | 423 for (const auto& entry : extension_to_certificates) { |
427 for (const CertificateInfo& cert_info : entry.second) | 424 for (const CertificateInfo& cert_info : entry.second) |
428 all_certs.push_back(cert_info.certificate); | 425 all_certs.push_back(base::MakeUnique<ClientCertIdentity>( |
426 cert_info.certificate, base::ThreadTaskRunnerHandle::Get(), | |
427 weak_factory_.GetWeakPtr())); | |
429 } | 428 } |
430 | 429 |
431 callback.Run(all_certs); | 430 callback.Run(std::move(all_certs)); |
432 } | 431 } |
433 | 432 |
434 void CertificateProviderService::TerminateCertificateRequest( | 433 void CertificateProviderService::TerminateCertificateRequest( |
435 int cert_request_id) { | 434 int cert_request_id) { |
436 DCHECK(thread_checker_.CalledOnValidThread()); | 435 DCHECK(thread_checker_.CalledOnValidThread()); |
437 | 436 |
438 std::map<std::string, CertificateInfoList> certificates; | 437 std::map<std::string, CertificateInfoList> certificates; |
439 base::Callback<void(const net::CertificateList&)> callback; | 438 base::Callback<void(net::ClientCertIdentityList)> callback; |
440 if (!certificate_requests_.RemoveRequest(cert_request_id, &certificates, | 439 if (!certificate_requests_.RemoveRequest(cert_request_id, &certificates, |
441 &callback)) { | 440 &callback)) { |
442 DLOG(WARNING) << "Request id " << cert_request_id << " unknown."; | 441 DLOG(WARNING) << "Request id " << cert_request_id << " unknown."; |
443 return; | 442 return; |
444 } | 443 } |
445 | 444 |
446 DVLOG(1) << "Time out certificate request " << cert_request_id; | 445 DVLOG(1) << "Time out certificate request " << cert_request_id; |
447 UpdateCertificatesAndRun(certificates, callback); | 446 UpdateCertificatesAndRun(certificates, callback); |
448 } | 447 } |
449 | 448 |
450 void CertificateProviderService::RequestSignatureFromExtension( | 449 void CertificateProviderService::RequestSignatureFromExtension( |
451 const std::string& extension_id, | 450 const std::string& extension_id, |
452 const scoped_refptr<net::X509Certificate>& certificate, | 451 const scoped_refptr<net::X509Certificate>& certificate, |
453 net::SSLPrivateKey::Hash hash, | 452 net::SSLPrivateKey::Hash hash, |
454 const std::string& digest, | 453 const std::string& digest, |
455 const net::SSLPrivateKey::SignCallback& callback) { | 454 const net::SSLPrivateKey::SignCallback& callback) { |
456 DCHECK(thread_checker_.CalledOnValidThread()); | 455 DCHECK(thread_checker_.CalledOnValidThread()); |
457 | 456 |
458 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); | 457 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); |
459 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, | 458 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, |
460 hash, certificate, digest)) { | 459 hash, certificate, digest)) { |
461 sign_requests_.RemoveRequest(extension_id, sign_request_id, | 460 sign_requests_.RemoveRequest(extension_id, sign_request_id, |
462 nullptr /* callback */); | 461 nullptr /* callback */); |
463 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 462 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
464 } | 463 } |
465 } | 464 } |
466 | 465 |
467 } // namespace chromeos | 466 } // namespace chromeos |
OLD | NEW |