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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 private: | 206 private: |
207 base::ScopedCFTypeRef<SecKeyRef> key_; | 207 base::ScopedCFTypeRef<SecKeyRef> key_; |
208 const CSSM_KEY* cssm_key_; | 208 const CSSM_KEY* cssm_key_; |
209 | 209 |
210 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyMac); | 210 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyMac); |
211 }; | 211 }; |
212 | 212 |
213 } // namespace | 213 } // namespace |
214 | 214 |
215 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | 215 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( |
216 X509Certificate* certificate, | 216 X509Certificate* certificate) { |
217 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 217 if (!certificate) { |
| 218 return nullptr; |
| 219 } |
| 220 |
218 // Look up the private key. | 221 // Look up the private key. |
219 base::ScopedCFTypeRef<SecKeyRef> private_key( | 222 base::ScopedCFTypeRef<SecKeyRef> private_key( |
220 FetchSecKeyRefForCertificate(certificate)); | 223 FetchSecKeyRefForCertificate(certificate)); |
221 if (!private_key) | 224 if (!private_key) |
222 return nullptr; | 225 return nullptr; |
223 | 226 |
224 const CSSM_KEY* cssm_key; | 227 const CSSM_KEY* cssm_key; |
225 OSStatus status = SecKeyGetCSSMKey(private_key.get(), &cssm_key); | 228 OSStatus status = SecKeyGetCSSMKey(private_key.get(), &cssm_key); |
226 if (status != noErr) | 229 if (status != noErr) |
227 return nullptr; | 230 return nullptr; |
228 | 231 |
229 if (cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_RSA && | 232 if (cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_RSA && |
230 cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_ECDSA) { | 233 cssm_key->KeyHeader.AlgorithmId != CSSM_ALGID_ECDSA) { |
231 LOG(ERROR) << "Unknown key type: " << cssm_key->KeyHeader.AlgorithmId; | 234 LOG(ERROR) << "Unknown key type: " << cssm_key->KeyHeader.AlgorithmId; |
232 return nullptr; | 235 return nullptr; |
233 } | 236 } |
234 return make_scoped_ptr(new ThreadedSSLPrivateKey( | 237 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
235 make_scoped_ptr(new SSLPlatformKeyMac(private_key.get(), cssm_key)), | 238 make_scoped_ptr(new SSLPlatformKeyMac(private_key.get(), cssm_key)), |
236 task_runner.Pass())); | 239 GetSSLPlatformKeyTaskRunner())); |
237 } | 240 } |
238 | 241 |
239 } // namespace net | 242 } // namespace net |
OLD | NEW |