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 "net/ssl/ssl_platform_key.h" | 5 #include "net/ssl/ssl_platform_key.h" |
6 | 6 |
7 #include <openssl/ecdsa.h> | 7 #include <openssl/ecdsa.h> |
8 #include <openssl/obj.h> | 8 #include <openssl/obj.h> |
9 #include <openssl/rsa.h> | 9 #include <openssl/rsa.h> |
10 | 10 |
11 #include <Security/cssm.h> | 11 #include <Security/cssm.h> |
12 #include <Security/SecBase.h> | 12 #include <Security/SecBase.h> |
13 #include <Security/SecCertificate.h> | 13 #include <Security/SecCertificate.h> |
14 #include <Security/SecIdentity.h> | 14 #include <Security/SecIdentity.h> |
15 #include <Security/SecKey.h> | 15 #include <Security/SecKey.h> |
16 | 16 |
17 #include "base/lazy_instance.h" | |
18 #include "base/location.h" | 17 #include "base/location.h" |
19 #include "base/logging.h" | 18 #include "base/logging.h" |
20 #include "base/mac/mac_logging.h" | 19 #include "base/mac/mac_logging.h" |
21 #include "base/mac/scoped_cftyperef.h" | 20 #include "base/mac/scoped_cftyperef.h" |
22 #include "base/memory/scoped_policy.h" | 21 #include "base/memory/scoped_policy.h" |
23 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
24 #include "base/sequenced_task_runner.h" | 23 #include "base/sequenced_task_runner.h" |
25 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
26 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
27 #include "crypto/mac_security_services_lock.h" | 26 #include "crypto/mac_security_services_lock.h" |
28 #include "crypto/openssl_util.h" | 27 #include "crypto/openssl_util.h" |
29 #include "crypto/scoped_openssl_types.h" | 28 #include "crypto/scoped_openssl_types.h" |
30 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
31 #include "net/cert/x509_certificate.h" | 30 #include "net/cert/x509_certificate.h" |
| 31 #include "net/ssl/ssl_platform_key_task_runner.h" |
32 #include "net/ssl/ssl_private_key.h" | 32 #include "net/ssl/ssl_private_key.h" |
33 #include "net/ssl/threaded_ssl_private_key.h" | 33 #include "net/ssl/threaded_ssl_private_key.h" |
34 | 34 |
35 namespace net { | 35 namespace net { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 class ScopedCSSM_CC_HANDLE { | 39 class ScopedCSSM_CC_HANDLE { |
40 public: | 40 public: |
41 ScopedCSSM_CC_HANDLE() : handle_(0) {} | 41 ScopedCSSM_CC_HANDLE() : handle_(0) {} |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 private: | 212 private: |
213 base::ScopedCFTypeRef<SecKeyRef> key_; | 213 base::ScopedCFTypeRef<SecKeyRef> key_; |
214 const CSSM_KEY* cssm_key_; | 214 const CSSM_KEY* cssm_key_; |
215 | 215 |
216 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyMac); | 216 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyMac); |
217 }; | 217 }; |
218 | 218 |
219 } // namespace | 219 } // namespace |
220 | 220 |
221 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | 221 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( |
222 X509Certificate* certificate, | 222 X509Certificate* certificate) { |
223 scoped_refptr<base::SequencedTaskRunner> task_runner) { | |
224 // Look up the private key. | 223 // Look up the private key. |
225 base::ScopedCFTypeRef<SecKeyRef> private_key( | 224 base::ScopedCFTypeRef<SecKeyRef> private_key( |
226 FetchSecKeyRefForCertificate(certificate)); | 225 FetchSecKeyRefForCertificate(certificate)); |
227 if (!private_key) | 226 if (!private_key) |
228 return nullptr; | 227 return nullptr; |
229 | 228 |
230 const CSSM_KEY* cssm_key; | 229 const CSSM_KEY* cssm_key; |
231 OSStatus status = SecKeyGetCSSMKey(private_key.get(), &cssm_key); | 230 OSStatus status = SecKeyGetCSSMKey(private_key.get(), &cssm_key); |
232 if (status != noErr) | 231 if (status != noErr) |
233 return nullptr; | 232 return nullptr; |
234 | 233 |
235 if (cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_RSA && | 234 if (cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_RSA && |
236 cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_ECDSA) { | 235 cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_ECDSA) { |
237 LOG(ERROR) << "Unknown key type: " << cssm_key->KeyHeader.AlgorithmId; | 236 LOG(ERROR) << "Unknown key type: " << cssm_key->KeyHeader.AlgorithmId; |
238 return nullptr; | 237 return nullptr; |
239 } | 238 } |
240 return make_scoped_ptr(new ThreadedSSLPrivateKey( | 239 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
241 make_scoped_ptr(new SSLPlatformKeyMac(private_key.get(), cssm_key)), | 240 make_scoped_ptr(new SSLPlatformKeyMac(private_key.get(), cssm_key)), |
242 task_runner.Pass())); | 241 GetSSLPlatformKeyTaskRunner())); |
243 } | 242 } |
244 | 243 |
245 } // namespace net | 244 } // namespace net |
OLD | NEW |