diff options
Diffstat (limited to 'app/jni/jbcrypto.cpp')
-rw-r--r-- | app/jni/jbcrypto.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/app/jni/jbcrypto.cpp b/app/jni/jbcrypto.cpp index 1c3e3ca9..2fd1262a 100644 --- a/app/jni/jbcrypto.cpp +++ b/app/jni/jbcrypto.cpp @@ -17,7 +17,7 @@ extern "C" { -jbyteArray Java_se_leap_openvpn_OpenVpnManagementThread_rsasign(JNIEnv* env, jclass, jbyteArray from, jint pkeyRef); +jbyteArray Java_de_blinkt_openvpn_core_NativeUtils_rsasign(JNIEnv* env, jclass, jbyteArray from, jint pkeyRef); } int jniThrowException(JNIEnv* env, const char* className, const char* msg) { @@ -40,8 +40,8 @@ int jniThrowException(JNIEnv* env, const char* className, const char* msg) { return 0; } - -jbyteArray Java_se_leap_openvpn_OpenVpnManagementThread_rsasign(JNIEnv* env, jclass, jbyteArray from, jint pkeyRef) { +static char opensslerr[1024]; +jbyteArray Java_de_blinkt_openvpn_core_NativeUtils_rsasign (JNIEnv* env, jclass, jbyteArray from, jint pkeyRef) { // EVP_MD_CTX* ctx = reinterpret_cast<EVP_MD_CTX*>(ctxRef); EVP_PKEY* pkey = reinterpret_cast<EVP_PKEY*>(pkeyRef); @@ -58,7 +58,7 @@ jbyteArray Java_se_leap_openvpn_OpenVpnManagementThread_rsasign(JNIEnv* env, jcl if(data==NULL ) jniThrowException(env, "java/lang/NullPointerException", "data is null"); - unsigned int siglen; + int siglen; unsigned char* sigret = (unsigned char*)malloc(RSA_size(pkey->pkey.rsa)); @@ -66,11 +66,16 @@ jbyteArray Java_se_leap_openvpn_OpenVpnManagementThread_rsasign(JNIEnv* env, jcl // unsigned char *sigret, unsigned int *siglen, RSA *rsa); // adapted from s3_clnt.c - if (RSA_sign(NID_md5_sha1, (unsigned char*) data, datalen, - sigret, &siglen, pkey->pkey.rsa) <= 0 ) + /* if (RSA_sign(NID_md5_sha1, (unsigned char*) data, datalen, + sigret, &siglen, pkey->pkey.rsa) <= 0 ) */ + + siglen = RSA_private_encrypt(datalen,(unsigned char*) data,sigret,pkey->pkey.rsa,RSA_PKCS1_PADDING); + + if (siglen < 0) { - jniThrowException(env, "java/security/InvalidKeyException", "rsa_sign went wrong, see logcat"); + ERR_error_string_n(ERR_get_error(), opensslerr ,1024); + jniThrowException(env, "java/security/InvalidKeyException", opensslerr); ERR_print_errors_fp(stderr); return NULL; |