| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 154 |
| 154 private: | 155 private: |
| 155 SSLPrivateKey::Type type_; | 156 SSLPrivateKey::Type type_; |
| 156 crypto::ScopedSECKEYPrivateKey key_; | 157 crypto::ScopedSECKEYPrivateKey key_; |
| 157 | 158 |
| 158 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyNSS); | 159 DISALLOW_COPY_AND_ASSIGN(SSLPlatformKeyNSS); |
| 159 }; | 160 }; |
| 160 | 161 |
| 161 } // namespace | 162 } // namespace |
| 162 | 163 |
| 163 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | 164 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( |
| 164 X509Certificate* certificate, | 165 X509Certificate* certificate) { |
| 165 scoped_refptr<base::SequencedTaskRunner> task_runner) { | |
| 166 crypto::ScopedSECKEYPrivateKey key( | 166 crypto::ScopedSECKEYPrivateKey key( |
| 167 PK11_FindKeyByAnyCert(certificate->os_cert_handle(), nullptr)); | 167 PK11_FindKeyByAnyCert(certificate->os_cert_handle(), nullptr)); |
| 168 if (!key) { | 168 if (!key) { |
| 169 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey( | 169 return ClientKeyStore::GetInstance()->FetchClientCertPrivateKey( |
| 170 *certificate); | 170 *certificate); |
| 171 } | 171 } |
| 172 | 172 |
| 173 KeyType nss_type = SECKEY_GetPrivateKeyType(key.get()); | 173 KeyType nss_type = SECKEY_GetPrivateKeyType(key.get()); |
| 174 SSLPrivateKey::Type type; | 174 SSLPrivateKey::Type type; |
| 175 switch (nss_type) { | 175 switch (nss_type) { |
| 176 case rsaKey: | 176 case rsaKey: |
| 177 type = SSLPrivateKey::Type::RSA; | 177 type = SSLPrivateKey::Type::RSA; |
| 178 break; | 178 break; |
| 179 case ecKey: | 179 case ecKey: |
| 180 type = SSLPrivateKey::Type::ECDSA; | 180 type = SSLPrivateKey::Type::ECDSA; |
| 181 break; | 181 break; |
| 182 default: | 182 default: |
| 183 LOG(ERROR) << "Unknown key type: " << nss_type; | 183 LOG(ERROR) << "Unknown key type: " << nss_type; |
| 184 return nullptr; | 184 return nullptr; |
| 185 } | 185 } |
| 186 return make_scoped_ptr(new ThreadedSSLPrivateKey( | 186 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
| 187 make_scoped_ptr(new SSLPlatformKeyNSS(type, key.Pass())), | 187 make_scoped_ptr(new SSLPlatformKeyNSS(type, key.Pass())), |
| 188 task_runner.Pass())); | 188 GetSSLPlatformKeyTaskRunner())); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace net | 191 } // namespace net |
| OLD | NEW |