Signed-off-by: Daniel Lenski <dlenski at gmail.com> --- .../infradead/libopenconnect/LibOpenConnect.java | 16 +++++ jni.c | 68 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/java/src/org/infradead/libopenconnect/LibOpenConnect.java b/java/src/org/infradead/libopenconnect/LibOpenConnect.java index ce4ffcc..c580f99 100644 --- a/java/src/org/infradead/libopenconnect/LibOpenConnect.java +++ b/java/src/org/infradead/libopenconnect/LibOpenConnect.java @@ -22,6 +22,12 @@ public abstract class LibOpenConnect { /* constants */ + public static final int OC_PROTO_PROXY = 1; + public static final int OC_PROTO_CSD = 2; + public static final int OC_PROTO_AUTH_CERT = 4; + public static final int OC_PROTO_AUTH_OTP = 8; + public static final int OC_PROTO_AUTH_STOKEN = 16; + public static final int OC_FORM_OPT_TEXT = 1; public static final int OC_FORM_OPT_PASSWORD = 2; public static final int OC_FORM_OPT_SELECT = 3; @@ -135,6 +141,7 @@ public abstract class LibOpenConnect { public synchronized native void setReqMTU(int mtu); public synchronized native void setPFS(boolean isEnabled); public synchronized native void setSystemTrust(boolean isEnabled); + public synchronized native int setProtocol(String protocol); /* connection info */ @@ -149,6 +156,7 @@ public abstract class LibOpenConnect { public synchronized native String getDTLSCipher(); public synchronized native String getCSTPCompression(); public synchronized native String getDTLSCompression(); + public synchronized native String getProtocol(); /* certificate info */ @@ -166,6 +174,7 @@ public abstract class LibOpenConnect { public static native boolean hasStokenSupport(); public static native boolean hasOATHSupport(); public static native boolean hasYubiOATHSupport(); + public static native VPNProto[] getSupportedProtocols(); /* public data structures */ @@ -265,6 +274,13 @@ public abstract class LibOpenConnect { public Object userData; }; + public static class VPNProto { + public String name; + public String prettyName; + public String description; + public int flags; + }; + /* Optional storage for caller's data */ public Object userData; diff --git a/jni.c b/jni.c index d72ac2e..4586136 100644 --- a/jni.c +++ b/jni.c @@ -1197,6 +1197,14 @@ JNIEXPORT jstring JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_getCS RETURN_STRING_END } +JNIEXPORT jstring JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_getProtocol( + JNIEnv *jenv, jobject jobj) +{ + RETURN_STRING_START + buf = openconnect_get_protocol(ctx->vpninfo); + RETURN_STRING_END +} + #define SET_STRING_START(ret) \ struct libctx *ctx = getctx(jenv, jobj); \ const char *arg = NULL; \ @@ -1247,6 +1255,16 @@ JNIEXPORT jint JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_setHTTPP return ret; } +JNIEXPORT jint JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_setProtocol( + JNIEnv *jenv, jobject jobj, jstring jarg) +{ + int ret; + SET_STRING_START(-ENOMEM) + ret = openconnect_set_protocol(ctx->vpninfo, arg); + SET_STRING_END(); + return ret; +} + JNIEXPORT void JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_setXMLSHA1( JNIEnv *jenv, jobject jobj, jstring jarg) { @@ -1381,3 +1399,53 @@ JNIEXPORT jobject JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_getIP return jobj; } + +JNIEXPORT jobjectArray JNICALL Java_org_infradead_libopenconnect_LibOpenConnect_getSupportedProtocols( + JNIEnv *jenv, jclass jcls) +{ + jmethodID mid; + jobjectArray result; + struct libctx ctx = { .jenv = jenv, .jobj = NULL, .async_lock = NULL, vpninfo = -1, loglevel = -1 }; + + /* call C library */ + struct oc_vpn_proto *protos; + int np, ii; + np = openconnect_get_supported_protocols(&protos); + if (np < 0) + return NULL; + + /* get VPNProto class, its init method, and create array */ + jcls = (*jenv)->FindClass(jenv, + "org/infradead/libopenconnect/LibOpenConnect$VPNProto"); + if (jcls == NULL) + goto err; + mid = (*jenv)->GetMethodID(jenv, jcls, "<init>", "()V"); + if (!mid) + goto err; + result = (*jenv)->NewObjectArray(jenv, np, jcls, NULL); + if (result == NULL) + goto nomem; + + for (ii=0; ii<np; ii++) { + jobject jobj = (*jenv)->NewObject(jenv, jcls, mid); + if (!jobj) + goto nomem; + + if (set_string(&ctx, jobj, "name", protos[ii].name) || + set_string(&ctx, jobj, "prettyName", protos[ii].pretty_name) || + set_string(&ctx, jobj, "description", protos[ii].description) || + set_int (&ctx, jobj, "flags", protos[ii].flags)) + goto nomem; + + (*jenv)->SetObjectArrayElement(jenv, result, ii, jobj); + } + + openconnect_free_supported_protocols(protos); + return result; + +nomem: + OOM(jenv); +err: + openconnect_free_supported_protocols(protos); + return NULL; +} -- 2.7.4