| 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/digest.h> | 7 #include <openssl/digest.h> |
| 8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "crypto/scoped_openssl_types.h" | 13 #include "crypto/scoped_openssl_types.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "net/ssl/openssl_client_key_store.h" | 15 #include "net/ssl/ssl_platform_key_task_runner.h" |
| 16 #include "net/ssl/ssl_private_key.h" | 16 #include "net/ssl/ssl_private_key.h" |
| 17 #include "net/ssl/threaded_ssl_private_key.h" | 17 #include "net/ssl/threaded_ssl_private_key.h" |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate { | 23 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate { |
| 24 public: | 24 public: |
| 25 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) | 25 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 crypto::ScopedEVP_PKEY key_; | 102 crypto::ScopedEVP_PKEY key_; |
| 103 SSLPrivateKey::Type type_; | 103 SSLPrivateKey::Type type_; |
| 104 | 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid); | 105 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 } // namespace | 108 } // namespace |
| 109 | 109 |
| 110 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | 110 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey(crypto::ScopedEVP_PKEY key) { |
| 111 X509Certificate* certificate, | |
| 112 scoped_refptr<base::SequencedTaskRunner> task_runner) { | |
| 113 crypto::ScopedEVP_PKEY key = | |
| 114 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey( | |
| 115 certificate); | |
| 116 if (!key) | 111 if (!key) |
| 117 return nullptr; | 112 return nullptr; |
| 118 | 113 |
| 119 SSLPrivateKey::Type type; | 114 SSLPrivateKey::Type type; |
| 120 switch (EVP_PKEY_id(key.get())) { | 115 switch (EVP_PKEY_id(key.get())) { |
| 121 case EVP_PKEY_RSA: | 116 case EVP_PKEY_RSA: |
| 122 type = SSLPrivateKey::Type::RSA; | 117 type = SSLPrivateKey::Type::RSA; |
| 123 break; | 118 break; |
| 124 case EVP_PKEY_EC: | 119 case EVP_PKEY_EC: |
| 125 type = SSLPrivateKey::Type::ECDSA; | 120 type = SSLPrivateKey::Type::ECDSA; |
| 126 break; | 121 break; |
| 127 default: | 122 default: |
| 128 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); | 123 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); |
| 129 return nullptr; | 124 return nullptr; |
| 130 } | 125 } |
| 131 return make_scoped_ptr(new ThreadedSSLPrivateKey( | 126 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
| 132 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), | 127 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), |
| 133 task_runner.Pass())); | 128 GetSSLPlatformKeyTaskRunner())); |
| 134 } | 129 } |
| 135 | 130 |
| 136 } // namespace net | 131 } // namespace net |
| OLD | NEW |