From 1c664e15c7bf36098025f15ec6e4e835adff997e Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Sun, 15 Jul 2012 17:01:33 +0200 Subject: Add warning if no dns is set. Check in a working copy of jbcrypto --- jni/Android.mk | 2 +- jni/jbcrypto.cpp | 29 ++++++++++++++++++++++++++--- res/values/strings.xml | 1 + src/de/blinkt/openvpn/OpenVpnService.java | 15 ++++++++++----- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/jni/Android.mk b/jni/Android.mk index 761fa005..3de07059 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -25,7 +25,7 @@ include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_LDLIBS := -llog LOCAL_SRC_FILES:= minivpn.c -LOCAL_MODULE = minivp +LOCAL_MODULE = minivpn LOCAL_SHARED_LIBRARIES=openvpn include $(BUILD_EXECUTABLE) diff --git a/jni/jbcrypto.cpp b/jni/jbcrypto.cpp index 0c56b974..8bc6fb8d 100644 --- a/jni/jbcrypto.cpp +++ b/jni/jbcrypto.cpp @@ -12,11 +12,34 @@ #include #include #include +#include +#include + extern "C" { jbyteArray Java_de_blinkt_openvpn_OpenVpnManagementThread_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; +} + jbyteArray Java_de_blinkt_openvpn_OpenVpnManagementThread_rsasign(JNIEnv* env, jclass, jbyteArray from, jint pkeyRef) { @@ -32,9 +55,10 @@ jbyteArray Java_de_blinkt_openvpn_OpenVpnManagementThread_rsasign(JNIEnv* env, j jbyte* data = env-> GetByteArrayElements (from, NULL); int datalen = env-> GetArrayLength(from); - if(data==NULL || datalen == ) + if(data==NULL ) + jniThrowException(env, "java/lang/NullPointerException", "data is null"); - unsigned int siglen; + unsigned int siglen; unsigned char* sigret = (unsigned char*)malloc(RSA_size(pkey->pkey.rsa)); @@ -46,7 +70,6 @@ jbyteArray Java_de_blinkt_openvpn_OpenVpnManagementThread_rsasign(JNIEnv* env, j sigret, &siglen, pkey->pkey.rsa) <= 0 ) { - ERR_print_errors(errbio); jniThrowException(env, "java/security/InvalidKeyException", "rsa_sign went wrong, see logcat"); ERR_print_errors_fp(stderr); diff --git a/res/values/strings.xml b/res/values/strings.xml index 6fa78150..b6d43e91 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -233,6 +233,7 @@ Obscure OpenVPN Settings. Normally not needed. Advanced ICS Openvpn Config + No DNS servers being used. Name resolution may not work. Consider setting custom DNS Servers \ No newline at end of file diff --git a/src/de/blinkt/openvpn/OpenVpnService.java b/src/de/blinkt/openvpn/OpenVpnService.java index c50196b8..102e5d59 100644 --- a/src/de/blinkt/openvpn/OpenVpnService.java +++ b/src/de/blinkt/openvpn/OpenVpnService.java @@ -241,7 +241,8 @@ public class OpenVpnService extends VpnService implements StateListener { for (String dns : mDnslist ) { builder.addDnsServer(dns); } - + + builder.setMtu(mMtu); @@ -283,7 +284,11 @@ public class OpenVpnService extends VpnService implements StateListener { OpenVPN.logBuilderConfig(bconfig); - + + // No DNS Server, log a warning + if(mDnslist.size()==0) + OpenVPN.logInfo(R.string.warn_no_dns); + // Reset information mDnslist.clear(); mRoutes.clear(); @@ -393,10 +398,10 @@ public class OpenVpnService extends VpnService implements StateListener { } // Skip exiting status if the status is already hidden - if("EXITING SIGINT".equals(state) && !mNotificationvisible) { + if(("EXITING SIGINT".equals(state) || "EXITING".equals(state)) + && !mNotificationvisible) { return; - } - + } if("BYTECOUNT".equals(state)) { if(mDisplayBytecount) { -- cgit v1.2.3