summaryrefslogtreecommitdiff
path: root/app/jni
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-06-04 19:20:15 +0200
committerParménides GV <parmegv@sdf.org>2015-06-04 19:20:15 +0200
commit27594eeae6f40a402bc3110f06d57975168e74e3 (patch)
treecdabf6571e6f4ff07205fd6921d8095539a1fcdc /app/jni
parent8dc4f58d96892fbfd83094fb85b1d17656035290 (diff)
ics-openvpn as a submodule! beautiful
ics-openvpn is now officially on GitHub, and they track openssl and openvpn as submodules, so it's easier to update everything. Just a git submodule update --recursive. I've also set up soft links to native modules from ics-openvpn in app, so that we don't copy files in Gradle (which was causing problems with the submodules .git* files, not being copied). That makes the repo cleaner.
Diffstat (limited to 'app/jni')
l---------app/jni1
-rw-r--r--app/jni/Android.mk77
-rw-r--r--app/jni/Application.mk11
-rw-r--r--app/jni/dummy.cpp8
-rw-r--r--app/jni/jbcrypto.cpp95
-rw-r--r--app/jni/jniglue.c24
-rw-r--r--app/jni/jniglue.h21
-rw-r--r--app/jni/minivpn.c0
-rw-r--r--app/jni/scan_ifs.c109
9 files changed, 1 insertions, 345 deletions
diff --git a/app/jni b/app/jni
new file mode 120000
index 00000000..e3180412
--- /dev/null
+++ b/app/jni
@@ -0,0 +1 @@
+../ics-openvpn/main/jni \ No newline at end of file
diff --git a/app/jni/Android.mk b/app/jni/Android.mk
deleted file mode 100644
index df8cbb34..00000000
--- a/app/jni/Android.mk
+++ /dev/null
@@ -1,77 +0,0 @@
-# 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
-
-ifeq ($(TARGET_ARCH),mips)
- USE_BREAKPAD=0
-endif
-ifeq ($(TARGET_ARCH),mips64)
- USE_BREAKPAD=0
-endif
-
-ifneq ($(USE_BREAKPAD),0)
- WITH_BREAKPAD=1
- include google-breakpad/android/google_breakpad/Android.mk
-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_CFLAGS = --std=c99
-LOCAL_C_INCLUDES := openssl/include openssl/crypto openssl
-LOCAL_SRC_FILES:= jniglue.c jbcrypto.cpp scan_ifs.c
-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/app/jni/Application.mk b/app/jni/Application.mk
deleted file mode 100644
index 21718248..00000000
--- a/app/jni/Application.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-APP_ABI := arm64-v8a armeabi armeabi-v7a mips x86 x86_64
-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/app/jni/dummy.cpp b/app/jni/dummy.cpp
deleted file mode 100644
index 58466656..00000000
--- a/app/jni/dummy.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-/*#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/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;
-
-}
diff --git a/app/jni/jniglue.c b/app/jni/jniglue.c
deleted file mode 100644
index 12e67543..00000000
--- a/app/jni/jniglue.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <jni.h>
-#include <android/log.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-
-#include "jniglue.h"
-
-jint JNI_OnLoad(JavaVM *vm, void *reserved) {
-#ifndef NDEBUG
- __android_log_write(ANDROID_LOG_DEBUG,"openvpn", "Loading openvpn native library $id$ compiled on " __DATE__ " " __TIME__ );
-#endif
- 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/app/jni/jniglue.h b/app/jni/jniglue.h
deleted file mode 100644
index 8f813b64..00000000
--- a/app/jni/jniglue.h
+++ /dev/null
@@ -1,21 +0,0 @@
-//
-// 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
-
-#ifdef __cplusplus
-extern "C" {
-#endif
- int jniThrowException(JNIEnv* env, const char* className, const char* msg);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/app/jni/minivpn.c b/app/jni/minivpn.c
deleted file mode 100644
index e69de29b..00000000
--- a/app/jni/minivpn.c
+++ /dev/null
diff --git a/app/jni/scan_ifs.c b/app/jni/scan_ifs.c
deleted file mode 100644
index e0024c54..00000000
--- a/app/jni/scan_ifs.c
+++ /dev/null
@@ -1,109 +0,0 @@
-#include <jni.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/ioctl.h>
-#include <linux/if.h>
-#include <android/log.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include "jniglue.h"
-
-jobjectArray Java_de_blinkt_openvpn_core_NativeUtils_getIfconfig(JNIEnv* env)
-{
-
- int sd;
- if ((sd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "Opening socket for intface get failed");
- //jniThrowException(env, "java/lang/IllegalArgumentException", "Opening socket for intface get failed");
- return NULL;
- }
-
- struct ifreq ifs[23];
-
- struct ifconf ifc;
- ifc.ifc_req = ifs;
- ifc.ifc_len = sizeof (ifs);
-
- if (ioctl (sd, SIOCGIFCONF, &ifc) < 0) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "IOCTL for intface get failed");
- //jniThrowException(env, "java/lang/IllegalArgumentException", "IOTCL socket for intface get failed");
- return NULL;
- }
-
-
-
-
- char buf[NI_MAXHOST];
-
- int ji=0;
-
- /*
- jtmp = (*env)->NewStringUTF(env, "HALLO WELT");
- (*env)->SetObjectArrayElement(env, ret, ji++, jtmp);
- */
-
- size_t num_intf=ifc.ifc_len / sizeof(struct ifreq);
- jobjectArray ret= (jobjectArray) (*env)->NewObjectArray(env, num_intf*3,(*env)->FindClass(env, "java/lang/String"), NULL);
-
- for (struct ifreq* ifr = ifc.ifc_req; ifr < ifs + num_intf; ifr++) {
-
- if (ifr->ifr_addr.sa_family != AF_INET) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "NOT AF_INET: %s", ifr->ifr_name);
- continue;
- }
-
- /* get interface addr, prefilled by SIOGIFCONF */
-
- int err;
- if (err=getnameinfo(&ifr->ifr_addr, sizeof(struct sockaddr_in), buf, NI_MAXHOST, NULL, 0,
- NI_NUMERICHOST) !=0) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "getnameinfo failed for %s: %s", ifr->ifr_name, gai_strerror(err));
- continue;
- }
- jstring jaddr = (*env)->NewStringUTF(env, buf);
- jstring jname = (*env)->NewStringUTF(env, ifr->ifr_name);
-
-
- struct ifreq ifreq;
- strncpy (ifreq.ifr_name, ifr->ifr_name, sizeof (ifreq.ifr_name));
-
- /* interface is up */
- if (ioctl (sd, SIOCGIFFLAGS, &ifreq) < 0) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "SIOCGIFFLAGS failed for %s: %s", ifr->ifr_name, strerror(errno));
- continue;
- }
-
- if (!(ifreq.ifr_flags & IFF_UP)) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "IFF_UP failed for %s", ifr->ifr_name);
- continue;
- }
-
- /* interface netmask */
- if (ioctl (sd, SIOCGIFNETMASK, &ifreq) < 0) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "SIOCIFNETMASK failed for %s: %s", ifr->ifr_name, strerror(errno));
- continue;
- }
-
- if (err=getnameinfo(&ifreq.ifr_netmask, sizeof(struct sockaddr_in), buf, NI_MAXHOST, NULL, 0,
- NI_NUMERICHOST) !=0) {
- __android_log_print(ANDROID_LOG_DEBUG, "openvpn", "getnameinfo failed for %s: %s", ifr->ifr_name, gai_strerror(err));
- continue;
- }
- jstring jnetmask = (*env)->NewStringUTF(env, buf);
-
- (*env)->SetObjectArrayElement(env, ret, ji++, jname);
- (*env)->SetObjectArrayElement(env, ret, ji++, jaddr);
- (*env)->SetObjectArrayElement(env, ret, ji++, jnetmask);
- }
- if (sd >= 0)
- close (sd);
-
- return ret;
-}
-