| 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 <windows.h> | 7 #include <windows.h> |
| 8 #include <NCrypt.h> | 8 #include <NCrypt.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
| 23 #include "base/stl_util.h" | 23 #include "base/stl_util.h" |
| 24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 25 #include "crypto/openssl_util.h" | 25 #include "crypto/openssl_util.h" |
| 26 #include "crypto/scoped_capi_types.h" | 26 #include "crypto/scoped_capi_types.h" |
| 27 #include "crypto/wincrypt_shim.h" | 27 #include "crypto/wincrypt_shim.h" |
| 28 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 29 #include "net/cert/x509_certificate.h" | 29 #include "net/cert/x509_certificate.h" |
| 30 #include "net/ssl/scoped_openssl_types.h" | 30 #include "net/ssl/scoped_openssl_types.h" |
| 31 #include "net/ssl/ssl_platform_key_task_runner.h" |
| 31 #include "net/ssl/ssl_private_key.h" | 32 #include "net/ssl/ssl_private_key.h" |
| 32 #include "net/ssl/threaded_ssl_private_key.h" | 33 #include "net/ssl/threaded_ssl_private_key.h" |
| 33 | 34 |
| 34 namespace net { | 35 namespace net { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 using NCryptFreeObjectFunc = SECURITY_STATUS(WINAPI*)(NCRYPT_HANDLE); | 39 using NCryptFreeObjectFunc = SECURITY_STATUS(WINAPI*)(NCRYPT_HANDLE); |
| 39 using NCryptSignHashFunc = SECURITY_STATUS(WINAPI*)(NCRYPT_KEY_HANDLE, // hKey | 40 using NCryptSignHashFunc = SECURITY_STATUS(WINAPI*)(NCRYPT_KEY_HANDLE, // hKey |
| 40 VOID*, // pPaddingInfo | 41 VOID*, // pPaddingInfo |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 break; | 317 break; |
| 317 default: | 318 default: |
| 318 return false; | 319 return false; |
| 319 } | 320 } |
| 320 *out_max_length = EVP_PKEY_size(key.get()); | 321 *out_max_length = EVP_PKEY_size(key.get()); |
| 321 return true; | 322 return true; |
| 322 } | 323 } |
| 323 | 324 |
| 324 } // namespace | 325 } // namespace |
| 325 | 326 |
| 326 scoped_ptr<SSLPrivateKey> FetchClientCertPrivateKey( | 327 scoped_refptr<SSLPrivateKey> FetchClientCertPrivateKey( |
| 327 X509Certificate* certificate, | 328 X509Certificate* certificate) { |
| 328 scoped_refptr<base::SequencedTaskRunner> task_runner) { | |
| 329 // Rather than query the private key for metadata, extract the public key from | 329 // Rather than query the private key for metadata, extract the public key from |
| 330 // the certificate without using Windows APIs. CAPI and CNG do not | 330 // the certificate without using Windows APIs. CAPI and CNG do not |
| 331 // consistently work depending on the system. See https://crbug.com/468345. | 331 // consistently work depending on the system. See https://crbug.com/468345. |
| 332 SSLPrivateKey::Type key_type; | 332 SSLPrivateKey::Type key_type; |
| 333 size_t max_length; | 333 size_t max_length; |
| 334 if (!GetKeyInfo(certificate, &key_type, &max_length)) | 334 if (!GetKeyInfo(certificate, &key_type, &max_length)) |
| 335 return nullptr; | 335 return nullptr; |
| 336 | 336 |
| 337 PCCERT_CONTEXT cert_context = certificate->os_cert_handle(); | 337 PCCERT_CONTEXT cert_context = certificate->os_cert_handle(); |
| 338 | 338 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 353 // transferred. | 353 // transferred. |
| 354 CHECK_EQ(must_free, TRUE); | 354 CHECK_EQ(must_free, TRUE); |
| 355 | 355 |
| 356 scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate; | 356 scoped_ptr<ThreadedSSLPrivateKey::Delegate> delegate; |
| 357 if (key_spec == CERT_NCRYPT_KEY_SPEC) { | 357 if (key_spec == CERT_NCRYPT_KEY_SPEC) { |
| 358 delegate.reset(new SSLPlatformKeyCNG(prov_or_key, key_type, max_length)); | 358 delegate.reset(new SSLPlatformKeyCNG(prov_or_key, key_type, max_length)); |
| 359 } else { | 359 } else { |
| 360 DCHECK(SSLPrivateKey::Type::RSA == key_type); | 360 DCHECK(SSLPrivateKey::Type::RSA == key_type); |
| 361 delegate.reset(new SSLPlatformKeyCAPI(prov_or_key, key_spec, max_length)); | 361 delegate.reset(new SSLPlatformKeyCAPI(prov_or_key, key_spec, max_length)); |
| 362 } | 362 } |
| 363 return make_scoped_ptr( | 363 return make_scoped_refptr(new ThreadedSSLPrivateKey( |
| 364 new ThreadedSSLPrivateKey(delegate.Pass(), task_runner.Pass())); | 364 delegate.Pass(), GetSSLPlatformKeyTaskRunner())); |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace net | 367 } // namespace net |
| OLD | NEW |