summaryrefslogtreecommitdiff
path: root/jni/jbcrypto.cpp
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2012-07-15 17:01:33 +0200
committerArne Schwabe <arne@rfc2549.org>2012-07-15 17:01:33 +0200
commitf0bc455648301570d4897b1342146e406af28dd9 (patch)
treef28a5dbf8299efb5125687f46cbb95bc26e04495 /jni/jbcrypto.cpp
parentba4844b8a72d7149af5774a4abdbf44fea90d662 (diff)
Add warning if no dns is set.
Check in a working copy of jbcrypto
Diffstat (limited to 'jni/jbcrypto.cpp')
-rw-r--r--jni/jbcrypto.cpp29
1 files changed, 26 insertions, 3 deletions
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 <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_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);