| 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_test.h" |
| 6 | 6 |
| 7 #include <openssl/digest.h> | 7 #include <openssl/digest.h> |
| 8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.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" | |
| 16 #include "net/ssl/ssl_platform_key_task_runner.h" | 15 #include "net/ssl/ssl_platform_key_task_runner.h" |
| 17 #include "net/ssl/ssl_private_key.h" | 16 #include "net/ssl/ssl_private_key.h" |
| 18 #include "net/ssl/threaded_ssl_private_key.h" | 17 #include "net/ssl/threaded_ssl_private_key.h" |
| 19 | 18 |
| 20 namespace net { | 19 namespace net { |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate { | 23 class SSLPlatformKeyTest : public ThreadedSSLPrivateKey::Delegate { |
| 25 public: | 24 public: |
| 26 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) | 25 SSLPlatformKeyTest(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) |
| 27 : key_(std::move(key)), type_(type) {} | 26 : key_(std::move(key)), type_(type) {} |
| 28 | 27 |
| 29 ~SSLPlatformKeyAndroid() override {} | 28 ~SSLPlatformKeyTest() override {} |
| 30 | 29 |
| 31 SSLPrivateKey::Type GetType() override { return type_; } | 30 SSLPrivateKey::Type GetType() override { return type_; } |
| 32 | 31 |
| 33 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override { | 32 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override { |
| 34 static const SSLPrivateKey::Hash kHashes[] = { | 33 static const SSLPrivateKey::Hash kHashes[] = { |
| 35 SSLPrivateKey::Hash::SHA512, SSLPrivateKey::Hash::SHA384, | 34 SSLPrivateKey::Hash::SHA512, SSLPrivateKey::Hash::SHA384, |
| 36 SSLPrivateKey::Hash::SHA256, SSLPrivateKey::Hash::SHA1}; | 35 SSLPrivateKey::Hash::SHA256, SSLPrivateKey::Hash::SHA1}; |
| 37 return std::vector<SSLPrivateKey::Hash>(kHashes, | 36 return std::vector<SSLPrivateKey::Hash>(kHashes, |
| 38 kHashes + arraysize(kHashes)); | 37 kHashes + arraysize(kHashes)); |
| 39 } | 38 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 92 |
| 94 signature->resize(sig_len); | 93 signature->resize(sig_len); |
| 95 | 94 |
| 96 return OK; | 95 return OK; |
| 97 } | 96 } |
| 98 | 97 |
| 99 private: | 98 private: |
| 100 crypto::ScopedEVP_PKEY key_; | 99 crypto::ScopedEVP_PKEY key_; |
| 101 SSLPrivateKey::Type type_; | 100 SSLPrivateKey::Type type_; |
| 102 | 101 |
| 103 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyAndroid); | 102 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyTest); |
| 104 }; | 103 }; |
| 105 | 104 |
| 105 } // namespace |
| 106 |
| 106 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey(crypto::ScopedEVP_PKEY key) { | 107 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey(crypto::ScopedEVP_PKEY key) { |
| 107 if (!key) | 108 if (!key) |
| 108 return nullptr; | 109 return nullptr; |
| 109 | 110 |
| 110 SSLPrivateKey::Type type; | 111 SSLPrivateKey::Type type; |
| 111 switch (EVP_PKEY_id(key.get())) { | 112 switch (EVP_PKEY_id(key.get())) { |
| 112 case EVP_PKEY_RSA: | 113 case EVP_PKEY_RSA: |
| 113 type = SSLPrivateKey::Type::RSA; | 114 type = SSLPrivateKey::Type::RSA; |
| 114 break; | 115 break; |
| 115 case EVP_PKEY_EC: | 116 case EVP_PKEY_EC: |
| 116 type = SSLPrivateKey::Type::ECDSA; | 117 type = SSLPrivateKey::Type::ECDSA; |
| 117 break; | 118 break; |
| 118 default: | 119 default: |
| 119 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); | 120 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); |
| 120 return nullptr; | 121 return nullptr; |
| 121 } | 122 } |
| 122 return make_scoped_refptr(new ThreadedSSLPrivateKey( | 123 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
| 123 make_scoped_ptr(new SSLPlatformKeyAndroid(std::move(key), type)), | 124 make_scoped_ptr(new SSLPlatformKeyTest(std::move(key), type)), |
| 124 GetSSLPlatformKeyTaskRunner())); | 125 GetSSLPlatformKeyTaskRunner())); |
| 125 } | 126 } |
| 126 | 127 |
| 127 } // namespace | |
| 128 | |
| 129 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( | |
| 130 X509Certificate* certificate) { | |
| 131 crypto::ScopedEVP_PKEY key = | |
| 132 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey( | |
| 133 certificate); | |
| 134 return WrapOpenSSLPrivateKey(std::move(key)); | |
| 135 } | |
| 136 | |
| 137 } // namespace net | 128 } // namespace net |
| OLD | NEW |