aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2017-01-03 11:38:43 +0100
committerylecollen <ylecollen@amdocs.com>2017-01-03 11:38:43 +0100
commitde962ef8d7f0dd447274dc88d9630caa6614379b (patch)
treee3de53b9d412274cecf6afb30f10ed666a1f3387
parente7c7d77a8a170ed9b85eb8b6ccc060ff09e63f24 (diff)
encryptMessage : the UTF8 conversion is done on JAVA side.
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java8
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp12
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h2
3 files changed, 13 insertions, 9 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
index 4c09313..7278d0f 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
@@ -235,12 +235,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
String retValue = null;
if(!TextUtils.isEmpty(aClearMsg)) {
- retValue = encryptMessageJni(aClearMsg);
+ try {
+ retValue = encryptMessageJni(aClearMsg.getBytes("UTF-8"));
+ } catch (Exception e) {
+ Log.e(LOG_TAG, "## encryptMessage() failed " + e.getMessage());
+ }
}
return retValue;
}
- private native String encryptMessageJni(String aClearMsg);
+ private native String encryptMessageJni(byte[] aClearMsgBuffer);
/**
* Return true the object resources have been released.<br>
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
index 2dad00a..3ee3db7 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
@@ -262,30 +262,30 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
}
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jstring aClearMsg)
+JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer)
{
LOGD("## encryptMessageJni(): IN");
jstring encryptedMsgRetValue = 0;
OlmOutboundGroupSession *sessionPtr = NULL;
- const char *clearMsgPtr = NULL;
+ jbyte* clearMsgPtr = NULL;
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
{
LOGE(" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL");
}
- else if (!aClearMsg)
+ else if (!aClearMsgBuffer)
{
LOGE(" ## encryptMessageJni(): failure - invalid clear message");
}
- else if (!(clearMsgPtr = env->GetStringUTFChars(aClearMsg, 0)))
+ else if (!(clearMsgPtr = env->GetByteArrayElements(aClearMsgBuffer, NULL)))
{
LOGE(" ## encryptMessageJni(): failure - clear message JNI allocation OOM");
}
else
{
// get clear message length
- size_t clearMsgLength = (size_t)env->GetStringUTFLength(aClearMsg);
+ size_t clearMsgLength = (size_t)env->GetArrayLength(aClearMsgBuffer);
LOGD(" ## encryptMessageJni(): clearMsgLength=%lu",static_cast<long unsigned int>(clearMsgLength));
// compute max encrypted length
@@ -325,7 +325,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
// free alloc
if (clearMsgPtr)
{
- env->ReleaseStringUTFChars(aClearMsg, clearMsgPtr);
+ env->ReleaseByteArrayElements(aClearMsgBuffer, clearMsgPtr, JNI_ABORT);
}
return encryptedMsgRetValue;
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
index 2fc44f8..f7e8a21 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
@@ -37,7 +37,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz);
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jstring aClearMsgPtr);
+JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer);
// serialization
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jstring aKey, jobject aErrorMsg);