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 <keyhi.h> | 7 #include <keyhi.h> |
8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
9 #include <prerror.h> | 9 #include <prerror.h> |
10 | 10 |
11 #include <openssl/bn.h> | 11 #include <openssl/bn.h> |
12 #include <openssl/ecdsa.h> | 12 #include <openssl/ecdsa.h> |
13 #include <openssl/rsa.h> | 13 #include <openssl/rsa.h> |
14 | 14 |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "crypto/scoped_nss_types.h" | 19 #include "crypto/scoped_nss_types.h" |
20 #include "crypto/scoped_openssl_types.h" | 20 #include "crypto/scoped_openssl_types.h" |
21 #include "net/cert/x509_certificate.h" | 21 #include "net/cert/x509_certificate.h" |
22 #include "net/ssl/client_key_store.h" | 22 #include "net/ssl/client_key_store.h" |
| 23 #include "net/ssl/ssl_platform_key_task_runner.h" |
23 #include "net/ssl/ssl_private_key.h" | 24 #include "net/ssl/ssl_private_key.h" |
24 #include "net/ssl/threaded_ssl_private_key.h" | 25 #include "net/ssl/threaded_ssl_private_key.h" |
25 | 26 |
26 namespace net { | 27 namespace net { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 void LogPRError() { | 31 void LogPRError() { |
31 PRErrorCode err = PR_GetError(); | 32 PRErrorCode err = PR_GetError(); |
32 const char* err_name = PR_ErrorToName(err); | 33 const char* err_name = PR_ErrorToName(err); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 148 |
148 private: | 149 private: |
149 SSLPrivateKey::Type type_; | 150 SSLPrivateKey::Type type_; |
150 crypto::ScopedSECKEYPrivateKey key_; | 151 crypto::ScopedSECKEYPrivateKey key_; |
151 | 152 |
152 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyNSS); | 153 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyNSS); |
153 }; | 154 }; |
154 | 155 |
155 } // namespace | 156 } // namespace |
156 | 157 |
157 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | 158 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( |
158 X509Certificate* certificate, | 159 X509Certificate* certificate) { |
159 scoped_refptr<base::SequencedTaskRunner> task_runner) { | 160 if (!certificate || !certificate->os_cert_handle()) { |
| 161 return nullptr; |
| 162 } |
| 163 |
160 crypto::ScopedSECKEYPrivateKey key( | 164 crypto::ScopedSECKEYPrivateKey key( |
161 PK11_FindKeyByAnyCert(certificate->os_cert_handle(), nullptr)); | 165 PK11_FindKeyByAnyCert(certificate->os_cert_handle(), nullptr)); |
162 if (!key) { | 166 if (!key) { |
163 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey( | 167 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey( |
164 *certificate); | 168 *certificate); |
165 } | 169 } |
166 | 170 |
167 KeyType nss_type = SECKEY_GetPrivateKeyType(key.get()); | 171 KeyType nss_type = SECKEY_GetPrivateKeyType(key.get()); |
168 SSLPrivateKey::Type type; | 172 SSLPrivateKey::Type type; |
169 switch (nss_type) { | 173 switch (nss_type) { |
170 case rsaKey: | 174 case rsaKey: |
171 type = SSLPrivateKey::Type::RSA; | 175 type = SSLPrivateKey::Type::RSA; |
172 break; | 176 break; |
173 case ecKey: | 177 case ecKey: |
174 type = SSLPrivateKey::Type::ECDSA; | 178 type = SSLPrivateKey::Type::ECDSA; |
175 break; | 179 break; |
176 default: | 180 default: |
177 LOG(ERROR) << "Unknown key type: " << nss_type; | 181 LOG(ERROR) << "Unknown key type: " << nss_type; |
178 return nullptr; | 182 return nullptr; |
179 } | 183 } |
180 return make_scoped_ptr(new ThreadedSSLPrivateKey( | 184 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
181 make_scoped_ptr(new SSLPlatformKeyNSS(type, key.Pass())), | 185 make_scoped_ptr(new SSLPlatformKeyNSS(type, key.Pass())), |
182 task_runner.Pass())); | 186 GetSSLPlatformKeyTaskRunner())); |
183 } | 187 } |
184 | 188 |
185 } // namespace net | 189 } // namespace net |
OLD | NEW |