OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/android/keystore_openssl.h" | 5 #include "net/android/keystore_openssl.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <openssl/bn.h> | 8 #include <openssl/bn.h> |
9 #include <openssl/ec.h> | 9 #include <openssl/ec.h> |
10 #include <openssl/engine.h> | 10 #include <openssl/engine.h> |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 ex_data->legacy_rsa = legacy_rsa; | 344 ex_data->legacy_rsa = legacy_rsa; |
345 ex_data->cached_size = VectorBignumSize(modulus); | 345 ex_data->cached_size = VectorBignumSize(modulus); |
346 RSA_set_ex_data( | 346 RSA_set_ex_data( |
347 rsa.get(), global_boringssl_engine.Get().rsa_ex_index(), ex_data); | 347 rsa.get(), global_boringssl_engine.Get().rsa_ex_index(), ex_data); |
348 | 348 |
349 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); | 349 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); |
350 if (!pkey || | 350 if (!pkey || |
351 !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) { | 351 !EVP_PKEY_set1_RSA(pkey.get(), rsa.get())) { |
352 return crypto::ScopedEVP_PKEY(); | 352 return crypto::ScopedEVP_PKEY(); |
353 } | 353 } |
354 return pkey.Pass(); | 354 return pkey; |
355 } | 355 } |
356 | 356 |
357 // On Android < 4.2, the libkeystore.so ENGINE uses CRYPTO_EX_DATA and is not | 357 // On Android < 4.2, the libkeystore.so ENGINE uses CRYPTO_EX_DATA and is not |
358 // added to the global engine list. If all references to it are dropped, OpenSSL | 358 // added to the global engine list. If all references to it are dropped, OpenSSL |
359 // will dlclose the module, leaving a dangling function pointer in the RSA | 359 // will dlclose the module, leaving a dangling function pointer in the RSA |
360 // CRYPTO_EX_DATA class. To work around this, leak an extra reference to the | 360 // CRYPTO_EX_DATA class. To work around this, leak an extra reference to the |
361 // ENGINE we extract in GetRsaLegacyKey. | 361 // ENGINE we extract in GetRsaLegacyKey. |
362 // | 362 // |
363 // In 4.2, this change avoids the problem: | 363 // In 4.2, this change avoids the problem: |
364 // https://android.googlesource.com/platform/libcore/+/106a8928fb4249f2f3d4dba1d
ddbe73ca5cb3d61 | 364 // https://android.googlesource.com/platform/libcore/+/106a8928fb4249f2f3d4dba1d
ddbe73ca5cb3d61 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 ex_data->cached_size = VectorBignumSize(order); | 519 ex_data->cached_size = VectorBignumSize(order); |
520 | 520 |
521 EC_KEY_set_ex_data( | 521 EC_KEY_set_ex_data( |
522 ec_key.get(), global_boringssl_engine.Get().ec_key_ex_index(), ex_data); | 522 ec_key.get(), global_boringssl_engine.Get().ec_key_ex_index(), ex_data); |
523 | 523 |
524 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); | 524 crypto::ScopedEVP_PKEY pkey(EVP_PKEY_new()); |
525 if (!pkey || | 525 if (!pkey || |
526 !EVP_PKEY_set1_EC_KEY(pkey.get(), ec_key.get())) { | 526 !EVP_PKEY_set1_EC_KEY(pkey.get(), ec_key.get())) { |
527 return crypto::ScopedEVP_PKEY(); | 527 return crypto::ScopedEVP_PKEY(); |
528 } | 528 } |
529 return pkey.Pass(); | 529 return pkey; |
530 } | 530 } |
531 | 531 |
532 const ECDSA_METHOD android_ecdsa_method = { | 532 const ECDSA_METHOD android_ecdsa_method = { |
533 { | 533 { |
534 0 /* references */, | 534 0 /* references */, |
535 1 /* is_static */ | 535 1 /* is_static */ |
536 } /* common */, | 536 } /* common */, |
537 NULL /* app_data */, | 537 NULL /* app_data */, |
538 | 538 |
539 NULL /* init */, | 539 NULL /* init */, |
(...skipping 16 matching lines...) Expand all Loading... |
556 return GetEcdsaPkeyWrapper(private_key); | 556 return GetEcdsaPkeyWrapper(private_key); |
557 default: | 557 default: |
558 LOG(WARNING) | 558 LOG(WARNING) |
559 << "GetOpenSSLPrivateKeyWrapper() called with invalid key type"; | 559 << "GetOpenSSLPrivateKeyWrapper() called with invalid key type"; |
560 return nullptr; | 560 return nullptr; |
561 } | 561 } |
562 } | 562 } |
563 | 563 |
564 } // namespace android | 564 } // namespace android |
565 } // namespace net | 565 } // namespace net |
OLD | NEW |