Update with master branch => OLM V2.0.0

This commit is contained in:
pedroGitt 2016-11-23 01:20:47 +01:00
parent 7a6897642b
commit e63be97774
6 changed files with 43 additions and 11 deletions

View file

@ -11,7 +11,7 @@ android {
targetSdkVersion 21 targetSdkVersion 21
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
version "0.3.0" version "0.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {

View file

@ -151,8 +151,10 @@ public class OlmGroupSessionTest {
@Test @Test
public void test10InboundDecryptMessage() { public void test10InboundDecryptMessage() {
// test decrypted message // test decrypted message
mBobDecryptedMessage = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage); OlmInboundGroupSession.DecryptIndex index = new OlmInboundGroupSession.DecryptIndex();
mBobDecryptedMessage = mBobInboundGroupSession.decryptMessage(mAliceToBobMessage, index);
assertFalse(TextUtils.isEmpty(mBobDecryptedMessage)); assertFalse(TextUtils.isEmpty(mBobDecryptedMessage));
assertTrue(0==index.mIndex);
} }
@Test @Test
@ -435,8 +437,10 @@ public class OlmGroupSessionTest {
assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode(), false); assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode(), false);
} }
String decryptedMessage = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji); OlmInboundGroupSession.DecryptIndex index = new OlmInboundGroupSession.DecryptIndex();
String decryptedMessage = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji, index);
assertNotNull(decryptedMessage); assertNotNull(decryptedMessage);
assertTrue(13==index.mIndex);
} }
} }

View file

@ -44,6 +44,14 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
*/ */
private transient long mNativeId; private transient long mNativeId;
/**
* Wrapper class to be used in {@link #decryptMessage(String, DecryptIndex)}
*/
static public class DecryptIndex {
/** decrypt index **/
public long mIndex;
}
/** /**
* Constructor.<br> * Constructor.<br>
* Create and save a new native session instance ID and start a new inbound group session. * Create and save a new native session instance ID and start a new inbound group session.
@ -136,13 +144,14 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/** /**
* Decrypt the message passed in parameter. * Decrypt the message passed in parameter.
* @param aEncryptedMsg the message to be decrypted * @param aEncryptedMsg the message to be decrypted
* @param aDecryptIndex_out decrypted message index
* @return the decrypted message if operation succeed, null otherwise. * @return the decrypted message if operation succeed, null otherwise.
*/ */
public String decryptMessage(String aEncryptedMsg) { public String decryptMessage(String aEncryptedMsg, DecryptIndex aDecryptIndex_out) {
String decryptedMessage = decryptMessageJni(aEncryptedMsg, OlmManager.ENABLE_STRING_UTF8_SPECIFIC_CONVERSION); String decryptedMessage = decryptMessageJni(aEncryptedMsg, aDecryptIndex_out, OlmManager.ENABLE_STRING_UTF8_SPECIFIC_CONVERSION);
return decryptedMessage; return decryptedMessage;
} }
private native String decryptMessageJni(String aEncryptedMsg, boolean aIsUtf8ConversionRequired); private native String decryptMessageJni(String aEncryptedMsg, DecryptIndex aDecryptIndex_out, boolean aIsUtf8ConversionRequired);
/** /**

View file

@ -2,8 +2,8 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := olm LOCAL_MODULE := olm
MAJOR := 1 MAJOR := 2
MINOR := 3 MINOR := 0
PATCH := 0 PATCH := 0
OLM_VERSION := $(MAJOR).$(MINOR).$(PATCH) OLM_VERSION := $(MAJOR).$(MINOR).$(PATCH)
SRC_ROOT_DIR := ../../../../../../.. SRC_ROOT_DIR := ../../../../../../..

View file

@ -180,13 +180,16 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
} }
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jstring aEncryptedMsg, jboolean aIsUtf8ConversionRequired) JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jstring aEncryptedMsg, jobject aDecryptIndex, jboolean aIsUtf8ConversionRequired)
{ {
jstring decryptedMsgRetValue = 0; jstring decryptedMsgRetValue = 0;
OlmInboundGroupSession *sessionPtr = NULL; OlmInboundGroupSession *sessionPtr = NULL;
const char *encryptedMsgPtr = NULL; const char *encryptedMsgPtr = NULL;
uint8_t *plainTextMsgPtr = NULL; uint8_t *plainTextMsgPtr = NULL;
uint8_t *tempEncryptedPtr = NULL; uint8_t *tempEncryptedPtr = NULL;
uint32_t messageIndex = 0;
jclass indexObjJClass = 0;
jfieldID indexMsgFieldId;
LOGD("## decryptMessageJni(): inbound group session IN"); LOGD("## decryptMessageJni(): inbound group session IN");
@ -198,10 +201,22 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
{ {
LOGE(" ## decryptMessageJni(): failure - invalid encrypted message"); LOGE(" ## decryptMessageJni(): failure - invalid encrypted message");
} }
else if(0 == aDecryptIndex)
{
LOGE(" ## decryptMessageJni(): failure - invalid index object");
}
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 if(0 == (indexObjJClass = env->GetObjectClass(aDecryptIndex)))
{
LOGE("## decryptMessageJni(): failure - unable to get index class");
}
else if(0 == (indexMsgFieldId = env->GetFieldID(indexObjJClass,"mIndex","J")))
{
LOGE("## decryptMessageJni(): failure - unable to get index type field");
}
else else
{ {
// get encrypted message length // get encrypted message length
@ -238,13 +253,17 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
tempEncryptedPtr, tempEncryptedPtr,
encryptedMsgLength, encryptedMsgLength,
plainTextMsgPtr, plainTextMsgPtr,
maxPlainTextLength); maxPlainTextLength,
&messageIndex);
if(plaintextLength == olm_error()) if(plaintextLength == olm_error())
{ {
LOGE(" ## decryptMessageJni(): failure - olm_group_decrypt Msg=%s",(const char *)olm_inbound_group_session_last_error(sessionPtr)); LOGE(" ## decryptMessageJni(): failure - olm_group_decrypt Msg=%s",(const char *)olm_inbound_group_session_last_error(sessionPtr));
} }
else else
{ {
// update index
env->SetLongField(aDecryptIndex, indexMsgFieldId, (jlong)messageIndex);
// UTF-8 conversion workaround for issue on Android versions older than Marshmallow (23) // UTF-8 conversion workaround for issue on Android versions older than Marshmallow (23)
if(aIsUtf8ConversionRequired) if(aIsUtf8ConversionRequired)
{ {

View file

@ -33,7 +33,7 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jstring aSessionKey); JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jstring aSessionKey);
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz); 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, jstring aEncryptedMsg, jboolean aIsUtf8ConversionRequired); JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jstring aEncryptedMsg, jobject aDecryptIndex, jboolean aIsUtf8ConversionRequired);
// serialization // serialization
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jstring aKey, jobject aErrorMsg); JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jstring aKey, jobject aErrorMsg);