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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 certificate_provider::ThreadSafeCertificateMap* certificate_map) | 144 certificate_provider::ThreadSafeCertificateMap* certificate_map) |
145 : service_task_runner_(service_task_runner), | 145 : service_task_runner_(service_task_runner), |
146 service_(service), | 146 service_(service), |
147 certificate_map_(certificate_map) {} | 147 certificate_map_(certificate_map) {} |
148 | 148 |
149 CertificateProviderService::CertKeyProviderImpl::~CertKeyProviderImpl() {} | 149 CertificateProviderService::CertKeyProviderImpl::~CertKeyProviderImpl() {} |
150 | 150 |
151 bool CertificateProviderService::CertKeyProviderImpl::GetCertificateKey( | 151 bool CertificateProviderService::CertKeyProviderImpl::GetCertificateKey( |
152 const net::X509Certificate& cert, | 152 const net::X509Certificate& cert, |
153 scoped_ptr<net::SSLPrivateKey>* private_key) { | 153 scoped_ptr<net::SSLPrivateKey>* private_key) { |
| 154 bool is_currently_provided = false; |
154 CertificateInfo info; | 155 CertificateInfo info; |
155 std::string extension_id; | 156 std::string extension_id; |
156 if (!certificate_map_->LookUpCertificate(cert, &info, &extension_id)) | 157 certificate_map_->LookUpCertificate(cert, &is_currently_provided, &info, |
| 158 &extension_id); |
| 159 if (!is_currently_provided) |
157 return false; | 160 return false; |
158 | 161 |
159 private_key->reset( | 162 private_key->reset( |
160 new SSLPrivateKey(extension_id, info, service_task_runner_, service_)); | 163 new SSLPrivateKey(extension_id, info, service_task_runner_, service_)); |
161 return true; | 164 return true; |
162 } | 165 } |
163 | 166 |
164 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( | 167 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( |
165 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 168 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
166 const base::WeakPtr<CertificateProviderService>& service) | 169 const base::WeakPtr<CertificateProviderService>& service) |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 if (!sign_requests_.RemoveRequest(extension_id, sign_request_id, &callback)) { | 346 if (!sign_requests_.RemoveRequest(extension_id, sign_request_id, &callback)) { |
344 LOG(ERROR) << "request id unknown."; | 347 LOG(ERROR) << "request id unknown."; |
345 // Maybe multiple replies to the same request. | 348 // Maybe multiple replies to the same request. |
346 return; | 349 return; |
347 } | 350 } |
348 | 351 |
349 const net::Error error_code = signature.empty() ? net::ERR_FAILED : net::OK; | 352 const net::Error error_code = signature.empty() ? net::ERR_FAILED : net::OK; |
350 callback.Run(error_code, signature); | 353 callback.Run(error_code, signature); |
351 } | 354 } |
352 | 355 |
| 356 bool CertificateProviderService::LookUpCertificate( |
| 357 const net::X509Certificate& cert, |
| 358 bool* has_extension, |
| 359 std::string* extension_id) { |
| 360 DCHECK(thread_checker_.CalledOnValidThread()); |
| 361 |
| 362 CertificateInfo unused_info; |
| 363 return certificate_map_.LookUpCertificate(cert, has_extension, &unused_info, |
| 364 extension_id); |
| 365 } |
| 366 |
353 scoped_ptr<CertificateProvider> | 367 scoped_ptr<CertificateProvider> |
354 CertificateProviderService::CreateCertificateProvider() { | 368 CertificateProviderService::CreateCertificateProvider() { |
355 DCHECK(thread_checker_.CalledOnValidThread()); | 369 DCHECK(thread_checker_.CalledOnValidThread()); |
356 | 370 |
357 return make_scoped_ptr(new CertificateProviderImpl( | 371 return make_scoped_ptr(new CertificateProviderImpl( |
358 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr())); | 372 base::ThreadTaskRunnerHandle::Get(), weak_factory_.GetWeakPtr())); |
359 } | 373 } |
360 | 374 |
361 void CertificateProviderService::OnExtensionUnloaded( | 375 void CertificateProviderService::OnExtensionUnloaded( |
362 const std::string& extension_id) { | 376 const std::string& extension_id) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); | 459 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); |
446 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, | 460 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, |
447 hash, certificate, digest)) { | 461 hash, certificate, digest)) { |
448 sign_requests_.RemoveRequest(extension_id, sign_request_id, | 462 sign_requests_.RemoveRequest(extension_id, sign_request_id, |
449 nullptr /* callback */); | 463 nullptr /* callback */); |
450 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 464 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
451 } | 465 } |
452 } | 466 } |
453 | 467 |
454 } // namespace chromeos | 468 } // namespace chromeos |
OLD | NEW |