| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 crypto::ScopedEVP_PKEY key_; | 96 crypto::ScopedEVP_PKEY key_; |
| 97 SSLPrivateKey::Type type_; | 97 SSLPrivateKey::Type type_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid); | 99 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 } // namespace | 102 } // namespace |
| 103 | 103 |
| 104 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | 104 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey(crypto::ScopedEVP_PKEY key) { |
| 105 X509Certificate* certificate, | |
| 106 scoped_refptr<base::SequencedTaskRunner> task_runner) { | |
| 107 crypto::ScopedEVP_PKEY key = | |
| 108 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey( | |
| 109 certificate); | |
| 110 if (!key) | 105 if (!key) |
| 111 return nullptr; | 106 return nullptr; |
| 112 | 107 |
| 113 SSLPrivateKey::Type type; | 108 SSLPrivateKey::Type type; |
| 114 switch (EVP_PKEY_id(key.get())) { | 109 switch (EVP_PKEY_id(key.get())) { |
| 115 case EVP_PKEY_RSA: | 110 case EVP_PKEY_RSA: |
| 116 type = SSLPrivateKey::Type::RSA; | 111 type = SSLPrivateKey::Type::RSA; |
| 117 break; | 112 break; |
| 118 case EVP_PKEY_EC: | 113 case EVP_PKEY_EC: |
| 119 type = SSLPrivateKey::Type::ECDSA; | 114 type = SSLPrivateKey::Type::ECDSA; |
| 120 break; | 115 break; |
| 121 default: | 116 default: |
| 122 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); | 117 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); |
| 123 return nullptr; | 118 return nullptr; |
| 124 } | 119 } |
| 125 return make_scoped_ptr(new ThreadedSSLPrivateKey( | 120 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
| 126 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), | 121 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), |
| 127 task_runner.Pass())); | 122 GetSSLPlatformKeyTaskRunner())); |
| 128 } | 123 } |
| 129 | 124 |
| 130 } // namespace net | 125 } // namespace net |
| OLD | NEW |