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 11 matching lines...) Expand all Loading... |
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 #include <openssl/x509.h> | 25 #include <openssl/x509.h> |
26 | 26 |
27 #include "base/debug/debugger.h" | 27 #include "base/debug/debugger.h" |
28 #include "base/debug/stack_trace.h" | 28 #include "base/debug/stack_trace.h" |
29 #include "base/lazy_instance.h" | 29 #include "base/lazy_instance.h" |
30 #include "base/logging.h" | 30 #include "base/logging.h" |
31 #include "base/memory/scoped_ptr.h" | 31 #include "base/memory/scoped_ptr.h" |
32 #include "base/profiler/scoped_tracker.h" | |
33 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
34 #include "crypto/openssl_util.h" | 33 #include "crypto/openssl_util.h" |
35 #include "crypto/scoped_capi_types.h" | 34 #include "crypto/scoped_capi_types.h" |
36 #include "crypto/wincrypt_shim.h" | 35 #include "crypto/wincrypt_shim.h" |
37 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
38 #include "net/cert/x509_certificate.h" | 37 #include "net/cert/x509_certificate.h" |
39 #include "net/ssl/openssl_ssl_util.h" | 38 #include "net/ssl/openssl_ssl_util.h" |
40 #include "net/ssl/scoped_openssl_types.h" | 39 #include "net/ssl/scoped_openssl_types.h" |
41 | 40 |
42 namespace net { | 41 namespace net { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 const KeyExData* ex_data = RsaGetExData(rsa); | 221 const KeyExData* ex_data = RsaGetExData(rsa); |
223 return (ex_data->key_length + 7) / 8; | 222 return (ex_data->key_length + 7) / 8; |
224 } | 223 } |
225 | 224 |
226 int RsaMethodSign(int hash_nid, | 225 int RsaMethodSign(int hash_nid, |
227 const uint8_t* in, | 226 const uint8_t* in, |
228 unsigned in_len, | 227 unsigned in_len, |
229 uint8_t* out, | 228 uint8_t* out, |
230 unsigned* out_len, | 229 unsigned* out_len, |
231 const RSA* rsa) { | 230 const RSA* rsa) { |
232 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed. | |
233 tracked_objects::ScopedTracker tracking_profile( | |
234 FROM_HERE_WITH_EXPLICIT_FUNCTION("424386 RsaMethodSign")); | |
235 | |
236 // TODO(davidben): Switch BoringSSL's sign hook to using size_t rather than | 231 // TODO(davidben): Switch BoringSSL's sign hook to using size_t rather than |
237 // unsigned. | 232 // unsigned. |
238 const KeyExData* ex_data = RsaGetExData(rsa); | 233 const KeyExData* ex_data = RsaGetExData(rsa); |
239 if (!ex_data) { | 234 if (!ex_data) { |
240 NOTREACHED(); | 235 NOTREACHED(); |
241 OPENSSL_PUT_ERROR(RSA, RSA_sign, ERR_R_INTERNAL_ERROR); | 236 OPENSSL_PUT_ERROR(RSA, RSA_sign, ERR_R_INTERNAL_ERROR); |
242 return 0; | 237 return 0; |
243 } | 238 } |
244 | 239 |
245 if (ex_data->key->dwKeySpec == CERT_NCRYPT_KEY_SPEC) { | 240 if (ex_data->key->dwKeySpec == CERT_NCRYPT_KEY_SPEC) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 const KeyExData* ex_data = EcKeyGetExData(ec_key); | 448 const KeyExData* ex_data = EcKeyGetExData(ec_key); |
454 // key_length is the size of the group order for EC keys. | 449 // key_length is the size of the group order for EC keys. |
455 return (ex_data->key_length + 7) / 8; | 450 return (ex_data->key_length + 7) / 8; |
456 } | 451 } |
457 | 452 |
458 int EcdsaMethodSign(const uint8_t* digest, | 453 int EcdsaMethodSign(const uint8_t* digest, |
459 size_t digest_len, | 454 size_t digest_len, |
460 uint8_t* out_sig, | 455 uint8_t* out_sig, |
461 unsigned int* out_sig_len, | 456 unsigned int* out_sig_len, |
462 EC_KEY* ec_key) { | 457 EC_KEY* ec_key) { |
463 // TODO(vadimt): Remove ScopedTracker below once crbug.com/424386 is fixed. | |
464 tracked_objects::ScopedTracker tracking_profile( | |
465 FROM_HERE_WITH_EXPLICIT_FUNCTION("424386 EcdsaMethodSign")); | |
466 | |
467 const KeyExData* ex_data = EcKeyGetExData(ec_key); | 458 const KeyExData* ex_data = EcKeyGetExData(ec_key); |
468 // Only CNG supports ECDSA. | 459 // Only CNG supports ECDSA. |
469 if (!ex_data || ex_data->key->dwKeySpec != CERT_NCRYPT_KEY_SPEC) { | 460 if (!ex_data || ex_data->key->dwKeySpec != CERT_NCRYPT_KEY_SPEC) { |
470 NOTREACHED(); | 461 NOTREACHED(); |
471 OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); | 462 OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); |
472 return 0; | 463 return 0; |
473 } | 464 } |
474 | 465 |
475 // An ECDSA signature is two integers, modulo the order of the group. | 466 // An ECDSA signature is two integers, modulo the order of the group. |
476 size_t order_len = (ex_data->key_length + 7) / 8; | 467 size_t order_len = (ex_data->key_length + 7) / 8; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 case EVP_PKEY_RSA: | 634 case EVP_PKEY_RSA: |
644 return CreateRSAWrapper(key.Pass(), key_length); | 635 return CreateRSAWrapper(key.Pass(), key_length); |
645 case EVP_PKEY_EC: | 636 case EVP_PKEY_EC: |
646 return CreateECDSAWrapper(key.Pass(), key_length); | 637 return CreateECDSAWrapper(key.Pass(), key_length); |
647 default: | 638 default: |
648 return nullptr; | 639 return nullptr; |
649 } | 640 } |
650 } | 641 } |
651 | 642 |
652 } // namespace net | 643 } // namespace net |
OLD | NEW |