summaryrefslogtreecommitdiff
path: root/app/jni/jbcrypto.cpp
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-06-16 11:28:05 +0200
committerParménides GV <parmegv@sdf.org>2015-06-16 11:28:05 +0200
commit66c79953db6876ec17a7ebf50dc4fd07d24fae37 (patch)
tree67075abe6ea28f7fc7213f654b86464b13507058 /app/jni/jbcrypto.cpp
parent1f41fec6765e49838141ad29151713c7ac3dd17c (diff)
parente533cf6939e3ea4233aa8a82812f8ce5fcb565ca (diff)
Merge branch 'develop'0.9.4
Diffstat (limited to 'app/jni/jbcrypto.cpp')
-rw-r--r--app/jni/jbcrypto.cpp95
1 files changed, 0 insertions, 95 deletions
diff --git a/app/jni/jbcrypto.cpp b/app/jni/jbcrypto.cpp
deleted file mode 100644
index 2fd1262a..00000000
--- a/app/jni/jbcrypto.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-//
-// JBCyrpto.cpp
-// xcopenvpn
-//
-// Created by Arne Schwabe on 12.07.12.
-// Copyright (c) 2012 Universität Paderborn. All rights reserved.
-//
-
-#include <jni.h>
-
-#include <openssl/ssl.h>
-#include <openssl/rsa.h>
-#include <openssl/objects.h>
-#include <openssl/md5.h>
-#include <android/log.h>
-#include <openssl/err.h>
-
-
-extern "C" {
-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) {
-
- jclass exceptionClass = env->FindClass(className);
-
- if (exceptionClass == NULL) {
- __android_log_print(ANDROID_LOG_DEBUG,"openvpn","Unable to find exception class %s", className);
- /* ClassNotFoundException now pending */
- return -1;
- }
-
- if (env->ThrowNew( exceptionClass, msg) != JNI_OK) {
- __android_log_print(ANDROID_LOG_DEBUG,"openvpn","Failed throwing '%s' '%s'", className, msg);
- /* an exception, most likely OOM, will now be pending */
- return -1;
- }
-
- env->DeleteLocalRef(exceptionClass);
- return 0;
-}
-
-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);
-
-
- if (pkey == NULL || from == NULL) {
- jniThrowException(env, "java/lang/NullPointerException", "EVP_KEY is null");
- return NULL;
- }
-
- jbyte* data = env-> GetByteArrayElements (from, NULL);
- int datalen = env-> GetArrayLength(from);
-
- if(data==NULL )
- jniThrowException(env, "java/lang/NullPointerException", "data is null");
-
- int siglen;
- unsigned char* sigret = (unsigned char*)malloc(RSA_size(pkey->pkey.rsa));
-
-
- //int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
- // 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 ) */
-
- siglen = RSA_private_encrypt(datalen,(unsigned char*) data,sigret,pkey->pkey.rsa,RSA_PKCS1_PADDING);
-
- if (siglen < 0)
- {
-
- ERR_error_string_n(ERR_get_error(), opensslerr ,1024);
- jniThrowException(env, "java/security/InvalidKeyException", opensslerr);
-
- ERR_print_errors_fp(stderr);
- return NULL;
-
-
- }
-
-
- jbyteArray jb;
-
- jb =env->NewByteArray(siglen);
-
- env->SetByteArrayRegion(jb, 0, siglen, (jbyte *) sigret);
- free(sigret);
- return jb;
-
-}