OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/test_ssl_private_key.h" | 5 #include "net/ssl/test_ssl_private_key.h" |
6 | 6 |
7 #include <openssl/digest.h> | 7 #include <openssl/digest.h> |
| 8 #include <openssl/ec.h> |
8 #include <openssl/evp.h> | 9 #include <openssl/evp.h> |
9 #include <openssl/rsa.h> | 10 #include <openssl/rsa.h> |
10 | 11 |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
17 #include "net/ssl/ssl_platform_key_task_runner.h" | 18 #include "net/ssl/ssl_platform_key_util.h" |
18 #include "net/ssl/ssl_private_key.h" | 19 #include "net/ssl/ssl_private_key.h" |
19 #include "net/ssl/threaded_ssl_private_key.h" | 20 #include "net/ssl/threaded_ssl_private_key.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 class TestSSLPlatformKey : public ThreadedSSLPrivateKey::Delegate { | 26 class TestSSLPlatformKey : public ThreadedSSLPrivateKey::Delegate { |
26 public: | 27 public: |
27 TestSSLPlatformKey(bssl::UniquePtr<EVP_PKEY> key, SSLPrivateKey::Type type) | 28 TestSSLPlatformKey(bssl::UniquePtr<EVP_PKEY> key, SSLPrivateKey::Type type) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey( | 109 scoped_refptr<SSLPrivateKey> WrapOpenSSLPrivateKey( |
109 bssl::UniquePtr<EVP_PKEY> key) { | 110 bssl::UniquePtr<EVP_PKEY> key) { |
110 if (!key) | 111 if (!key) |
111 return nullptr; | 112 return nullptr; |
112 | 113 |
113 SSLPrivateKey::Type type; | 114 SSLPrivateKey::Type type; |
114 switch (EVP_PKEY_id(key.get())) { | 115 switch (EVP_PKEY_id(key.get())) { |
115 case EVP_PKEY_RSA: | 116 case EVP_PKEY_RSA: |
116 type = SSLPrivateKey::Type::RSA; | 117 type = SSLPrivateKey::Type::RSA; |
117 break; | 118 break; |
118 case EVP_PKEY_EC: | 119 case EVP_PKEY_EC: { |
119 type = SSLPrivateKey::Type::ECDSA; | 120 EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(key.get()); |
| 121 int curve = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec_key)); |
| 122 switch (curve) { |
| 123 case NID_X9_62_prime256v1: |
| 124 type = SSLPrivateKey::Type::ECDSA_P256; |
| 125 break; |
| 126 case NID_secp384r1: |
| 127 type = SSLPrivateKey::Type::ECDSA_P384; |
| 128 break; |
| 129 case NID_secp521r1: |
| 130 type = SSLPrivateKey::Type::ECDSA_P384; |
| 131 break; |
| 132 default: |
| 133 LOG(ERROR) << "Unknown curve: " << curve; |
| 134 return nullptr; |
| 135 } |
120 break; | 136 break; |
| 137 } |
121 default: | 138 default: |
122 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); | 139 LOG(ERROR) << "Unknown key type: " << EVP_PKEY_id(key.get()); |
123 return nullptr; | 140 return nullptr; |
124 } | 141 } |
125 return make_scoped_refptr(new ThreadedSSLPrivateKey( | 142 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
126 base::MakeUnique<TestSSLPlatformKey>(std::move(key), type), | 143 base::MakeUnique<TestSSLPlatformKey>(std::move(key), type), |
127 GetSSLPlatformKeyTaskRunner())); | 144 GetSSLPlatformKeyTaskRunner())); |
128 } | 145 } |
129 | 146 |
130 } // namespace net | 147 } // namespace net |
OLD | NEW |