Commit ebfcd03c authored by pedroGitt's avatar pedroGitt
Browse files

- Add in/outbound group unit test OK

parent 10280995
package org.matrix.olm; package org.matrix.olm;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.junit.BeforeClass; import org.junit.BeforeClass;
...@@ -10,6 +11,7 @@ import org.junit.runner.RunWith; ...@@ -10,6 +11,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
...@@ -19,6 +21,15 @@ public class OlmGroupTest { ...@@ -19,6 +21,15 @@ public class OlmGroupTest {
private static final String LOG_TAG = "OlmSessionTest"; private static final String LOG_TAG = "OlmSessionTest";
private static OlmManager mOlmManager; private static OlmManager mOlmManager;
private static OlmOutboundGroupSession mAliceOutboundSession;
private static String mAliceSessionIdentifier;
private static long mAliceMessageIndex;
public static final String CLEAR_MESSAGE1 = "Hello!";
private static String mAliceToBobMessage;
private static OlmInboundGroupSession mBobInboundSession;
private static String mAliceOutboundSessionKey;
private static String mBobSessionIdentifier;
private static String mBobDecryptedMessage;
@BeforeClass @BeforeClass
public static void setUpClass(){ public static void setUpClass(){
...@@ -30,66 +41,112 @@ public class OlmGroupTest { ...@@ -30,66 +41,112 @@ public class OlmGroupTest {
Log.d(LOG_TAG, "## setUpClass(): lib version="+version); Log.d(LOG_TAG, "## setUpClass(): lib version="+version);
} }
@Test
public void test00AliceToBob() {
// TBD
}
/** /**
* Basic test: * Basic test:
* - alice creates an account
* - bob creates an account
* - alice creates an outbound group session * - alice creates an outbound group session
* - bob creates an inbound group session with alice's outbound session key * - bob creates an inbound group session with alice's outbound session key
* - alice encrypts a message with its session * - alice encrypts a message with its session
* - bob decrypts the encrypted message with its session * - bob decrypts the encrypted message with its session
* - decrypted message is identical to original alice message
*/ */
//@Test @Test
public void test01AliceToBob() { public void test01CreateOutboundSession() {
// creates alice outbound session // alice creates OUTBOUND GROUP SESSION
OlmOutboundGroupSession aliceOutboundSession = new OlmOutboundGroupSession(); try {
mAliceOutboundSession = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
}
}
@Test
public void test02GetOutboundGroupSessionIdentifier() {
// test session ID
mAliceSessionIdentifier = mAliceOutboundSession.sessionIdentifier();
assertNotNull(mAliceSessionIdentifier);
assertTrue(mAliceSessionIdentifier.length() > 0);
}
// test accounts creation @Test
String aliceSessionIdentifier = aliceOutboundSession.sessionIdentifier(); public void test03GetOutboundGroupSessionKey() {
assertNotNull(aliceSessionIdentifier); // test session Key
assertTrue(aliceSessionIdentifier.length()>0); mAliceOutboundSessionKey = mAliceOutboundSession.sessionKey();
assertNotNull(mAliceOutboundSessionKey);
assertTrue(mAliceOutboundSessionKey.length() > 0);
}
String aliceOutboundSessionKey = aliceOutboundSession.sessionKey(); @Test
assertNotNull(aliceOutboundSessionKey); public void test04GetOutboundGroupMessageIndex() {
assertTrue(aliceOutboundSessionKey.length()>0); // test message index before any encryption
mAliceMessageIndex = mAliceOutboundSession.messageIndex();
assertTrue(0 == mAliceMessageIndex);
}
long messageIndex = aliceOutboundSession.messageIndex(); @Test
assertTrue(0==messageIndex); public void test05OutboundGroupEncryptMessage() {
// alice encrypts a message to bob
mAliceToBobMessage = mAliceOutboundSession.encryptMessage(CLEAR_MESSAGE1);
assertFalse(TextUtils.isEmpty(mAliceToBobMessage));
// test message index after encryption is incremented
mAliceMessageIndex = mAliceOutboundSession.messageIndex();
assertTrue(1== mAliceMessageIndex);
}
String clearMessage = "Hello!"; @Test
String encryptedMessage = aliceOutboundSession.encryptMessage(clearMessage); public void test06CreateInboundGroupSession() {
assertNotNull(encryptedMessage); // bob creates INBOUND GROUP SESSION with alice outbound key
try {
mBobInboundSession = new OlmInboundGroupSession(mAliceOutboundSessionKey);
} catch (OlmException e) {
assertTrue("Exception in bob OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false);
}
}
messageIndex = aliceOutboundSession.messageIndex(); @Test
assertTrue(1==messageIndex); public void test07OutboundGroupSessionIdentifiers() {
// check session identifiers are equals
mAliceSessionIdentifier = mAliceOutboundSession.sessionIdentifier();
assertFalse(TextUtils.isEmpty(mAliceSessionIdentifier));
}
assertTrue(encryptedMessage.length()>=0); @Test
public void test08InboundGroupSessionIdentifiers() {
// check session identifiers are equals
mBobSessionIdentifier = mBobInboundSession.sessionIdentifier();
assertFalse(TextUtils.isEmpty(mBobSessionIdentifier));
assertTrue(mAliceSessionIdentifier.equals(mBobSessionIdentifier));
}
OlmInboundGroupSession bobInboundSession = new OlmInboundGroupSession(); @Test
bobInboundSession.initInboundGroupSessionWithSessionKey(aliceOutboundSessionKey); public void test09SessionIdentifiersIdentical() {
// check session identifiers are equals // check session identifiers are equals
aliceSessionIdentifier = aliceOutboundSession.sessionIdentifier(); assertTrue(mAliceSessionIdentifier.equals(mBobSessionIdentifier));
String bobSessionIdentifier = aliceOutboundSession.sessionIdentifier(); }
assertTrue(aliceSessionIdentifier.equals(bobSessionIdentifier ));
String decryptedMessage = bobInboundSession.decryptMessage(encryptedMessage); @Test
assertTrue(decryptedMessage.equals(bobSessionIdentifier )); public void test10InboundDecryptMessage() {
// test decrypted message
mBobDecryptedMessage = mBobInboundSession.decryptMessage(mAliceToBobMessage);
assertFalse(TextUtils.isEmpty(mBobDecryptedMessage));
assertTrue(mBobDecryptedMessage.equals(CLEAR_MESSAGE1));
} }
//@Test @Test
public void test02InboundGroupSession() { public void test11InboundDecryptedMessageIdentical() {
// creates alice outbound session // test decrypted message
OlmInboundGroupSession aliceInboundSession = new OlmInboundGroupSession(); assertTrue(mBobDecryptedMessage.equals(CLEAR_MESSAGE1));
}
// test session identifier @Test
String sessionIdentifier = aliceInboundSession.sessionIdentifier(); public void test12ReleaseOutboundSession() {
assertNotNull(sessionIdentifier); // release group sessions
assertTrue(sessionIdentifier.length()>0); mAliceOutboundSession.releaseSession();
} }
@Test
public void test13ReleaseInboundSession() {
// release group sessions
mBobInboundSession.releaseSession();
}
} }
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package org.matrix.olm; package org.matrix.olm;
public class OlmUtilsException extends Exception { public class OlmException extends Exception {
// exception codes // exception codes
public static final int EXCEPTION_CODE_INIT_NEW_SESSION_FAILURE = 0; public static final int EXCEPTION_CODE_INIT_NEW_SESSION_FAILURE = 0;
public static final int EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION = 1; public static final int EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION = 1;
...@@ -24,7 +24,7 @@ public class OlmUtilsException extends Exception { ...@@ -24,7 +24,7 @@ public class OlmUtilsException extends Exception {
private final int mCode; private final int mCode;
public OlmUtilsException(int aExceptionCode) { public OlmException(int aExceptionCode) {
super(); super();
mCode = aExceptionCode; mCode = aExceptionCode;
} }
......
...@@ -48,16 +48,16 @@ public class OlmInboundGroupSession implements Serializable { ...@@ -48,16 +48,16 @@ public class OlmInboundGroupSession implements Serializable {
* The session key parameter is retrieved from a outbound group session * The session key parameter is retrieved from a outbound group session
* See {@link #initNewSession()} and {@link #initInboundGroupSessionWithSessionKey(String)} * See {@link #initNewSession()} and {@link #initInboundGroupSessionWithSessionKey(String)}
* @param aSessionKey session key * @param aSessionKey session key
* @throws OlmUtilsException * @throws OlmException
*/ */
public OlmInboundGroupSession(String aSessionKey) throws OlmUtilsException { public OlmInboundGroupSession(String aSessionKey) throws OlmException {
if(initNewSession()) { if(initNewSession()) {
if( 0 != initInboundGroupSessionWithSessionKey(aSessionKey)) { if( 0 != initInboundGroupSessionWithSessionKey(aSessionKey)) {
releaseSession();// prevent memory leak before throwing releaseSession();// prevent memory leak before throwing
throw new OlmUtilsException(OlmUtilsException.EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION);
} }
} else { } else {
throw new OlmUtilsException(OlmUtilsException.EXCEPTION_CODE_INIT_NEW_SESSION_FAILURE); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_NEW_SESSION_FAILURE);
} }
} }
......
...@@ -18,7 +18,6 @@ package org.matrix.olm; ...@@ -18,7 +18,6 @@ package org.matrix.olm;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
public class OlmOutboundGroupSession { public class OlmOutboundGroupSession {
private static final String LOG_TAG = "OlmOutboundGroupSession"; private static final String LOG_TAG = "OlmOutboundGroupSession";
...@@ -41,16 +40,16 @@ public class OlmOutboundGroupSession { ...@@ -41,16 +40,16 @@ public class OlmOutboundGroupSession {
* Create and save a new session native instance ID and * Create and save a new session native instance ID and
* initialise a new outbound group session.<br> * initialise a new outbound group session.<br>
* See {@link #initNewSession()} and {@link #initOutboundGroupSession()} * See {@link #initNewSession()} and {@link #initOutboundGroupSession()}
* @throws OlmUtilsException * @throws OlmException
*/ */
public OlmOutboundGroupSession() throws OlmUtilsException { public OlmOutboundGroupSession() throws OlmException {
if(initNewSession()) { if(initNewSession()) {
if( 0 != initOutboundGroupSession()) { if( 0 != initOutboundGroupSession()) {
releaseSession();// prevent memory leak before throwing releaseSession();// prevent memory leak before throwing
throw new OlmUtilsException(OlmUtilsException.EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION);
} }
} else { } else {
throw new OlmUtilsException(OlmUtilsException.EXCEPTION_CODE_INIT_NEW_SESSION_FAILURE); throw new OlmException(OlmException.EXCEPTION_CODE_INIT_NEW_SESSION_FAILURE);
} }
} }
......
...@@ -26,7 +26,7 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env ...@@ -26,7 +26,7 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
{ {
OlmInboundGroupSession* sessionPtr = NULL; OlmInboundGroupSession* sessionPtr = NULL;
LOGD("## releaseSessionJni(): sessionPtr=%p",sessionPtr); LOGD("## releaseSessionJni(): intbound group session");
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{ {
...@@ -34,12 +34,14 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env ...@@ -34,12 +34,14 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
} }
else else
{ {
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
size_t retCode = olm_clear_inbound_group_session(sessionPtr); size_t retCode = olm_clear_inbound_group_session(sessionPtr);
LOGD("## releaseSessionJni(): clear_inbound_group_session=%lu",retCode); LOGD(" ## releaseSessionJni(): clear_inbound_group_session=%lu",retCode);
LOGD("## releaseSessionJni(): IN"); LOGD(" ## releaseSessionJni(): free IN");
free(sessionPtr); free(sessionPtr);
LOGD("## releaseSessionJni(): OUT"); LOGD(" ## releaseSessionJni(): free OUT");
} }
} }
...@@ -52,20 +54,23 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env ...@@ -52,20 +54,23 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz) JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz)
{ {
OlmInboundGroupSession* sessionPtr = NULL; OlmInboundGroupSession* sessionPtr = NULL;
size_t sessionSize = olm_inbound_group_session_size(); size_t sessionSize = 0;
LOGD("## initNewSessionJni(): inbound group session IN");
sessionSize = olm_inbound_group_session_size();
if(0 == sessionSize) if(0 == sessionSize)
{ {
LOGE("## initNewSessionJni(): failure - inbound group session size = 0"); LOGE(" ## initNewSessionJni(): failure - inbound group session size = 0");
} }
else if(NULL != (sessionPtr=(OlmInboundGroupSession*)malloc(sessionSize))) else if(NULL != (sessionPtr=(OlmInboundGroupSession*)malloc(sessionSize)))
{ {
sessionPtr = olm_inbound_group_session(sessionPtr); sessionPtr = olm_inbound_group_session(sessionPtr);
LOGD("## initNewSessionJni(): success - inbound group session size=%lu",sessionSize); LOGD(" ## initNewSessionJni(): success - inbound group session size=%lu",sessionSize);
} }
else else
{ {
LOGE("## initNewSessionJni(): failure - inbound group session OOM"); LOGE(" ## initNewSessionJni(): failure - inbound group session OOM");
} }
return (jlong)(intptr_t)sessionPtr; return (jlong)(intptr_t)sessionPtr;
...@@ -83,32 +88,34 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes ...@@ -83,32 +88,34 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
const uint8_t *sessionKeyPtr = NULL; const uint8_t *sessionKeyPtr = NULL;
size_t sessionResult; size_t sessionResult;
LOGD("## initInboundGroupSessionWithSessionKeyJni(): inbound group session IN");
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{ {
LOGE("## initInboundGroupSessionWithSessionKeyJni(): failure - invalid inbound group session instance"); LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid inbound group session instance");
} }
else if(0 == aSessionKey) else if(0 == aSessionKey)
{ {
LOGE("## initInboundGroupSessionWithSessionKeyJni(): failure - invalid aSessionKey"); LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid aSessionKey");
} }
else if(NULL == (sessionKeyPtr = (const uint8_t *)env->GetStringUTFChars(aSessionKey, 0))) else if(NULL == (sessionKeyPtr = (const uint8_t *)env->GetStringUTFChars(aSessionKey, 0)))
{ {
LOGE("## initInboundSessionFromIdKeyJni(): failure - session key JNI allocation OOM"); LOGE(" ## initInboundSessionFromIdKeyJni(): failure - session key JNI allocation OOM");
} }
else else
{ {
size_t sessionKeyLength = (size_t)env->GetStringUTFLength(aSessionKey); size_t sessionKeyLength = (size_t)env->GetStringUTFLength(aSessionKey);
LOGD("## initInboundSessionFromIdKeyJni(): sessionKeyLength=%lu",sessionKeyLength); LOGD(" ## initInboundSessionFromIdKeyJni(): sessionKeyLength=%lu",sessionKeyLength);
sessionResult = olm_init_inbound_group_session(sessionPtr, sessionKeyPtr, sessionKeyLength); sessionResult = olm_init_inbound_group_session(sessionPtr, sessionKeyPtr, sessionKeyLength);
if(sessionResult == olm_error()) { if(sessionResult == olm_error()) {
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr); const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
LOGE("## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",errorMsgPtr); LOGE(" ## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
} }
else else
{ {
retCode = ERROR_CODE_OK; retCode = ERROR_CODE_OK;
LOGD("## initInboundSessionFromIdKeyJni(): success - result=%lu", sessionResult); LOGD(" ## initInboundSessionFromIdKeyJni(): success - result=%lu", sessionResult);
} }
} }
...@@ -135,17 +142,17 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn ...@@ -135,17 +142,17 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{ {
LOGE("## sessionIdentifierJni(): failure - invalid inbound group session instance"); LOGE(" ## sessionIdentifierJni(): failure - invalid inbound group session instance");
} }
else else
{ {
// get the size to alloc // get the size to alloc
size_t lengthSessionId = olm_inbound_group_session_id_length(sessionPtr); size_t lengthSessionId = olm_inbound_group_session_id_length(sessionPtr);
LOGD("## sessionIdentifierJni(): inbound group session lengthSessionId=%lu",lengthSessionId); LOGD(" ## sessionIdentifierJni(): inbound group session lengthSessionId=%lu",lengthSessionId);
if(NULL == (sessionIdPtr = (uint8_t*)malloc(lengthSessionId*sizeof(uint8_t)))) if(NULL == (sessionIdPtr = (uint8_t*)malloc(lengthSessionId*sizeof(uint8_t))))
{ {
LOGE("## sessionIdentifierJni(): failure - inbound group session identifier allocation OOM"); LOGE(" ## sessionIdentifierJni(): failure - inbound group session identifier allocation OOM");
} }
else else
{ {
...@@ -153,13 +160,13 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn ...@@ -153,13 +160,13 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
if (result == olm_error()) if (result == olm_error())
{ {
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr); const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
LOGE("## sessionIdentifierJni(): failure - get inbound group session identifier failure Msg=%s",errorMsgPtr); LOGE(" ## sessionIdentifierJni(): failure - get inbound group session identifier failure Msg=%s",errorMsgPtr);
} }
else else
{ {
// update length // update length
sessionIdPtr[result] = static_cast<char>('\0'); sessionIdPtr[result] = static_cast<char>('\0');
LOGD("## sessionIdentifierJni(): success - inbound group session result=%lu sessionId=%s",result, (char*)sessionIdPtr); LOGD(" ## sessionIdentifierJni(): success - inbound group session result=%lu sessionId=%s",result, (char*)sessionIdPtr);
returnValueStr = env->NewStringUTF((const char*)sessionIdPtr); returnValueStr = env->NewStringUTF((const char*)sessionIdPtr);
} }
free(sessionIdPtr); free(sessionIdPtr);
...@@ -178,19 +185,19 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv * ...@@ -178,19 +185,19 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
uint8_t *plainTextMsgPtr = NULL; uint8_t *plainTextMsgPtr = NULL;
uint8_t *tempEncryptedPtr = NULL; uint8_t *tempEncryptedPtr = NULL;
LOGD("## decryptMessageJni(): IN"); LOGD("## decryptMessageJni(): inbound group session IN");
if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz))) if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
{ {
LOGE("## decryptMessageJni(): failure - invalid inbound group session ptr=NULL"); LOGE(" ## decryptMessageJni(): failure - invalid inbound group session ptr=NULL");
} }
else if(0 == aEncryptedMsg) else if(0 == aEncryptedMsg)
{ {
LOGE("## decryptMessageJni(): failure - invalid encrypted message"); LOGE(" ## decryptMessageJni(): failure - invalid encrypted message");
} }
else if(0 == (encryptedMsgPtr = env->GetStringUTFChars(aEncryptedMsg, 0))) else if(0 == (encryptedMsgPtr = env->GetStringUTFChars(aEncryptedMsg, 0)))
{ {
LOGE("## decryptMessageJni(): failure - encrypted message JNI allocation OOM"); LOGE(" ## decryptMessageJni(): failure - encrypted message JNI allocation OOM");
} }
else else
{ {
...@@ -200,12 +207,12 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv * ...@@ -200,12 +207,12 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
// create a dedicated temp buffer to be used in next Olm API calls // create a dedicated temp buffer to be used in next Olm API calls
if(NULL == (tempEncryptedPtr = static_cast<uint8_t*>(malloc(encryptedMsgLength*sizeof(uint8_t))))) if(NULL == (tempEncryptedPtr = static_cast<uint8_t*>(malloc(encryptedMsgLength*sizeof(uint8_t)))))
{ {
LOGE("## decryptMessageJni(): failure - tempEncryptedPtr allocation OOM"); LOGE(" ## decryptMessageJni(): failure - tempEncryptedPtr allocation OOM");
} }
else else
{ {
memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength); memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength);
LOGD("## decryptMessageJni(): encryptedMsgLength=%lu encryptedMsg=%s",encryptedMsgLength,encryptedMsgPtr); LOGD(" ## decryptMessageJni(): encryptedMsgLength=%lu encryptedMsg=%s",encryptedMsgLength,encryptedMsgPtr);
// get max plaintext length // get max plaintext length
size_t maxPlainTextLength = olm_group_decrypt_max_plaintext_length(sessionPtr, size_t maxPlainTextLength = olm_group_decrypt_max_plaintext_length(sessionPtr,
...@@ -214,11 +221,11 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv * ...@@ -214,11 +221,11 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
if(maxPlainTextLength == olm_error()) if(maxPlainTextLength == olm_error())
{ {
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr); const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
LOGE("## decryptMessageJni(): failure - olm_group_decrypt_max_plaintext_length Msg=%s",errorMsgPtr); LOGE(" ## decryptMessageJni(): failure - olm_group_decrypt_max_plaintext_length Msg=%s",errorMsgPtr);
} }