Commit de962ef8 authored by ylecollen's avatar ylecollen
Browse files

encryptMessage : the UTF8 conversion is done on JAVA side.

parent e7c7d77a
......@@ -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>
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment