diff options
Diffstat (limited to 'ics-openvpn-stripped/main/jni')
-rw-r--r-- | ics-openvpn-stripped/main/jni/Android.mk | 73 | ||||
-rw-r--r-- | ics-openvpn-stripped/main/jni/Application.mk | 11 | ||||
-rw-r--r-- | ics-openvpn-stripped/main/jni/dummy.cpp | 8 | ||||
-rw-r--r-- | ics-openvpn-stripped/main/jni/jbcrypto.cpp | 95 | ||||
-rw-r--r-- | ics-openvpn-stripped/main/jni/jniglue.c | 21 | ||||
-rw-r--r-- | ics-openvpn-stripped/main/jni/jniglue.h | 12 | ||||
-rw-r--r-- | ics-openvpn-stripped/main/jni/minivpn.c | 0 |
7 files changed, 220 insertions, 0 deletions
diff --git a/ics-openvpn-stripped/main/jni/Android.mk b/ics-openvpn-stripped/main/jni/Android.mk new file mode 100644 index 00000000..33d0bc76 --- /dev/null +++ b/ics-openvpn-stripped/main/jni/Android.mk @@ -0,0 +1,73 @@ +# Path of the sources +JNI_DIR := $(call my-dir) + +#optional arguments +#WITH_POLAR=1 +#WITH_OPENVPN3=1 +# Build openvpn with polar (OpenVPN3 core is always build with polar) +#WITH_BREAKPAD=0 + + +include lzo/Android.mk +include snappy/Android.mk + +include openssl/Android.mk + +ifneq ($(USE_BREAKPAD),0) + ifneq ($(TARGET_ARCH),mips) + WITH_BREAKPAD=1 + include google-breakpad/android/google_breakpad/Android.mk + else + WITH_BREAKPAD=0 + endif +else +WITH_BREAKPAD=0 +endif + +ifeq ($(WITH_POLAR),1) + USE_POLAR=1 +endif +ifeq ($(WITH_OPENVPN3),1) + USE_POLAR=1 +endif + +ifeq ($(USE_POLAR),1) + include polarssl/Android.mk +endif + +include openvpn/Android.mk + +ifeq ($(WITH_OPENVPN3),1) + include ovpn3/Android.mk +endif + +LOCAL_PATH := $(JNI_DIR) + +# The only real JNI library +include $(CLEAR_VARS) +LOCAL_LDLIBS := -llog -lz +LOCAL_C_INCLUDES := openssl/include openssl/crypto openssl +LOCAL_SRC_FILES:= jniglue.c jbcrypto.cpp +LOCAL_MODULE = opvpnutil +LOCAL_SHARED_LIBRARIES := libcrypto +include $(BUILD_SHARED_LIBRARY) + + +include $(CLEAR_VARS) +LOCAL_LDLIBS := -lz -lc +LOCAL_SHARED_LIBRARIES := libssl libcrypto openvpn +LOCAL_SRC_FILES:= minivpn.c dummy.cpp +LOCAL_MODULE = nopievpn +include $(BUILD_EXECUTABLE) + + +include $(CLEAR_VARS) +LOCAL_LDLIBS := -lz -lc +LOCAL_CFLAGS= -fPIE -pie +LOCAL_CFLAGS = -fPIE +LOCAL_LDFLAGS = -fPIE -pie +LOCAL_SHARED_LIBRARIES := libssl libcrypto openvpn +LOCAL_SRC_FILES:= minivpn.c dummy.cpp +LOCAL_MODULE = pievpn +include $(BUILD_EXECUTABLE) + diff --git a/ics-openvpn-stripped/main/jni/Application.mk b/ics-openvpn-stripped/main/jni/Application.mk new file mode 100644 index 00000000..718e79a8 --- /dev/null +++ b/ics-openvpn-stripped/main/jni/Application.mk @@ -0,0 +1,11 @@ +APP_ABI := all +APP_PLATFORM := android-14 + +APP_STL:=stlport_shared +#APP_STL:=gnustl_shared + +#APP_OPTIM := release + +#LOCAL_ARM_MODE := arm + +#NDK_TOOLCHAIN_VERSION=clang
\ No newline at end of file diff --git a/ics-openvpn-stripped/main/jni/dummy.cpp b/ics-openvpn-stripped/main/jni/dummy.cpp new file mode 100644 index 00000000..58466656 --- /dev/null +++ b/ics-openvpn-stripped/main/jni/dummy.cpp @@ -0,0 +1,8 @@ +/*#include <string> +#include <iostream> + +void dummy() +{ + std::cout << "I am a dummy function to help compile on Android NDK r9" << std::endl; +} +*/ diff --git a/ics-openvpn-stripped/main/jni/jbcrypto.cpp b/ics-openvpn-stripped/main/jni/jbcrypto.cpp new file mode 100644 index 00000000..2fd1262a --- /dev/null +++ b/ics-openvpn-stripped/main/jni/jbcrypto.cpp @@ -0,0 +1,95 @@ +// +// 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; + +} diff --git a/ics-openvpn-stripped/main/jni/jniglue.c b/ics-openvpn-stripped/main/jni/jniglue.c new file mode 100644 index 00000000..36ad8fe7 --- /dev/null +++ b/ics-openvpn-stripped/main/jni/jniglue.c @@ -0,0 +1,21 @@ +#include <jni.h> +#include <android/log.h> +#include <stdlib.h> +#include <setjmp.h> + +#include "jniglue.h" + +jint JNI_OnLoad(JavaVM *vm, void *reserved) { + __android_log_write(ANDROID_LOG_DEBUG,"openvpn", "Loading openvpn native library $id$ compiled on " __DATE__ " " __TIME__ ); + return JNI_VERSION_1_2; +} + + +void android_openvpn_log(int level,const char* prefix,const char* prefix_sep,const char* m1) +{ + __android_log_print(ANDROID_LOG_DEBUG,"openvpn","%s%s%s",prefix,prefix_sep,m1); +} + +void Java_de_blinkt_openvpn_core_NativeUtils_jniclose(JNIEnv *env,jclass jo, jint fd) { + int ret = close(fd); +} diff --git a/ics-openvpn-stripped/main/jni/jniglue.h b/ics-openvpn-stripped/main/jni/jniglue.h new file mode 100644 index 00000000..a86d52da --- /dev/null +++ b/ics-openvpn-stripped/main/jni/jniglue.h @@ -0,0 +1,12 @@ +// +// jniglue.h +// xcopenvpn +// +// Created by Arne Schwabe on 29.03.12. +// Copyright (c) 2012 Universität Paderborn. All rights reserved. +// + +#ifndef xcopenvpn_jniglue_h +#define xcopenvpn_jniglue_h +void android_openvpn_log(int level,const char* prefix,const char* prefix_sep,const char* m1); +#endif diff --git a/ics-openvpn-stripped/main/jni/minivpn.c b/ics-openvpn-stripped/main/jni/minivpn.c new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/ics-openvpn-stripped/main/jni/minivpn.c |