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))); |
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) {} |
154 | 132 |
155 CertificateProviderService::CertKeyProviderImpl::~CertKeyProviderImpl() {} | 133 void AcquirePrivateKey( |
| 134 const base::Callback<void(scoped_refptr<net::SSLPrivateKey>)>& |
| 135 private_key_callback) override; |
156 | 136 |
157 bool CertificateProviderService::CertKeyProviderImpl::GetCertificateKey( | 137 private: |
158 const net::X509Certificate& cert, | 138 scoped_refptr<net::SSLPrivateKey> AcquirePrivateKeyOnServiceThread( |
159 scoped_refptr<net::SSLPrivateKey>* private_key) { | 139 net::X509Certificate* cert); |
| 140 |
| 141 scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
| 142 // Must be dereferenced on |service_task_runner_| only. |
| 143 const base::WeakPtr<CertificateProviderService> service_; |
| 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(ClientCertIdentity); |
| 146 }; |
| 147 |
| 148 void CertificateProviderService::ClientCertIdentity::AcquirePrivateKey( |
| 149 const base::Callback<void(scoped_refptr<net::SSLPrivateKey>)>& |
| 150 private_key_callback) { |
| 151 // The caller is responsible for keeping the ClientCertIdentity alive until |
| 152 // |private_key_callback| is run, so it's safe to use Unretained here. |
| 153 if (base::PostTaskAndReplyWithResult( |
| 154 service_task_runner_.get(), FROM_HERE, |
| 155 base::Bind(&ClientCertIdentity::AcquirePrivateKeyOnServiceThread, |
| 156 base::Unretained(this), base::Unretained(certificate())), |
| 157 private_key_callback)) { |
| 158 return; |
| 159 } |
| 160 // If the task could not be posted, behave as if there was no key. |
| 161 private_key_callback.Run(nullptr); |
| 162 } |
| 163 |
| 164 scoped_refptr<net::SSLPrivateKey> CertificateProviderService:: |
| 165 ClientCertIdentity::AcquirePrivateKeyOnServiceThread( |
| 166 net::X509Certificate* cert) { |
| 167 if (!service_) |
| 168 return nullptr; |
| 169 |
160 bool is_currently_provided = false; | 170 bool is_currently_provided = false; |
161 CertificateInfo info; | 171 CertificateInfo info; |
162 std::string extension_id; | 172 std::string extension_id; |
163 certificate_map_->LookUpCertificate(cert, &is_currently_provided, &info, | 173 // TODO(mattm): can the ClientCertIdentity store a handle directly to the |
164 &extension_id); | 174 // extension instead of having to go through service_->certificate_map_ ? |
| 175 service_->certificate_map_.LookUpCertificate(*cert, &is_currently_provided, |
| 176 &info, &extension_id); |
165 if (!is_currently_provided) | 177 if (!is_currently_provided) |
166 return false; | 178 return nullptr; |
167 | 179 |
168 *private_key = | 180 return base::MakeRefCounted<SSLPrivateKey>(extension_id, info, |
169 new SSLPrivateKey(extension_id, info, service_task_runner_, service_); | 181 service_task_runner_, service_); |
170 | |
171 return true; | |
172 } | 182 } |
173 | 183 |
174 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( | 184 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( |
175 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 185 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
176 const base::WeakPtr<CertificateProviderService>& service) | 186 const base::WeakPtr<CertificateProviderService>& service) |
177 : service_task_runner_(service_task_runner), service_(service) {} | 187 : service_task_runner_(service_task_runner), service_(service) {} |
178 | 188 |
179 CertificateProviderService::CertificateProviderImpl:: | 189 CertificateProviderService::CertificateProviderImpl:: |
180 ~CertificateProviderImpl() {} | 190 ~CertificateProviderImpl() {} |
181 | 191 |
182 void CertificateProviderService::CertificateProviderImpl::GetCertificates( | 192 void CertificateProviderService::CertificateProviderImpl::GetCertificates( |
183 const base::Callback<void(const net::CertificateList&)>& callback) { | 193 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
184 const scoped_refptr<base::TaskRunner> source_task_runner = | 194 const scoped_refptr<base::TaskRunner> source_task_runner = |
185 base::ThreadTaskRunnerHandle::Get(); | 195 base::ThreadTaskRunnerHandle::Get(); |
186 const base::Callback<void(const net::CertificateList&)> | 196 const base::Callback<void(net::ClientCertIdentityList)> |
187 callback_from_service_thread = base::Bind(&PostCertificatesToTaskRunner, | 197 callback_from_service_thread = |
188 source_task_runner, callback); | 198 base::Bind(&PostIdentitiesToTaskRunner, source_task_runner, callback); |
189 | 199 |
190 service_task_runner_->PostTask( | 200 service_task_runner_->PostTask( |
191 FROM_HERE, base::Bind(&GetCertificatesOnServiceThread, service_, | 201 FROM_HERE, base::Bind(&GetCertificatesOnServiceThread, service_, |
192 callback_from_service_thread)); | 202 callback_from_service_thread)); |
193 } | 203 } |
194 | 204 |
195 std::unique_ptr<CertificateProvider> | 205 std::unique_ptr<CertificateProvider> |
196 CertificateProviderService::CertificateProviderImpl::Copy() { | 206 CertificateProviderService::CertificateProviderImpl::Copy() { |
197 return base::WrapUnique( | 207 return base::WrapUnique( |
198 new CertificateProviderImpl(service_task_runner_, service_)); | 208 new CertificateProviderImpl(service_task_runner_, service_)); |
199 } | 209 } |
200 | 210 |
201 // static | 211 // static |
202 void CertificateProviderService::CertificateProviderImpl:: | 212 void CertificateProviderService::CertificateProviderImpl:: |
203 GetCertificatesOnServiceThread( | 213 GetCertificatesOnServiceThread( |
204 const base::WeakPtr<CertificateProviderService>& service, | 214 const base::WeakPtr<CertificateProviderService>& service, |
205 const base::Callback<void(const net::CertificateList&)>& callback) { | 215 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
206 if (!service) { | 216 if (!service) { |
207 callback.Run(net::CertificateList()); | 217 callback.Run(net::ClientCertIdentityList()); |
208 return; | 218 return; |
209 } | 219 } |
210 service->GetCertificatesFromExtensions(callback); | 220 service->GetCertificatesFromExtensions(callback); |
211 } | 221 } |
212 | 222 |
213 CertificateProviderService::SSLPrivateKey::SSLPrivateKey( | 223 CertificateProviderService::SSLPrivateKey::SSLPrivateKey( |
214 const std::string& extension_id, | 224 const std::string& extension_id, |
215 const CertificateInfo& cert_info, | 225 const CertificateInfo& cert_info, |
216 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 226 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
217 const base::WeakPtr<CertificateProviderService>& service) | 227 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) { | 290 const std::vector<uint8_t>& signature) { |
281 DCHECK(thread_checker_.CalledOnValidThread()); | 291 DCHECK(thread_checker_.CalledOnValidThread()); |
282 callback.Run(error, signature); | 292 callback.Run(error, signature); |
283 } | 293 } |
284 | 294 |
285 CertificateProviderService::CertificateProviderService() | 295 CertificateProviderService::CertificateProviderService() |
286 : weak_factory_(this) {} | 296 : weak_factory_(this) {} |
287 | 297 |
288 CertificateProviderService::~CertificateProviderService() { | 298 CertificateProviderService::~CertificateProviderService() { |
289 DCHECK(thread_checker_.CalledOnValidThread()); | 299 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 } | 300 } |
299 | 301 |
300 void CertificateProviderService::SetDelegate( | 302 void CertificateProviderService::SetDelegate( |
301 std::unique_ptr<Delegate> delegate) { | 303 std::unique_ptr<Delegate> delegate) { |
302 DCHECK(thread_checker_.CalledOnValidThread()); | 304 DCHECK(thread_checker_.CalledOnValidThread()); |
303 DCHECK(!delegate_); | 305 DCHECK(!delegate_); |
304 DCHECK(delegate); | 306 DCHECK(delegate); |
305 | 307 |
306 delegate_ = std::move(delegate); | 308 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 } | 309 } |
312 | 310 |
313 bool CertificateProviderService::SetCertificatesProvidedByExtension( | 311 bool CertificateProviderService::SetCertificatesProvidedByExtension( |
314 const std::string& extension_id, | 312 const std::string& extension_id, |
315 int cert_request_id, | 313 int cert_request_id, |
316 const CertificateInfoList& certificate_infos) { | 314 const CertificateInfoList& certificate_infos) { |
317 DCHECK(thread_checker_.CalledOnValidThread()); | 315 DCHECK(thread_checker_.CalledOnValidThread()); |
318 | 316 |
319 bool completed = false; | 317 bool completed = false; |
320 if (!certificate_requests_.SetCertificates(extension_id, cert_request_id, | 318 if (!certificate_requests_.SetCertificates(extension_id, cert_request_id, |
321 certificate_infos, &completed)) { | 319 certificate_infos, &completed)) { |
322 DLOG(WARNING) << "Unexpected reply of extension " << extension_id | 320 DLOG(WARNING) << "Unexpected reply of extension " << extension_id |
323 << " to request " << cert_request_id; | 321 << " to request " << cert_request_id; |
324 return false; | 322 return false; |
325 } | 323 } |
326 if (completed) { | 324 if (completed) { |
327 std::map<std::string, CertificateInfoList> certificates; | 325 std::map<std::string, CertificateInfoList> certificates; |
328 base::Callback<void(const net::CertificateList&)> callback; | 326 base::Callback<void(net::ClientCertIdentityList)> callback; |
329 certificate_requests_.RemoveRequest(cert_request_id, &certificates, | 327 certificate_requests_.RemoveRequest(cert_request_id, &certificates, |
330 &callback); | 328 &callback); |
331 UpdateCertificatesAndRun(certificates, callback); | 329 UpdateCertificatesAndRun(certificates, callback); |
332 } | 330 } |
333 return true; | 331 return true; |
334 } | 332 } |
335 | 333 |
336 void CertificateProviderService::ReplyToSignRequest( | 334 void CertificateProviderService::ReplyToSignRequest( |
337 const std::string& extension_id, | 335 const std::string& extension_id, |
338 int sign_request_id, | 336 int sign_request_id, |
(...skipping 30 matching lines...) Expand all Loading... |
369 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); | 367 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr()); |
370 } | 368 } |
371 | 369 |
372 void CertificateProviderService::OnExtensionUnloaded( | 370 void CertificateProviderService::OnExtensionUnloaded( |
373 const std::string& extension_id) { | 371 const std::string& extension_id) { |
374 DCHECK(thread_checker_.CalledOnValidThread()); | 372 DCHECK(thread_checker_.CalledOnValidThread()); |
375 | 373 |
376 for (const int cert_request_id : | 374 for (const int cert_request_id : |
377 certificate_requests_.DropExtension(extension_id)) { | 375 certificate_requests_.DropExtension(extension_id)) { |
378 std::map<std::string, CertificateInfoList> certificates; | 376 std::map<std::string, CertificateInfoList> certificates; |
379 base::Callback<void(const net::CertificateList&)> callback; | 377 base::Callback<void(net::ClientCertIdentityList)> callback; |
380 certificate_requests_.RemoveRequest(cert_request_id, &certificates, | 378 certificate_requests_.RemoveRequest(cert_request_id, &certificates, |
381 &callback); | 379 &callback); |
382 UpdateCertificatesAndRun(certificates, callback); | 380 UpdateCertificatesAndRun(certificates, callback); |
383 } | 381 } |
384 | 382 |
385 certificate_map_.RemoveExtension(extension_id); | 383 certificate_map_.RemoveExtension(extension_id); |
386 | 384 |
387 for (auto callback : sign_requests_.RemoveAllRequests(extension_id)) | 385 for (auto callback : sign_requests_.RemoveAllRequests(extension_id)) |
388 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 386 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
389 | 387 |
390 pin_dialog_manager_.ExtensionUnloaded(extension_id); | 388 pin_dialog_manager_.ExtensionUnloaded(extension_id); |
391 } | 389 } |
392 | 390 |
393 void CertificateProviderService::GetCertificatesFromExtensions( | 391 void CertificateProviderService::GetCertificatesFromExtensions( |
394 const base::Callback<void(const net::CertificateList&)>& callback) { | 392 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
395 DCHECK(thread_checker_.CalledOnValidThread()); | 393 DCHECK(thread_checker_.CalledOnValidThread()); |
396 | 394 |
397 const std::vector<std::string> provider_extensions( | 395 const std::vector<std::string> provider_extensions( |
398 delegate_->CertificateProviderExtensions()); | 396 delegate_->CertificateProviderExtensions()); |
399 | 397 |
400 if (provider_extensions.empty()) { | 398 if (provider_extensions.empty()) { |
401 DVLOG(2) << "No provider extensions left, clear all certificates."; | 399 DVLOG(2) << "No provider extensions left, clear all certificates."; |
402 UpdateCertificatesAndRun(std::map<std::string, CertificateInfoList>(), | 400 UpdateCertificatesAndRun(std::map<std::string, CertificateInfoList>(), |
403 callback); | 401 callback); |
404 return; | 402 return; |
405 } | 403 } |
406 | 404 |
407 const int cert_request_id = certificate_requests_.AddRequest( | 405 const int cert_request_id = certificate_requests_.AddRequest( |
408 provider_extensions, callback, | 406 provider_extensions, callback, |
409 base::Bind(&CertificateProviderService::TerminateCertificateRequest, | 407 base::Bind(&CertificateProviderService::TerminateCertificateRequest, |
410 base::Unretained(this))); | 408 base::Unretained(this))); |
411 | 409 |
412 DVLOG(2) << "Start certificate request " << cert_request_id; | 410 DVLOG(2) << "Start certificate request " << cert_request_id; |
413 delegate_->BroadcastCertificateRequest(cert_request_id); | 411 delegate_->BroadcastCertificateRequest(cert_request_id); |
414 } | 412 } |
415 | 413 |
416 void CertificateProviderService::UpdateCertificatesAndRun( | 414 void CertificateProviderService::UpdateCertificatesAndRun( |
417 const std::map<std::string, CertificateInfoList>& extension_to_certificates, | 415 const std::map<std::string, CertificateInfoList>& extension_to_certificates, |
418 const base::Callback<void(const net::CertificateList&)>& callback) { | 416 const base::Callback<void(net::ClientCertIdentityList)>& callback) { |
419 DCHECK(thread_checker_.CalledOnValidThread()); | 417 DCHECK(thread_checker_.CalledOnValidThread()); |
420 | 418 |
421 // Extensions are removed from the service's state when they're unloaded. | 419 // Extensions are removed from the service's state when they're unloaded. |
422 // Any remaining extension is assumed to be enabled. | 420 // Any remaining extension is assumed to be enabled. |
423 certificate_map_.Update(extension_to_certificates); | 421 certificate_map_.Update(extension_to_certificates); |
424 | 422 |
425 net::CertificateList all_certs; | 423 net::ClientCertIdentityList all_certs; |
426 for (const auto& entry : extension_to_certificates) { | 424 for (const auto& entry : extension_to_certificates) { |
427 for (const CertificateInfo& cert_info : entry.second) | 425 for (const CertificateInfo& cert_info : entry.second) |
428 all_certs.push_back(cert_info.certificate); | 426 all_certs.push_back(base::MakeUnique<ClientCertIdentity>( |
| 427 cert_info.certificate, base::ThreadTaskRunnerHandle::Get(), |
| 428 weak_factory_.GetWeakPtr())); |
429 } | 429 } |
430 | 430 |
431 callback.Run(all_certs); | 431 callback.Run(std::move(all_certs)); |
432 } | 432 } |
433 | 433 |
434 void CertificateProviderService::TerminateCertificateRequest( | 434 void CertificateProviderService::TerminateCertificateRequest( |
435 int cert_request_id) { | 435 int cert_request_id) { |
436 DCHECK(thread_checker_.CalledOnValidThread()); | 436 DCHECK(thread_checker_.CalledOnValidThread()); |
437 | 437 |
438 std::map<std::string, CertificateInfoList> certificates; | 438 std::map<std::string, CertificateInfoList> certificates; |
439 base::Callback<void(const net::CertificateList&)> callback; | 439 base::Callback<void(net::ClientCertIdentityList)> callback; |
440 if (!certificate_requests_.RemoveRequest(cert_request_id, &certificates, | 440 if (!certificate_requests_.RemoveRequest(cert_request_id, &certificates, |
441 &callback)) { | 441 &callback)) { |
442 DLOG(WARNING) << "Request id " << cert_request_id << " unknown."; | 442 DLOG(WARNING) << "Request id " << cert_request_id << " unknown."; |
443 return; | 443 return; |
444 } | 444 } |
445 | 445 |
446 DVLOG(1) << "Time out certificate request " << cert_request_id; | 446 DVLOG(1) << "Time out certificate request " << cert_request_id; |
447 UpdateCertificatesAndRun(certificates, callback); | 447 UpdateCertificatesAndRun(certificates, callback); |
448 } | 448 } |
449 | 449 |
450 void CertificateProviderService::RequestSignatureFromExtension( | 450 void CertificateProviderService::RequestSignatureFromExtension( |
451 const std::string& extension_id, | 451 const std::string& extension_id, |
452 const scoped_refptr<net::X509Certificate>& certificate, | 452 const scoped_refptr<net::X509Certificate>& certificate, |
453 net::SSLPrivateKey::Hash hash, | 453 net::SSLPrivateKey::Hash hash, |
454 const std::string& digest, | 454 const std::string& digest, |
455 const net::SSLPrivateKey::SignCallback& callback) { | 455 const net::SSLPrivateKey::SignCallback& callback) { |
456 DCHECK(thread_checker_.CalledOnValidThread()); | 456 DCHECK(thread_checker_.CalledOnValidThread()); |
457 | 457 |
458 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); | 458 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); |
459 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, | 459 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, |
460 hash, certificate, digest)) { | 460 hash, certificate, digest)) { |
461 sign_requests_.RemoveRequest(extension_id, sign_request_id, | 461 sign_requests_.RemoveRequest(extension_id, sign_request_id, |
462 nullptr /* callback */); | 462 nullptr /* callback */); |
463 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 463 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
464 } | 464 } |
465 } | 465 } |
466 | 466 |
467 } // namespace chromeos | 467 } // namespace chromeos |
OLD | NEW |