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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 // |certificate_map| must outlive this provider. |service| must be | 45 // |certificate_map| must outlive this provider. |service| must be |
46 // dereferenceable on |service_task_runner|. | 46 // dereferenceable on |service_task_runner|. |
47 // This provider may be accessed from any thread. Methods and destructor must | 47 // This provider may be accessed from any thread. Methods and destructor must |
48 // never be called concurrently. | 48 // never be called concurrently. |
49 CertKeyProviderImpl( | 49 CertKeyProviderImpl( |
50 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 50 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
51 const base::WeakPtr<CertificateProviderService>& service, | 51 const base::WeakPtr<CertificateProviderService>& service, |
52 certificate_provider::ThreadSafeCertificateMap* certificate_map); | 52 certificate_provider::ThreadSafeCertificateMap* certificate_map); |
53 ~CertKeyProviderImpl() override; | 53 ~CertKeyProviderImpl() override; |
54 | 54 |
55 bool GetCertificateKey(const net::X509Certificate& cert, | 55 bool GetCertificateKey( |
56 scoped_ptr<net::SSLPrivateKey>* private_key) override; | 56 const net::X509Certificate& cert, |
57 scoped_refptr<net::SSLPrivateKey>* private_key) override; | |
57 | 58 |
58 private: | 59 private: |
59 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; | 60 const scoped_refptr<base::SequencedTaskRunner> service_task_runner_; |
60 // Must be dereferenced on |service_task_runner_| only. | 61 // Must be dereferenced on |service_task_runner_| only. |
61 base::WeakPtr<CertificateProviderService> service_; | 62 base::WeakPtr<CertificateProviderService> service_; |
62 certificate_provider::ThreadSafeCertificateMap* const certificate_map_; | 63 certificate_provider::ThreadSafeCertificateMap* const certificate_map_; |
63 | 64 |
64 DISALLOW_COPY_AND_ASSIGN(CertKeyProviderImpl); | 65 DISALLOW_COPY_AND_ASSIGN(CertKeyProviderImpl); |
65 }; | 66 }; |
66 | 67 |
(...skipping 30 matching lines...) Expand all Loading... | |
97 // Objects of this class must be used on a single thread. Any thread is allowed. | 98 // Objects of this class must be used on a single thread. Any thread is allowed. |
98 class CertificateProviderService::SSLPrivateKey : public net::SSLPrivateKey { | 99 class CertificateProviderService::SSLPrivateKey : public net::SSLPrivateKey { |
99 public: | 100 public: |
100 // Any calls back to |service| will be posted to |service_task_runner|. | 101 // Any calls back to |service| will be posted to |service_task_runner|. |
101 // |service| must be dereferenceable on |service_task_runner|. | 102 // |service| must be dereferenceable on |service_task_runner|. |
102 SSLPrivateKey( | 103 SSLPrivateKey( |
103 const std::string& extension_id, | 104 const std::string& extension_id, |
104 const CertificateInfo& cert_info, | 105 const CertificateInfo& cert_info, |
105 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 106 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
106 const base::WeakPtr<CertificateProviderService>& service); | 107 const base::WeakPtr<CertificateProviderService>& service); |
107 ~SSLPrivateKey() override; | |
108 | 108 |
109 // net::SSLPrivateKey: | 109 // net::SSLPrivateKey: |
110 Type GetType() override; | 110 Type GetType() override; |
111 bool SupportsHash(Hash hash) override; | 111 bool SupportsHash(Hash hash) override; |
112 size_t GetMaxSignatureLengthInBytes() override; | 112 size_t GetMaxSignatureLengthInBytes() override; |
113 void SignDigest(Hash hash, | 113 void SignDigest(Hash hash, |
114 const base::StringPiece& input, | 114 const base::StringPiece& input, |
115 const SignCallback& callback) override; | 115 const SignCallback& callback) override; |
116 | 116 |
117 private: | 117 private: |
118 ~SSLPrivateKey() override; | |
119 | |
118 static void SignDigestOnServiceTaskRunner( | 120 static void SignDigestOnServiceTaskRunner( |
119 const base::WeakPtr<CertificateProviderService>& service, | 121 const base::WeakPtr<CertificateProviderService>& service, |
120 const std::string& extension_id, | 122 const std::string& extension_id, |
121 const scoped_refptr<net::X509Certificate>& certificate, | 123 const scoped_refptr<net::X509Certificate>& certificate, |
122 Hash hash, | 124 Hash hash, |
123 const std::string& input, | 125 const std::string& input, |
124 const SignCallback& callback); | 126 const SignCallback& callback); |
125 | 127 |
126 void DidSignDigest(const SignCallback& callback, | 128 void DidSignDigest(const SignCallback& callback, |
127 net::Error error, | 129 net::Error error, |
(...skipping 15 matching lines...) Expand all Loading... | |
143 const base::WeakPtr<CertificateProviderService>& service, | 145 const base::WeakPtr<CertificateProviderService>& service, |
144 certificate_provider::ThreadSafeCertificateMap* certificate_map) | 146 certificate_provider::ThreadSafeCertificateMap* certificate_map) |
145 : service_task_runner_(service_task_runner), | 147 : service_task_runner_(service_task_runner), |
146 service_(service), | 148 service_(service), |
147 certificate_map_(certificate_map) {} | 149 certificate_map_(certificate_map) {} |
148 | 150 |
149 CertificateProviderService::CertKeyProviderImpl::~CertKeyProviderImpl() {} | 151 CertificateProviderService::CertKeyProviderImpl::~CertKeyProviderImpl() {} |
150 | 152 |
151 bool CertificateProviderService::CertKeyProviderImpl::GetCertificateKey( | 153 bool CertificateProviderService::CertKeyProviderImpl::GetCertificateKey( |
152 const net::X509Certificate& cert, | 154 const net::X509Certificate& cert, |
153 scoped_ptr<net::SSLPrivateKey>* private_key) { | 155 scoped_refptr<net::SSLPrivateKey>* private_key) { |
154 bool is_currently_provided = false; | 156 bool is_currently_provided = false; |
155 CertificateInfo info; | 157 CertificateInfo info; |
156 std::string extension_id; | 158 std::string extension_id; |
157 certificate_map_->LookUpCertificate(cert, &is_currently_provided, &info, | 159 certificate_map_->LookUpCertificate(cert, &is_currently_provided, &info, |
158 &extension_id); | 160 &extension_id); |
159 if (!is_currently_provided) | 161 if (!is_currently_provided) |
160 return false; | 162 return false; |
161 | 163 |
162 private_key->reset( | 164 scoped_refptr<net::SSLPrivateKey> new_key = |
163 new SSLPrivateKey(extension_id, info, service_task_runner_, service_)); | 165 new SSLPrivateKey(extension_id, info, service_task_runner_, service_); |
166 private_key->swap(new_key); | |
167 | |
164 return true; | 168 return true; |
165 } | 169 } |
166 | 170 |
167 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( | 171 CertificateProviderService::CertificateProviderImpl::CertificateProviderImpl( |
168 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, | 172 const scoped_refptr<base::SequencedTaskRunner>& service_task_runner, |
169 const base::WeakPtr<CertificateProviderService>& service) | 173 const base::WeakPtr<CertificateProviderService>& service) |
170 : service_task_runner_(service_task_runner), service_(service) {} | 174 : service_task_runner_(service_task_runner), service_(service) {} |
171 | 175 |
172 CertificateProviderService::CertificateProviderImpl:: | 176 CertificateProviderService::CertificateProviderImpl:: |
173 ~CertificateProviderImpl() {} | 177 ~CertificateProviderImpl() {} |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 service_task_runner_(service_task_runner), | 217 service_task_runner_(service_task_runner), |
214 service_(service), | 218 service_(service), |
215 weak_factory_(this) { | 219 weak_factory_(this) { |
216 // This constructor is called on |service_task_runner|. Only subsequent calls | 220 // This constructor is called on |service_task_runner|. Only subsequent calls |
217 // to member functions have to be on a common thread. | 221 // to member functions have to be on a common thread. |
218 thread_checker_.DetachFromThread(); | 222 thread_checker_.DetachFromThread(); |
219 } | 223 } |
220 | 224 |
221 CertificateProviderService::SSLPrivateKey::~SSLPrivateKey() { | 225 CertificateProviderService::SSLPrivateKey::~SSLPrivateKey() { |
222 DCHECK(thread_checker_.CalledOnValidThread()); | 226 DCHECK(thread_checker_.CalledOnValidThread()); |
223 } | 227 } |
davidben
2015/09/25 20:10:11
Reorder to match declaration
svaldez
2015/09/28 16:54:52
Done.
| |
224 | 228 |
225 CertificateProviderService::SSLPrivateKey::Type | 229 CertificateProviderService::SSLPrivateKey::Type |
226 CertificateProviderService::SSLPrivateKey::GetType() { | 230 CertificateProviderService::SSLPrivateKey::GetType() { |
227 DCHECK(thread_checker_.CalledOnValidThread()); | 231 DCHECK(thread_checker_.CalledOnValidThread()); |
228 return cert_info_.type; | 232 return cert_info_.type; |
229 } | 233 } |
230 | 234 |
231 bool CertificateProviderService::SSLPrivateKey::SupportsHash(Hash hash) { | 235 bool CertificateProviderService::SSLPrivateKey::SupportsHash(Hash hash) { |
232 DCHECK(thread_checker_.CalledOnValidThread()); | 236 DCHECK(thread_checker_.CalledOnValidThread()); |
233 return ContainsValue(cert_info_.supported_hashes, hash); | 237 return ContainsValue(cert_info_.supported_hashes, hash); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); | 463 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); |
460 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, | 464 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, |
461 hash, certificate, digest)) { | 465 hash, certificate, digest)) { |
462 sign_requests_.RemoveRequest(extension_id, sign_request_id, | 466 sign_requests_.RemoveRequest(extension_id, sign_request_id, |
463 nullptr /* callback */); | 467 nullptr /* callback */); |
464 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 468 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
465 } | 469 } |
466 } | 470 } |
467 | 471 |
468 } // namespace chromeos | 472 } // namespace chromeos |
OLD | NEW |