Repository: cloudflare/boringtun (language: rust)

Issue:
jni: create_new_tunnel requires psk
Calling `create_new_tunnel` without a preshared key is no longer possible since #215.

Passing `null` as argument does not work because `env.get_string_utf_chars` does not allow `null`, and empty strings are not allowed because of a check in `ffi::new_tunnel`.


Discussion / hints:

Fix patch:
diff --git a/boringtun/src/jni.rs b/boringtun/src/jni.rs
index 6fde5673..ecf60409 100644
--- a/boringtun/src/jni.rs
+++ b/boringtun/src/jni.rs
@@ -146,9 +146,13 @@ pub unsafe extern "C" fn create_new_tunnel(
         Err(_) => return 0,
     };
 
-    let preshared_key = match env.get_string_utf_chars(arg_preshared_key) {
-        Ok(v) => v,
-        Err(_) => return 0,
+    let preshared_key = if arg_preshared_key.is_null() {
+        ptr::null_mut()
+    } else {
+        match env.get_string_utf_chars(arg_preshared_key) {
+            Ok(v) => v,
+            Err(_) => return 0,
+        }
     };
 
     let tunnel = new_tunnel(


Test patch: