| 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 // This include is required to get the ECDSA_METHOD structure definition | 9 // This include is required to get the ECDSA_METHOD structure definition |
| 10 // which isn't currently part of the OpenSSL official ABI. This should | 10 // which isn't currently part of the OpenSSL official ABI. This should |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 int RsaMethodInit(RSA* rsa) { | 201 int RsaMethodInit(RSA* rsa) { |
| 202 return 0; | 202 return 0; |
| 203 } | 203 } |
| 204 | 204 |
| 205 int RsaMethodFinish(RSA* rsa) { | 205 int RsaMethodFinish(RSA* rsa) { |
| 206 // Ensure the global JNI reference created with this wrapper is | 206 // Ensure the global JNI reference created with this wrapper is |
| 207 // properly destroyed with it. | 207 // properly destroyed with it. |
| 208 jobject key = reinterpret_cast<jobject>(RSA_get_app_data(rsa)); | 208 jobject key = reinterpret_cast<jobject>(RSA_get_app_data(rsa)); |
| 209 if (key != NULL) { | 209 if (key != NULL) { |
| 210 RSA_set_app_data(rsa, NULL); | 210 RSA_set_app_data(rsa, NULL); |
| 211 JNIEnv* env = base::android::AttachCurrentThread(); | 211 ReleaseKey(key); |
| 212 env->DeleteGlobalRef(key); | |
| 213 } | 212 } |
| 214 // Actual return value is ignored by OpenSSL. There are no docs | 213 // Actual return value is ignored by OpenSSL. There are no docs |
| 215 // explaining what this is supposed to be. | 214 // explaining what this is supposed to be. |
| 216 return 0; | 215 return 0; |
| 217 } | 216 } |
| 218 | 217 |
| 219 const RSA_METHOD android_rsa_method = { | 218 const RSA_METHOD android_rsa_method = { |
| 220 /* .name = */ "Android signing-only RSA method", | 219 /* .name = */ "Android signing-only RSA method", |
| 221 /* .rsa_pub_enc = */ RsaMethodPubEnc, | 220 /* .rsa_pub_enc = */ RsaMethodPubEnc, |
| 222 /* .rsa_pub_dec = */ RsaMethodPubDec, | 221 /* .rsa_pub_dec = */ RsaMethodPubDec, |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_INVALID_DIGEST_TYPE); | 405 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_INVALID_DIGEST_TYPE); |
| 407 return -1; | 406 return -1; |
| 408 } | 407 } |
| 409 | 408 |
| 410 int DsaMethodFinish(DSA* dsa) { | 409 int DsaMethodFinish(DSA* dsa) { |
| 411 // Free the global JNI reference that was created with this | 410 // Free the global JNI reference that was created with this |
| 412 // wrapper key. | 411 // wrapper key. |
| 413 jobject key = reinterpret_cast<jobject>(DSA_get_ex_data(dsa,0)); | 412 jobject key = reinterpret_cast<jobject>(DSA_get_ex_data(dsa,0)); |
| 414 if (key != NULL) { | 413 if (key != NULL) { |
| 415 DSA_set_ex_data(dsa, 0, NULL); | 414 DSA_set_ex_data(dsa, 0, NULL); |
| 416 JNIEnv* env = base::android::AttachCurrentThread(); | 415 ReleaseKey(key); |
| 417 env->DeleteGlobalRef(key); | |
| 418 } | 416 } |
| 419 // Actual return value is ignored by OpenSSL. There are no docs | 417 // Actual return value is ignored by OpenSSL. There are no docs |
| 420 // explaining what this is supposed to be. | 418 // explaining what this is supposed to be. |
| 421 return 0; | 419 return 0; |
| 422 } | 420 } |
| 423 | 421 |
| 424 const DSA_METHOD android_dsa_method = { | 422 const DSA_METHOD android_dsa_method = { |
| 425 /* .name = */ "Android signing-only DSA method", | 423 /* .name = */ "Android signing-only DSA method", |
| 426 /* .dsa_do_sign = */ DsaMethodDoSign, | 424 /* .dsa_do_sign = */ DsaMethodDoSign, |
| 427 /* .dsa_sign_setup = */ DsaMethodSignSetup, | 425 /* .dsa_sign_setup = */ DsaMethodSignSetup, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 void* ptr, | 484 void* ptr, |
| 487 CRYPTO_EX_DATA* ad, | 485 CRYPTO_EX_DATA* ad, |
| 488 int idx, | 486 int idx, |
| 489 long argl, | 487 long argl, |
| 490 void* argp) { | 488 void* argp) { |
| 491 jobject private_key = reinterpret_cast<jobject>(ptr); | 489 jobject private_key = reinterpret_cast<jobject>(ptr); |
| 492 if (private_key == NULL) | 490 if (private_key == NULL) |
| 493 return; | 491 return; |
| 494 | 492 |
| 495 CRYPTO_set_ex_data(ad, idx, NULL); | 493 CRYPTO_set_ex_data(ad, idx, NULL); |
| 496 | 494 ReleaseKey(private_key); |
| 497 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 498 env->DeleteGlobalRef(private_key); | |
| 499 } | 495 } |
| 500 | 496 |
| 501 int ExDataDup(CRYPTO_EX_DATA* to, | 497 int ExDataDup(CRYPTO_EX_DATA* to, |
| 502 CRYPTO_EX_DATA* from, | 498 CRYPTO_EX_DATA* from, |
| 503 void* from_d, | 499 void* from_d, |
| 504 int idx, | 500 int idx, |
| 505 long argl, | 501 long argl, |
| 506 void* argp) { | 502 void* argp) { |
| 507 // This callback shall never be called with the current OpenSSL | 503 // This callback shall never be called with the current OpenSSL |
| 508 // implementation (the library only ever duplicates EX_DATA items | 504 // implementation (the library only ever duplicates EX_DATA items |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 default: | 687 default: |
| 692 LOG(WARNING) | 688 LOG(WARNING) |
| 693 << "GetOpenSSLPrivateKeyWrapper() called with invalid key type"; | 689 << "GetOpenSSLPrivateKeyWrapper() called with invalid key type"; |
| 694 return NULL; | 690 return NULL; |
| 695 } | 691 } |
| 696 return pkey.release(); | 692 return pkey.release(); |
| 697 } | 693 } |
| 698 | 694 |
| 699 } // namespace android | 695 } // namespace android |
| 700 } // namespace net | 696 } // namespace net |
| OLD | NEW |