diff options
author | cyBerta <cyberta@riseup.net> | 2018-02-01 16:45:45 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2018-02-01 16:45:45 +0100 |
commit | a73104923c7313243ae8828ced39f0ac223dc1ff (patch) | |
tree | 37ddaeafae2fcd6df6b3a4b826656701a77c3648 /main/jni | |
parent | 498e9a6264e51ce36c11df7587d6f82395172ac7 (diff) | |
parent | 97e2e6674ad1aff81b7b7d94e96594a532c40367 (diff) |
#8832 update upstream deps
Diffstat (limited to 'main/jni')
-rw-r--r-- | main/jni/Android.mk | 4 | ||||
-rw-r--r-- | main/jni/Application.mk | 2 | ||||
-rw-r--r-- | main/jni/jbcrypto.cpp | 98 | ||||
-rw-r--r-- | main/jni/jniglue.c | 33 | ||||
-rw-r--r-- | main/jni/jniglue.h | 21 | ||||
-rw-r--r-- | main/jni/scan_ifs.c | 109 |
6 files changed, 4 insertions, 263 deletions
diff --git a/main/jni/Android.mk b/main/jni/Android.mk index 5848edd6..32a76dc0 100644 --- a/main/jni/Android.mk +++ b/main/jni/Android.mk @@ -52,8 +52,10 @@ LOCAL_PATH := $(JNI_DIR) include $(CLEAR_VARS) LOCAL_LDLIBS := -llog -lz LOCAL_CFLAGS = -DTARGET_ARCH_ABI=\"${TARGET_ARCH_ABI}\" -LOCAL_SRC_FILES:= jniglue.c scan_ifs.c +LOCAL_SRC_FILES:= jniglue.c scan_ifs.c sslspeed.c +LOCAL_C_INCLUDES := openssl/include openssl/crypto openssl openssl/crypto/include LOCAL_MODULE = opvpnutil +LOCAL_STATIC_LIBRARIES := libssl_static libcrypto_static include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) diff --git a/main/jni/Application.mk b/main/jni/Application.mk index 838c2eba..7033ee93 100644 --- a/main/jni/Application.mk +++ b/main/jni/Application.mk @@ -2,7 +2,7 @@ ifeq ($(USE_SHORT_COMMANDS),1) APP_SHORT_COMMANDS := true endif -APP_ABI := arm64-v8a armeabi armeabi-v7a x86 x86_64 +APP_ABI := arm64-v8a armeabi-v7a x86 x86_64 APP_PLATFORM := android-14 #APP_STL:=stlport_static diff --git a/main/jni/jbcrypto.cpp b/main/jni/jbcrypto.cpp deleted file mode 100644 index 810a3bc7..00000000 --- a/main/jni/jbcrypto.cpp +++ /dev/null @@ -1,98 +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 <internal/cryptlib.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> - -#include <internal/evp_int.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/main/jni/jniglue.c b/main/jni/jniglue.c deleted file mode 100644 index bb5ec688..00000000 --- a/main/jni/jniglue.c +++ /dev/null @@ -1,33 +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); -} - - -//! Hack to get the current installed ABI of the libraries. See also https://github.com/schwabe/ics-openvpn/issues/391 -jstring Java_de_blinkt_openvpn_core_NativeUtils_getNativeAPI(JNIEnv *env, jclass jo) -{ - - return (*env)->NewStringUTF(env, TARGET_ARCH_ABI); -} diff --git a/main/jni/jniglue.h b/main/jni/jniglue.h deleted file mode 100644 index 8f813b64..00000000 --- a/main/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/main/jni/scan_ifs.c b/main/jni/scan_ifs.c deleted file mode 100644 index a26e2b36..00000000 --- a/main/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; -} - |