summaryrefslogtreecommitdiff
path: root/app/jni/jbcrypto.cpp
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-06-13 12:13:04 +0200
committerParménides GV <parmegv@sdf.org>2014-06-13 12:13:04 +0200
commit3a71bc9e4aa4296f460e2e3c55de74c9852477ad (patch)
treef816597a7c4322137f0657e7aa2bf392404d1870 /app/jni/jbcrypto.cpp
parentcfe67bfd8260253ce9288225b9e26f666d27133f (diff)
parent36247e71df88fa13c6c5a887de3b11d9a883615f (diff)
Merge branch 'feature/establish-an-upstream-relationship-with-ics-openvpn-codebase-#5381' into develop
Diffstat (limited to 'app/jni/jbcrypto.cpp')
-rw-r--r--app/jni/jbcrypto.cpp19
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;