Commit 9552e14f authored by ylecollen's avatar ylecollen
Browse files

-> the byte[] to String conversions are done on Java level (when it is possible)

-> remove javaCStringToUtf8
parent 765647cd
......@@ -118,7 +118,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
} else {
aErrorMsg.setLength(0);
try {
pickleRetValue = serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg);
pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
aErrorMsg.append(e.getMessage());
......@@ -127,7 +127,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
return pickleRetValue;
}
private native String serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
/**
......@@ -164,6 +164,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
return retCode;
}
private native String initWithSerializedDataJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
/**
......@@ -363,25 +364,34 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
* @return the signed message if operation succeed, null otherwise
*/
public String signMessage(String aMessage) {
if (null == aMessage) {
return null;
}
String result = null;
byte[] utf8String = null;
if (null != aMessage) {
byte[] utf8String = null;
try {
utf8String = aMessage.getBytes("UTF-8");
} catch (Exception e) {
Log.d(LOG_TAG,"## signMessage(): failed ="+e.getMessage());
}
try {
utf8String = aMessage.getBytes("UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## signMessage(): failed =" + e.getMessage());
}
if (null == utf8String) {
return null;
if (null != utf8String) {
byte[] signedMessage = signMessageJni(utf8String);
if (null != signedMessage) {
try {
result = new String(signedMessage, "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## signMessage(): failed =" + e.getMessage());
}
}
}
}
return signMessageJni(utf8String);
return result;
}
private native String signMessageJni(byte[] aMessage);
private native byte[] signMessageJni(byte[] aMessage);
/**
* Return true the object resources have been released.<br>
......
......@@ -144,10 +144,16 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @return the session ID if operation succeed, null otherwise
*/
public String sessionIdentifier() {
return sessionIdentifierJni();
try {
return new String(sessionIdentifierJni(), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## sessionIdentifier() failed " + e.getMessage());
}
return null;
}
private native String sessionIdentifierJni();
private native byte[] sessionIdentifierJni();
/**
* Decrypt the message passed in parameter.<br>
......@@ -161,9 +167,14 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
StringBuffer errorMsg = new StringBuffer();
try {
result.mDecryptedMessage = decryptMessageJni(aEncryptedMsg.getBytes("UTF-8"), result, errorMsg);
byte[] decryptedMessageBuffer = decryptMessageJni(aEncryptedMsg.getBytes("UTF-8"), result, errorMsg);
if (null != decryptedMessageBuffer) {
result.mDecryptedMessage = new String(decryptedMessageBuffer, "UTF-8");
}
} catch (Exception e) {
Log.e(LOG_TAG, "## decryptMessage() failed " + e.getMessage());
errorMsg.append(e.getMessage());
}
// check if there is an error while decrypting
......@@ -174,7 +185,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
return result;
}
private native String decryptMessageJni(byte[] aEncryptedMsg, DecryptMessageResult aDecryptMessageResult, StringBuffer aErrorMsg);
private native byte[] decryptMessageJni(byte[] aEncryptedMsg, DecryptMessageResult aDecryptMessageResult, StringBuffer aErrorMsg);
/**
* Kick off the serialization mechanism.
......@@ -226,9 +237,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
} else {
aErrorMsg.setLength(0);
try {
pickleRetValue = serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg);
pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
aErrorMsg.append(e.getMessage());
}
}
......@@ -240,7 +252,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise
*/
private native String serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
/**
......
......@@ -208,10 +208,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return session identifier if operation succeed, null otherwise.
*/
public String sessionIdentifier() {
return sessionIdentifierJni();
try {
return new String(sessionIdentifierJni(), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## sessionIdentifier() failed " + e.getMessage());
}
return null;
}
private native String sessionIdentifierJni();
private native byte[] sessionIdentifierJni();
/**
* Get the current message index for this session.<br>
......@@ -231,9 +237,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return outbound session key
*/
public String sessionKey() {
return sessionKeyJni();
try {
return new String(sessionKeyJni(), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## sessionKey() failed " + e.getMessage());
}
return null;
}
private native String sessionKeyJni();
private native byte[] sessionKeyJni();
/**
* Encrypt some plain-text message.<br>
......@@ -246,7 +259,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
if(!TextUtils.isEmpty(aClearMsg)) {
try {
retValue = encryptMessageJni(aClearMsg.getBytes("UTF-8"));
retValue = new String(encryptMessageJni(aClearMsg.getBytes("UTF-8")), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## encryptMessage() failed " + e.getMessage());
}
......@@ -254,7 +267,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return retValue;
}
private native String encryptMessageJni(byte[] aClearMsgBuffer);
private native byte[] encryptMessageJni(byte[] aClearMsgBuffer);
/**
* Return true the object resources have been released.<br>
......
......@@ -302,10 +302,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @return the session ID as a String if operation succeed, null otherwise
*/
public String sessionIdentifier() {
return getSessionIdentifierJni();
try {
return new String(getSessionIdentifierJni(), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## sessionIdentifier(): " + e.getMessage());
}
return null;
}
private native String getSessionIdentifierJni();
private native byte[] getSessionIdentifierJni();
/**
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br>
......@@ -383,10 +389,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @return the decrypted message if operation succeed, null otherwise
*/
public String decryptMessage(OlmMessage aEncryptedMsg) {
return decryptMessageJni(aEncryptedMsg);
try {
return new String(decryptMessageJni(aEncryptedMsg), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## decryptMessage(): failed " + e.getMessage());
}
return null;
}
private native String decryptMessageJni(OlmMessage aEncryptedMsg);
private native byte[] decryptMessageJni(OlmMessage aEncryptedMsg);
/**
* Return true the object resources have been released.<br>
......
......@@ -121,7 +121,7 @@ public class OlmUtility {
if (null != aMessageToHash) {
try {
hashRetValue = sha256Jni(aMessageToHash.getBytes("UTF-8"));
hashRetValue = new String(sha256Jni(aMessageToHash.getBytes("UTF-8")), "UTF-8");
} catch (Exception e) {
Log.e(LOG_TAG, "## sha256(): failed " + e.getMessage());
}
......@@ -130,7 +130,7 @@ public class OlmUtility {
return hashRetValue;
}
private native String sha256Jni(byte[] aMessage);
private native byte[] sha256Jni(byte[] aMessage);
/**
......
......@@ -405,10 +405,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
* @param aMessage message to sign
* @return the signed message, null otherwise
**/
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage)
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage)
{
OlmAccount* accountPtr = NULL;
jstring signedMsgRetValue = NULL;
jbyteArray signedMsgRetValueBuffer = NULL;
if (!aMessage)
{
......@@ -425,7 +425,8 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
// signature memory allocation
size_t signatureLength = olm_account_signature_length(accountPtr);
void* signedMsgPtr = malloc((signatureLength+1)*sizeof(uint8_t));
size_t bufferLen = signatureLength + 1;
void* signedMsgPtr = malloc(bufferLen * sizeof(uint8_t));
if (!signedMsgPtr)
{
......@@ -448,9 +449,12 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
{
// info: signatureLength is always equal to resultSign
(static_cast<char*>(signedMsgPtr))[signatureLength] = static_cast<char>('\0');
// convert to jstring
signedMsgRetValue = env->NewStringUTF((const char*)signedMsgPtr); // UTF8
LOGD("## signMessageJni(): success - retCode=%lu signatureLength=%lu", static_cast<long unsigned int>(resultSign), static_cast<long unsigned int>(signatureLength));
signedMsgRetValueBuffer = env->NewByteArray(signatureLength);
env->SetByteArrayRegion(signedMsgRetValueBuffer, 0 , signatureLength, (jbyte*)signedMsgPtr);
}
free(signedMsgPtr);
......@@ -463,7 +467,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
}
}
return signedMsgRetValue;
return signedMsgRetValueBuffer;
}
/**
......@@ -472,9 +476,9 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
**/
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
{
jstring pickledDataRetValue = 0;
jbyteArray pickledDataRetValue = 0;
jclass errorMsgJClass = 0;
jmethodID errorMsgMethodId = 0;
jstring errorJstring = 0;
......@@ -541,8 +545,11 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
{
// build success output
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
pickledDataRetValue = env->NewByteArray(pickledLength+1);
env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength+1, (jbyte*)pickledPtr);
}
free(pickledPtr);
......
......@@ -44,10 +44,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysForSessionJni)(JNIEnv *env,
JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz);
// signing
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);
// serialization
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer);
#ifdef __cplusplus
......
......@@ -137,10 +137,10 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
/**
* Get a base64-encoded identifier for this inbound group session.
*/
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
{
OlmInboundGroupSession *sessionPtr = NULL;
jstring returnValueStr=0;
jbyteArray returnValue = 0;
LOGD("## sessionIdentifierJni(): inbound group session IN");
......@@ -170,22 +170,26 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
}
else
{
// update length
sessionIdPtr[result] = static_cast<char>('\0');
LOGD(" ## sessionIdentifierJni(): success - inbound group session result=%lu sessionId=%s",static_cast<long unsigned int>(result), (char*)sessionIdPtr);
returnValueStr = env->NewStringUTF((const char*)sessionIdPtr);
returnValue = env->NewByteArray(result);
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);
}
free(sessionIdPtr);
}
}
return returnValueStr;
return returnValue;
}
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsgBuffer, jobject aDecryptionResult, jobject aErrorMsg)
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsgBuffer, jobject aDecryptionResult, jobject aErrorMsg)
{
jstring decryptedMsgRetValue = 0;
jbyteArray decryptedMsgBuffer = 0;
OlmInboundGroupSession *sessionPtr = NULL;
jbyte *encryptedMsgPtr = NULL;
jclass indexObjJClass = 0;
......@@ -298,17 +302,10 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
// update index
env->SetLongField(aDecryptionResult, indexMsgFieldId, (jlong)messageIndex);
// convert to utf8
decryptedMsgRetValue = javaCStringToUtf8(env, plainTextMsgPtr, plaintextLength);
decryptedMsgBuffer = env->NewByteArray(plaintextLength);
env->SetByteArrayRegion(decryptedMsgBuffer, 0 , plaintextLength, (jbyte*)plainTextMsgPtr);
if (!decryptedMsgRetValue)
{
LOGE(" ## decryptMessageJni(): UTF-8 Conversion failure - javaCStringToUtf8() returns null");
}
else
{
LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast<long unsigned int>(plaintextLength));
}
LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast<long unsigned int>(plaintextLength));
}
if (plainTextMsgPtr)
......@@ -330,7 +327,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
env->ReleaseByteArrayElements(aEncryptedMsgBuffer, encryptedMsgPtr, JNI_ABORT);
}
return decryptedMsgRetValue;
return decryptedMsgBuffer;
}
......@@ -340,9 +337,10 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
**/
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
{
jstring pickledDataRetValue = 0;
jbyteArray pickledDataRet = 0;
jclass errorMsgJClass = 0;
jmethodID errorMsgMethodId = 0;
jbyte* keyPtr = NULL;
......@@ -408,10 +406,11 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JN
}
else
{
// build success output
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
pickledDataRet = env->NewByteArray(pickledLength);
env->SetByteArrayRegion(pickledDataRet, 0 , pickledLength, (jbyte*)pickledPtr);
}
free(pickledPtr);
......@@ -424,7 +423,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JN
env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
}
return pickledDataRetValue;
return pickledDataRet;
}
......
......@@ -33,11 +33,11 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer);
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex, jobject aErrorMsg);
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex, jobject aErrorMsg);
// serialization
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
......
......@@ -74,7 +74,6 @@ jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jlong getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
jstring javaCStringToUtf8(JNIEnv *env, uint8_t *aCStringMsgPtr, size_t aMsgLength);
#ifdef __cplusplus
}
......
......@@ -213,45 +213,3 @@ jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_UTILITY);
return instanceId;
}
/**
* Convert a C string into a UTF-8 format string.
* The conversion is performed in JAVA side to workaround the issue in NewStringUTF().
* The problem is described here: https://github.com/eclipsesource/J2V8/issues/142
*/
jstring javaCStringToUtf8(JNIEnv *env, uint8_t *aCStringMsgPtr, size_t aMsgLength)
{
jstring convertedRetValue = 0;
jbyteArray tempByteArray = NULL;
if (!aCStringMsgPtr || !env)
{
LOGE("## javaCStringToUtf8(): failure - invalid parameters (null)");
}
else if (!(tempByteArray = env->NewByteArray(aMsgLength)))
{
LOGE("## javaCStringToUtf8(): failure - return byte array OOM");
}
else
{
env->SetByteArrayRegion(tempByteArray, 0, aMsgLength, (const jbyte*)aCStringMsgPtr);
// UTF-8 conversion from JAVA
jstring strEncode = (env)->NewStringUTF("UTF-8");
jclass jClass = env->FindClass("java/lang/String");
jmethodID cstor = env->GetMethodID(jClass, "<init>", "([BLjava/lang/String;)V");
if (jClass && strEncode)
{
convertedRetValue = (jstring) env->NewObject(jClass, cstor, tempByteArray, strEncode);
LOGD(" ## javaCStringToUtf8(): succeed");
env->DeleteLocalRef(tempByteArray);
}
else
{
LOGE(" ## javaCStringToUtf8(): failure - invalid Java references");
}
}
return convertedRetValue;
}
......@@ -138,12 +138,13 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
/**
* Get a base64-encoded identifier for this outbound group session.
*/
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
{
LOGD("## sessionIdentifierJni(): outbound group session IN");
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
jstring returnValueStr=0;
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
jbyteArray returnValue = 0;
if (!sessionPtr)
{
LOGE(" ## sessionIdentifierJni(): failure - invalid outbound group session instance");
......@@ -172,8 +173,11 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
{
// update length
sessionIdPtr[result] = static_cast<char>('\0');
returnValue = env->NewByteArray(result);
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);
LOGD(" ## sessionIdentifierJni(): success - outbound group session identifier result=%lu sessionId=%s",static_cast<long unsigned int>(result), reinterpret_cast<char*>(sessionIdPtr));
returnValueStr = env->NewStringUTF((const char*)sessionIdPtr);
}
// free alloc
......@@ -181,7 +185,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
}
}
return returnValueStr;
return returnValue;
}
......@@ -215,11 +219,12 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env,
/**
* Get the base64-encoded current ratchet key for this session.<br>
*/
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
{
LOGD("## sessionKeyJni(): outbound group session IN");
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
jstring returnValueStr = 0;
jbyteArray returnValue = 0;
if (!sessionPtr)
{
......@@ -250,7 +255,9 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
// update length
sessionKeyPtr[result] = static_cast<char>('\0');
LOGD(" ## sessionKeyJni(): success - outbound group session key result=%lu sessionKey=%s",static_cast<long unsigned int>(result), reinterpret_cast<char*>(sessionKeyPtr));
returnValueStr = env->NewStringUTF((const char*)sessionKeyPtr