From 38ad727c61a7525fbeca5303c49a3415abd8c942 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Tue, 20 Sep 2016 13:13:39 +0200 Subject: [PATCH] Added JNI wrapper for TLS certificate/key related methods in LinphoneCore and LinphoneAuthInfo --- coreapi/linphonecore_jni.cc | 128 ++++++++++++++++++ .../org/linphone/core/LinphoneAuthInfo.java | 48 +++++++ .../org/linphone/core/LinphoneCore.java | 48 +++++++ .../linphone/core/LinphoneAuthInfoImpl.java | 50 ++++++- .../org/linphone/core/LinphoneCoreImpl.java | 48 +++++++ 5 files changed, 321 insertions(+), 1 deletion(-) diff --git a/coreapi/linphonecore_jni.cc b/coreapi/linphonecore_jni.cc index 177bdc6c8..d3d071323 100644 --- a/coreapi/linphonecore_jni.cc +++ b/coreapi/linphonecore_jni.cc @@ -2995,6 +2995,74 @@ JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getHa1 } } +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setTlsCertificate +(JNIEnv *env, jobject, jlong auth_info, jstring jcert) { + const char* cert = GetStringUTFChars(env, jcert); + linphone_auth_info_set_tls_cert((LinphoneAuthInfo*)auth_info,cert); + ReleaseStringUTFChars(env, jcert, cert); +} + +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setTlsKey +(JNIEnv *env, jobject, jlong auth_info, jstring jkey) { + const char* key = GetStringUTFChars(env, jkey); + linphone_auth_info_set_tls_key((LinphoneAuthInfo*)auth_info,key); + ReleaseStringUTFChars(env, jkey, key); +} + +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setTlsCertificatePath +(JNIEnv *env, jobject, jlong auth_info, jstring jpath) { + const char* path = GetStringUTFChars(env, jpath); + linphone_auth_info_set_tls_cert_path((LinphoneAuthInfo*)auth_info,path); + ReleaseStringUTFChars(env, jpath, path); +} + +JNIEXPORT void JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_setTlsKeyPath +(JNIEnv *env, jobject, jlong auth_info, jstring jpath) { + const char* path = GetStringUTFChars(env, jpath); + linphone_auth_info_set_tls_key_path((LinphoneAuthInfo*)auth_info,path); + ReleaseStringUTFChars(env, jpath, path); +} + +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getTlsCertificate +(JNIEnv *env , jobject, jlong auth_info) { + const char* cert = linphone_auth_info_get_tls_cert((LinphoneAuthInfo*)auth_info); + if (cert) { + return env->NewStringUTF(cert); + } else { + return NULL; + } +} + +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getTlsKey +(JNIEnv *env , jobject, jlong auth_info) { + const char* key = linphone_auth_info_get_tls_key((LinphoneAuthInfo*)auth_info); + if (key) { + return env->NewStringUTF(key); + } else { + return NULL; + } +} + +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getTlsCertificatePath +(JNIEnv *env , jobject, jlong auth_info) { + const char* path = linphone_auth_info_get_tls_cert_path((LinphoneAuthInfo*)auth_info); + if (path) { + return env->NewStringUTF(path); + } else { + return NULL; + } +} + +JNIEXPORT jstring JNICALL Java_org_linphone_core_LinphoneAuthInfoImpl_getTlsKeyPath +(JNIEnv *env , jobject, jlong auth_info) { + const char* path = linphone_auth_info_get_tls_key_path((LinphoneAuthInfo*)auth_info); + if (path) { + return env->NewStringUTF(path); + } else { + return NULL; + } +} + //LinphoneAddress @@ -8200,4 +8268,64 @@ extern "C" jobject Java_org_linphone_core_LinphoneAccountCreatorImpl_configure(J LinphoneCoreVTable *table = linphone_core_get_current_vtable(lc); LinphoneCoreData* lcData = (LinphoneCoreData*)linphone_core_v_table_get_user_data(table); return getProxy(env, lpc, lcData->core); +} + +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setTlsCertificate(JNIEnv *env, jobject thiz, jlong lc, jstring jcert) { + const char* cert = GetStringUTFChars(env, jcert); + linphone_core_set_tls_cert((LinphoneCore*)lc, cert); + ReleaseStringUTFChars(env, jcert, cert); +} + +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setTlsKey(JNIEnv *env, jobject, jlong lc, jstring jkey) { + const char* key = GetStringUTFChars(env, jkey); + linphone_core_set_tls_key((LinphoneCore*)lc, key); + ReleaseStringUTFChars(env, jkey, key); +} + +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setTlsCertificatePath(JNIEnv *env, jobject, jlong lc, jstring jpath) { + const char* path = GetStringUTFChars(env, jpath); + linphone_core_set_tls_cert_path((LinphoneCore*)lc, path); + ReleaseStringUTFChars(env, jpath, path); +} + +extern "C" void Java_org_linphone_core_LinphoneCoreImpl_setTlsKeyPath(JNIEnv *env, jobject, jlong lc, jstring jpath) { + const char* path = GetStringUTFChars(env, jpath); + linphone_core_set_tls_key_path((LinphoneCore*)lc, path); + ReleaseStringUTFChars(env, jpath, path); +} + +extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getTlsCertificate(JNIEnv *env , jobject, jlong lc) { + const char* cert = linphone_core_get_tls_cert((LinphoneCore*)lc); + if (cert) { + return env->NewStringUTF(cert); + } else { + return NULL; + } +} + +extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getTlsKey(JNIEnv *env , jobject, jlong lc) { + const char* key = linphone_core_get_tls_key((LinphoneCore*)lc); + if (key) { + return env->NewStringUTF(key); + } else { + return NULL; + } +} + +extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getTlsCertificatePath(JNIEnv *env , jobject, jlong lc) { + const char* path = linphone_core_get_tls_cert_path((LinphoneCore*)lc); + if (path) { + return env->NewStringUTF(path); + } else { + return NULL; + } +} + +extern "C" jstring Java_org_linphone_core_LinphoneCoreImpl_getTlsKeyPath(JNIEnv *env , jobject, jlong lc) { + const char* path = linphone_core_get_tls_key_path((LinphoneCore*)lc); + if (path) { + return env->NewStringUTF(path); + } else { + return NULL; + } } \ No newline at end of file diff --git a/java/common/org/linphone/core/LinphoneAuthInfo.java b/java/common/org/linphone/core/LinphoneAuthInfo.java index 6b71d006b..c17c33683 100644 --- a/java/common/org/linphone/core/LinphoneAuthInfo.java +++ b/java/common/org/linphone/core/LinphoneAuthInfo.java @@ -100,6 +100,54 @@ public interface LinphoneAuthInfo { * @return the clone auth info */ LinphoneAuthInfo clone(); + + /** + * Gets the TLS certificate + * @return the TLS certificate + */ + String getTlsCertificate(); + + /** + * Gets the TLS key file + * @return the TLS key + */ + String getTlsKey(); + + /** + * Gets the path to the TLS certificate file + * @return the path to the TLS certificate + */ + String getTlsCertificatePath(); + + /** + * Gets the path to the TLS key file + * @return the path to the TLS key + */ + String getTlsKeyPath(); + + /** + * Sets the TLS certificate + * @param cert the certificate + */ + void setTlsCertificate(String cert); + + /** + * Sets the TLS key + * @param key the key + */ + void setTlsKey(String key); + + /** + * Sets the TLS certificate file path + * @param path the path of the certificate + */ + void setTlsCertificatePath(String path); + + /** + * Sets the TLS key file path + * @param path the path of the key + */ + void setTlsKeyPath(String path); } diff --git a/java/common/org/linphone/core/LinphoneCore.java b/java/common/org/linphone/core/LinphoneCore.java index 5b1b94973..cf7db8aba 100644 --- a/java/common/org/linphone/core/LinphoneCore.java +++ b/java/common/org/linphone/core/LinphoneCore.java @@ -2448,4 +2448,52 @@ public interface LinphoneCore { public void setLimeEncryption(LinphoneLimeState lime); public LinphoneLimeState getLimeEncryption(); + + /** + * Gets the TLS certificate + * @return the TLS certificate + */ + public String getTlsCertificate(); + + /** + * Gets the TLS key file + * @return the TLS key + */ + public String getTlsKey(); + + /** + * Gets the path to the TLS certificate file + * @return the path to the TLS certificate + */ + public String getTlsCertificatePath(); + + /** + * Gets the path to the TLS key file + * @return the path to the TLS key + */ + public String getTlsKeyPath(); + + /** + * Sets the TLS certificate + * @param cert the certificate + */ + public void setTlsCertificate(String cert); + + /** + * Sets the TLS key + * @param key the key + */ + public void setTlsKey(String key); + + /** + * Sets the TLS certificate file path + * @param path the path of the certificate + */ + public void setTlsCertificatePath(String path); + + /** + * Sets the TLS key file path + * @param path the path of the key + */ + public void setTlsKeyPath(String path); } diff --git a/java/impl/org/linphone/core/LinphoneAuthInfoImpl.java b/java/impl/org/linphone/core/LinphoneAuthInfoImpl.java index f67aa4c94..26a416915 100644 --- a/java/impl/org/linphone/core/LinphoneAuthInfoImpl.java +++ b/java/impl/org/linphone/core/LinphoneAuthInfoImpl.java @@ -30,10 +30,18 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo { private native void setUsername(long ptr, String username); private native void setUserId(long ptr, String username); private native void setHa1(long ptr, String ha1); + private native void setDomain(long ptr, String domain); + private native void setTlsCertificate(long ptr, String cert); + private native void setTlsKey(long ptr, String key); + private native void setTlsCertificatePath(long ptr, String path); + private native void setTlsKeyPath(long ptr, String path); private native String getUserId(long ptr); private native String getHa1(long ptr); private native String getDomain(long ptr); - private native void setDomain(long ptr, String domain); + private native String getTlsCertificate(long ptr); + private native String getTlsKey(long ptr); + private native String getTlsCertificatePath(long ptr); + private native String getTlsKeyPath(long ptr); boolean ownPtr = false; protected LinphoneAuthInfoImpl(String username,String password, String realm, String domain) { @@ -111,4 +119,44 @@ class LinphoneAuthInfoImpl implements LinphoneAuthInfo { getDomain()); return clone; } + + @Override + public String getTlsCertificate() { + return getTlsCertificate(nativePtr); + } + + @Override + public String getTlsKey() { + return getTlsKey(nativePtr); + } + + @Override + public String getTlsCertificatePath() { + return getTlsCertificatePath(nativePtr); + } + + @Override + public String getTlsKeyPath() { + return getTlsKeyPath(nativePtr); + } + + @Override + public void setTlsCertificate(String cert) { + setTlsCertificate(nativePtr, cert); + } + + @Override + public void setTlsKey(String key) { + setTlsKey(nativePtr, key); + } + + @Override + public void setTlsCertificatePath(String path) { + setTlsCertificatePath(nativePtr, path); + } + + @Override + public void setTlsKeyPath(String path) { + setTlsKeyPath(nativePtr, path); + } } diff --git a/java/impl/org/linphone/core/LinphoneCoreImpl.java b/java/impl/org/linphone/core/LinphoneCoreImpl.java index 58bb250d2..5fdeab764 100644 --- a/java/impl/org/linphone/core/LinphoneCoreImpl.java +++ b/java/impl/org/linphone/core/LinphoneCoreImpl.java @@ -1726,4 +1726,52 @@ class LinphoneCoreImpl implements LinphoneCore { public synchronized LinphoneLimeState getLimeEncryption() { return LinphoneLimeState.fromInt(getLimeEncryption(nativePtr)); } + + private native String getTlsCertificate(long ptr); + @Override + public String getTlsCertificate() { + return getTlsCertificate(nativePtr); + } + + private native String getTlsKey(long ptr); + @Override + public String getTlsKey() { + return getTlsKey(nativePtr); + } + + private native String getTlsCertificatePath(long ptr); + @Override + public String getTlsCertificatePath() { + return getTlsCertificatePath(nativePtr); + } + + private native String getTlsKeyPath(long ptr); + @Override + public String getTlsKeyPath() { + return getTlsKeyPath(nativePtr); + } + + private native void setTlsCertificate(long ptr, String cert); + @Override + public void setTlsCertificate(String cert) { + setTlsCertificate(nativePtr, cert); + } + + private native void setTlsKey(long ptr, String key); + @Override + public void setTlsKey(String key) { + setTlsKey(nativePtr, key); + } + + private native void setTlsCertificatePath(long ptr, String path); + @Override + public void setTlsCertificatePath(String path) { + setTlsCertificatePath(nativePtr, path); + } + + private native void setTlsKeyPath(long ptr, String path); + @Override + public void setTlsKeyPath(String path) { + setTlsKeyPath(nativePtr, path); + } }