return KeyChain.getPrivateKey(getApplicationContext(), mCurrentUserCertificateAlias);
}
+ /**
+ * Function called via JNI to request a password from the user.
+ *
+ * Note that this method is called from a thread of charon's thread pool.
+ *
+ * @return the password
+ */
+ private String getPassword()
+ {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ {
+ return mPasswordPrompt.getPassword();
+ }
+ return null;
+ }
+
/**
* Initialization of charon, provided by libandroidbridge.so
*
return NULL;
}
+METHOD(charonservice_t, get_password, char*,
+ private_charonservice_t *this)
+{
+ JNIEnv *env;
+ jmethodID method_id;
+ jstring jpassword;
+ char *pwd = NULL;
+
+ androidjni_attach_thread(&env);
+
+ method_id = (*env)->GetMethodID(env, android_charonvpnservice_class,
+ "getPassword", "()Ljava/lang/String;");
+ if (!method_id)
+ {
+ goto failed;
+ }
+ jpassword = (*env)->CallObjectMethod(env, this->vpn_service, method_id);
+ if (androidjni_exception_occurred(env) || !jpassword)
+ {
+ goto failed;
+ }
+ pwd = androidjni_convert_jstring(env, jpassword);
+
+failed:
+ androidjni_exception_occurred(env);
+ androidjni_detach_thread();
+ return pwd;
+}
+
METHOD(charonservice_t, get_vpnservice_builder, vpnservice_builder_t*,
private_charonservice_t *this)
{
.get_trusted_certificates = _get_trusted_certificates,
.get_user_certificate = _get_user_certificate,
.get_user_key = _get_user_key,
+ .get_password = _get_password,
.get_vpnservice_builder = _get_vpnservice_builder,
.get_network_manager = _get_network_manager,
},
/*
- * Copyright (C) 2012-2013 Tobias Brunner
+ * Copyright (C) 2012-2020 Tobias Brunner
* Copyright (C) 2012 Giuliano Grassi
* Copyright (C) 2012 Ralf Sager
* HSR Hochschule fuer Technik Rapperswil
*/
private_key_t *(*get_user_key)(charonservice_t *this, public_key_t *pubkey);
+ /**
+ * Get a password from the user via JNI
+ *
+ * @return allocated password, NULL on failure
+ */
+ char *(*get_password)(charonservice_t *this);
+
/**
* Get the current vpnservice_builder_t object
*