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 #include <utility> |
9 | 10 |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "crypto/scoped_openssl_types.h" | 13 #include "crypto/scoped_openssl_types.h" |
13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
14 #include "net/ssl/openssl_client_key_store.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_platform_key_task_runner.h" |
16 #include "net/ssl/ssl_private_key.h" | 17 #include "net/ssl/ssl_private_key.h" |
17 #include "net/ssl/threaded_ssl_private_key.h" | 18 #include "net/ssl/threaded_ssl_private_key.h" |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate { | 24 class SSLPlatformKeyAndroid : public ThreadedSSLPrivateKey::Delegate { |
24 public: | 25 public: |
25 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) | 26 SSLPlatformKeyAndroid(crypto::ScopedEVP_PKEY key, SSLPrivateKey::Type type) |
26 : key_(key.Pass()), type_(type) {} | 27 : key_(std::move(key)), type_(type) {} |
27 | 28 |
28 ~SSLPlatformKeyAndroid() override {} | 29 ~SSLPlatformKeyAndroid() override {} |
29 | 30 |
30 SSLPrivateKey::Type GetType() override { return type_; } | 31 SSLPrivateKey::Type GetType() override { return type_; } |
31 | 32 |
32 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override { | 33 std::vector<SSLPrivateKey::Hash> GetDigestPreferences() override { |
33 static const SSLPrivateKey::Hash kHashes[] = { | 34 static const SSLPrivateKey::Hash kHashes[] = { |
34 SSLPrivateKey::Hash::SHA512, SSLPrivateKey::Hash::SHA384, | 35 SSLPrivateKey::Hash::SHA512, SSLPrivateKey::Hash::SHA384, |
35 SSLPrivateKey::Hash::SHA256, SSLPrivateKey::Hash::SHA1}; | 36 SSLPrivateKey::Hash::SHA256, SSLPrivateKey::Hash::SHA1}; |
36 return std::vector<SSLPrivateKey::Hash>(kHashes, | 37 return std::vector<SSLPrivateKey::Hash>(kHashes, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 type = SSLPrivateKey::Type::RSA; | 113 type = SSLPrivateKey::Type::RSA; |
113 break; | 114 break; |
114 case EVP_PKEY_EC: | 115 case EVP_PKEY_EC: |
115 type = SSLPrivateKey::Type::ECDSA; | 116 type = SSLPrivateKey::Type::ECDSA; |
116 break; | 117 break; |
117 default: | 118 default: |
118 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); | 119 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); |
119 return nullptr; | 120 return nullptr; |
120 } | 121 } |
121 return make_scoped_refptr(new ThreadedSSLPrivateKey( | 122 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
122 make_scoped_ptr(new SSLPlatformKeyAndroid(key.Pass(), type)), | 123 make_scoped_ptr(new SSLPlatformKeyAndroid(std::move(key), type)), |
123 GetSSLPlatformKeyTaskRunner())); | 124 GetSSLPlatformKeyTaskRunner())); |
124 } | 125 } |
125 | 126 |
126 } // namespace | 127 } // namespace |
127 | 128 |
128 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( | 129 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( |
129 X509Certificate* certificate) { | 130 X509Certificate* certificate) { |
130 crypto::ScopedEVP_PKEY key = | 131 crypto::ScopedEVP_PKEY key = |
131 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey( | 132 OpenSSLClientKeyStore::GetInstance()->FetchClientCertPrivateKey( |
132 certificate); | 133 certificate); |
133 return WrapOpenSSLPrivateKey(key.Pass()); | 134 return WrapOpenSSLPrivateKey(std::move(key)); |
134 } | 135 } |
135 | 136 |
136 } // namespace net | 137 } // namespace net |
OLD | NEW |