aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src')
-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);