OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/openssl_platform_key.h" | 5 #include "net/ssl/openssl_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 <string.h> | 10 #include <string.h> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include <openssl/md5.h> | 21 #include <openssl/md5.h> |
22 #include <openssl/obj_mac.h> | 22 #include <openssl/obj_mac.h> |
23 #include <openssl/rsa.h> | 23 #include <openssl/rsa.h> |
24 #include <openssl/sha.h> | 24 #include <openssl/sha.h> |
25 | 25 |
26 #include "base/debug/debugger.h" | 26 #include "base/debug/debugger.h" |
27 #include "base/debug/stack_trace.h" | 27 #include "base/debug/stack_trace.h" |
28 #include "base/lazy_instance.h" | 28 #include "base/lazy_instance.h" |
29 #include "base/logging.h" | 29 #include "base/logging.h" |
30 #include "base/memory/scoped_ptr.h" | 30 #include "base/memory/scoped_ptr.h" |
| 31 #include "base/profiler/scoped_tracker.h" |
31 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
32 #include "crypto/scoped_capi_types.h" | 33 #include "crypto/scoped_capi_types.h" |
33 #include "crypto/wincrypt_shim.h" | 34 #include "crypto/wincrypt_shim.h" |
34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
35 #include "net/cert/x509_certificate.h" | 36 #include "net/cert/x509_certificate.h" |
36 #include "net/ssl/openssl_ssl_util.h" | 37 #include "net/ssl/openssl_ssl_util.h" |
37 | 38 |
38 namespace net { | 39 namespace net { |
39 | 40 |
40 namespace { | 41 namespace { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 const KeyExData* ex_data = RsaGetExData(rsa); | 190 const KeyExData* ex_data = RsaGetExData(rsa); |
190 return (ex_data->key_length + 7) / 8; | 191 return (ex_data->key_length + 7) / 8; |
191 } | 192 } |
192 | 193 |
193 int RsaMethodSign(int hash_nid, | 194 int RsaMethodSign(int hash_nid, |
194 const uint8_t* in, | 195 const uint8_t* in, |
195 unsigned in_len, | 196 unsigned in_len, |
196 uint8_t* out, | 197 uint8_t* out, |
197 unsigned* out_len, | 198 unsigned* out_len, |
198 const RSA* rsa) { | 199 const RSA* rsa) { |
| 200 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed. |
| 201 tracked_objects::ScopedTracker tracking_profile( |
| 202 FROM_HERE_WITH_EXPLICIT_FUNCTION("424386 RsaMethodSign")); |
| 203 |
199 // TODO(davidben): Switch BoringSSL's sign hook to using size_t rather than | 204 // TODO(davidben): Switch BoringSSL's sign hook to using size_t rather than |
200 // unsigned. | 205 // unsigned. |
201 const KeyExData* ex_data = RsaGetExData(rsa); | 206 const KeyExData* ex_data = RsaGetExData(rsa); |
202 if (!ex_data) { | 207 if (!ex_data) { |
203 NOTREACHED(); | 208 NOTREACHED(); |
204 OPENSSL_PUT_ERROR(RSA, RSA_sign, ERR_R_INTERNAL_ERROR); | 209 OPENSSL_PUT_ERROR(RSA, RSA_sign, ERR_R_INTERNAL_ERROR); |
205 return 0; | 210 return 0; |
206 } | 211 } |
207 | 212 |
208 if (ex_data->key->dwKeySpec == CERT_NCRYPT_KEY_SPEC) { | 213 if (ex_data->key->dwKeySpec == CERT_NCRYPT_KEY_SPEC) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa375520(v=vs.85).a
spx | 429 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa375520(v=vs.85).a
spx |
425 // which uses the same length for both. | 430 // which uses the same length for both. |
426 return (ex_data->key_length + 7) / 8; | 431 return (ex_data->key_length + 7) / 8; |
427 } | 432 } |
428 | 433 |
429 int EcdsaMethodSign(const uint8_t* digest, | 434 int EcdsaMethodSign(const uint8_t* digest, |
430 size_t digest_len, | 435 size_t digest_len, |
431 uint8_t* out_sig, | 436 uint8_t* out_sig, |
432 unsigned int* out_sig_len, | 437 unsigned int* out_sig_len, |
433 EC_KEY* ec_key) { | 438 EC_KEY* ec_key) { |
| 439 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed. |
| 440 tracked_objects::ScopedTracker tracking_profile( |
| 441 FROM_HERE_WITH_EXPLICIT_FUNCTION("424386 EcdsaMethodSign")); |
| 442 |
434 const KeyExData* ex_data = EcKeyGetExData(ec_key); | 443 const KeyExData* ex_data = EcKeyGetExData(ec_key); |
435 // Only CNG supports ECDSA. | 444 // Only CNG supports ECDSA. |
436 if (!ex_data || ex_data->key->dwKeySpec != CERT_NCRYPT_KEY_SPEC) { | 445 if (!ex_data || ex_data->key->dwKeySpec != CERT_NCRYPT_KEY_SPEC) { |
437 NOTREACHED(); | 446 NOTREACHED(); |
438 OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); | 447 OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); |
439 return 0; | 448 return 0; |
440 } | 449 } |
441 | 450 |
442 size_t degree = (ex_data->key_length + 7) / 8; | 451 size_t degree = (ex_data->key_length + 7) / 8; |
443 if (degree == 0) { | 452 if (degree == 0) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 case EVP_PKEY_RSA: | 675 case EVP_PKEY_RSA: |
667 return CreateRSAWrapper(key.Pass(), key_length); | 676 return CreateRSAWrapper(key.Pass(), key_length); |
668 case EVP_PKEY_EC: | 677 case EVP_PKEY_EC: |
669 return CreateECDSAWrapper(key.Pass(), key_length); | 678 return CreateECDSAWrapper(key.Pass(), key_length); |
670 default: | 679 default: |
671 return nullptr; | 680 return nullptr; |
672 } | 681 } |
673 } | 682 } |
674 | 683 |
675 } // namespace net | 684 } // namespace net |
OLD | NEW |