aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/main/jni
diff options
context:
space:
mode:
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/main/jni')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp21
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp182
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h6
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h7
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp186
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp24
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h2
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp30
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp3
9 files changed, 242 insertions, 219 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
index 1a1b360..baa7939 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
@@ -119,8 +119,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thi
// create account
accountRetCode = olm_create_account(accountPtr, (void*)randomBuffPtr, randomSize);
if(accountRetCode == olm_error()) {
- const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGE("## initNewAccount(): failure - account creation failed Msg=%s", errorMsgPtr);
+ LOGE("## initNewAccount(): failure - account creation failed Msg=%s", (const char *)olm_account_last_error(accountPtr));
}
LOGD("## initNewAccount(): success - OLM account created");
@@ -171,8 +170,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
{ // retrieve key pairs in identityKeysBytesPtr
keysResult = olm_account_identity_keys(accountPtr, identityKeysBytesPtr, identityKeysLength);
if(keysResult == olm_error()) {
- const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGE("## identityKeys(): failure - error getting identity keys Msg=%s",errorMsgPtr);
+ LOGE("## identityKeys(): failure - error getting identity keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
}
else
{ // allocate the byte array to be returned to java
@@ -253,8 +251,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeys)(JNIEnv *env, jobject th
// retrieve key pairs in keysBytesPtr
result = olm_account_generate_one_time_keys(accountPtr, (size_t)aNumberOfKeys, (void*)randomBufferPtr, randomLength);
if(result == olm_error()) {
- const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGE("## generateOneTimeKeys(): failure - error generating one time keys Msg=%s",errorMsgPtr);
+ LOGE("## generateOneTimeKeys(): failure - error generating one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
}
else
{
@@ -302,8 +299,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(oneTimeKeysJni)(JNIEnv *env, jobject t
{ // retrieve key pairs in keysBytesPtr
keysResult = olm_account_one_time_keys(accountPtr, keysBytesPtr, keysLength);
if(keysResult == olm_error()) {
- const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGE("## oneTimeKeysJni(): failure - error getting one time keys Msg=%s",errorMsgPtr);
+ LOGE("## oneTimeKeysJni(): failure - error getting one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
}
else
{ // allocate the byte array to be returned to java
@@ -351,8 +347,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysForSessionJni)(JNIEnv *env,
result = olm_remove_one_time_keys(accountPtr, sessionPtr);
if(result == olm_error())
{ // the account doesn't have any matching "one time keys"..
- const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGW("## removeOneTimeKeysForSessionJni(): failure - removing one time keys Msg=%s",errorMsgPtr);
+ LOGW("## removeOneTimeKeysForSessionJni(): failure - removing one time keys Msg=%s",(const char *)olm_account_last_error(accountPtr));
retCode = ERROR_CODE_NO_MATCHING_ONE_TIME_KEYS;
}
@@ -386,8 +381,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
result = olm_account_mark_keys_as_published(accountPtr);
if(result == olm_error())
{
- const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGW("## markOneTimeKeysAsPublishedJni(): failure - Msg=%s",errorMsgPtr);
+ LOGW("## markOneTimeKeysAsPublishedJni(): failure - Msg=%s",(const char *)olm_account_last_error(accountPtr));
retCode = ERROR_CODE_KO;
}
else
@@ -448,8 +442,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
signatureLength);
if(resultSign == olm_error())
{
- const char *errorMsgPtr = olm_account_last_error(accountPtr);
- LOGE("## signMessageJni(): failure - error signing message Msg=%s",errorMsgPtr);
+ LOGE("## signMessageJni(): failure - error signing message Msg=%s",(const char *)olm_account_last_error(accountPtr));
}
else
{
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
index d10a05b..810d62c 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
@@ -38,7 +38,7 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
size_t retCode = olm_clear_inbound_group_session(sessionPtr);
- LOGD(" ## releaseSessionJni(): clear_inbound_group_session=%lu",retCode);
+ LOGI(" ## releaseSessionJni(): clear_inbound_group_session=%lu",retCode);
LOGD(" ## releaseSessionJni(): free IN");
free(sessionPtr);
@@ -52,26 +52,26 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
* to make the cast (OlmInboundGroupSession* => jlong) platform independent.
* @return the initialized OlmInboundGroupSession* instance if init succeed, NULL otherwise
**/
-JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz)
+JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz)
{
OlmInboundGroupSession* sessionPtr = NULL;
size_t sessionSize = 0;
- LOGD("## initNewSessionJni(): inbound group session IN");
+ LOGD("## createNewSessionJni(): inbound group session IN");
sessionSize = olm_inbound_group_session_size();
if(0 == sessionSize)
{
- LOGE(" ## initNewSessionJni(): failure - inbound group session size = 0");
+ LOGE(" ## createNewSessionJni(): failure - inbound group session size = 0");
}
else if(NULL != (sessionPtr=(OlmInboundGroupSession*)malloc(sessionSize)))
{
sessionPtr = olm_inbound_group_session(sessionPtr);
- LOGD(" ## initNewSessionJni(): success - inbound group session size=%lu",sessionSize);
+ LOGD(" ## createNewSessionJni(): success - inbound group session size=%lu",sessionSize);
}
else
{
- LOGE(" ## initNewSessionJni(): failure - inbound group session OOM");
+ LOGE(" ## createNewSessionJni(): failure - inbound group session OOM");
}
return (jlong)(intptr_t)sessionPtr;
@@ -160,8 +160,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
size_t result = olm_inbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
if (result == olm_error())
{
- 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",(const char *)olm_inbound_group_session_last_error(sessionPtr));
}
else
{
@@ -221,8 +220,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
encryptedMsgLength);
if(maxPlainTextLength == olm_error())
{
- 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",(const char *)olm_inbound_group_session_last_error(sessionPtr));
}
else
{
@@ -240,8 +238,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
maxPlainTextLength);
if(plaintextLength == olm_error())
{
- const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
- LOGE(" ## decryptMessageJni(): failure - olm_group_decrypt Msg=%s",errorMsgPtr);
+ LOGE(" ## decryptMessageJni(): failure - olm_group_decrypt Msg=%s",(const char *)olm_inbound_group_session_last_error(sessionPtr));
}
else
{
@@ -275,4 +272,165 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
}
+/**
+* Serialize and encrypt session instance into a base64 string.<br>
+* @param aKey key used to encrypt the serialized session data
+* @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, jstring aKey, jobject aErrorMsg)
+{
+ jstring pickledDataRetValue = 0;
+ jclass errorMsgJClass = 0;
+ jmethodID errorMsgMethodId = 0;
+ jstring errorJstring = 0;
+ const char *keyPtr = NULL;
+ void *pickledPtr = NULL;
+ OlmInboundGroupSession* sessionPtr = NULL;
+
+ LOGD("## inbound group session serializeDataWithKeyJni(): IN");
+
+ if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
+ {
+ LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
+ }
+ else if(0 == aKey)
+ {
+ LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
+ }
+ else if(0 == aErrorMsg)
+ {
+ LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
+ }
+ else if(0 == (errorMsgJClass = env->GetObjectClass(aErrorMsg)))
+ {
+ LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
+ }
+ else if(0 == (errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
+ {
+ LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
+ }
+ else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0)))
+ {
+ LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
+ }
+ else
+ {
+ size_t pickledLength = olm_pickle_inbound_group_session_length(sessionPtr);
+ size_t keyLength = (size_t)env->GetStringUTFLength(aKey);
+ LOGD(" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu",pickledLength, keyLength);
+ LOGD(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
+
+ if(NULL == (pickledPtr = (void*)malloc((pickledLength+1)*sizeof(uint8_t))))
+ {
+ LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
+ }
+ else
+ {
+ size_t result = olm_pickle_inbound_group_session(sessionPtr,
+ (void const *)keyPtr,
+ keyLength,
+ (void*)pickledPtr,
+ pickledLength);
+ if(result == olm_error())
+ {
+ const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
+ LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
+
+ if(0 != (errorJstring = env->NewStringUTF(errorMsgPtr)))
+ {
+ env->CallObjectMethod(aErrorMsg, errorMsgMethodId, errorJstring);
+ }
+ }
+ else
+ {
+ // 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", result, static_cast<char*>(pickledPtr));
+ }
+ }
+ }
+
+ // free alloc
+ if(NULL != keyPtr)
+ {
+ env->ReleaseStringUTFChars(aKey, keyPtr);
+ }
+
+ if(NULL != pickledPtr)
+ {
+ free(pickledPtr);
+ }
+
+ return pickledDataRetValue;
+}
+
+
+JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jstring aSerializedData, jstring aKey)
+{
+ OlmInboundGroupSession* sessionPtr = NULL;
+ jstring errorMessageRetValue = 0;
+ const char *keyPtr = NULL;
+ const char *pickledPtr = NULL;
+ LOGD("## initWithSerializedDataJni(): IN");
+
+ if(NULL == (sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
+ {
+ LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
+ }
+ else if(0 == aKey)
+ {
+ LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
+ }
+ else if(0 == aSerializedData)
+ {
+ LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
+ }
+ else if(NULL == (keyPtr = env->GetStringUTFChars(aKey, 0)))
+ {
+ LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
+ }
+ else if(NULL == (pickledPtr = env->GetStringUTFChars(aSerializedData, 0)))
+ {
+ LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
+ }
+ else
+ {
+ size_t pickledLength = (size_t)env->GetStringUTFLength(aSerializedData);
+ size_t keyLength = (size_t)env->GetStringUTFLength(aKey);
+ LOGD(" ## initWithSerializedDataJni(): pickledLength=%lu keyLength=%lu",pickledLength, keyLength);
+ LOGD(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
+ LOGD(" ## initWithSerializedDataJni(): pickled=%s",(char const *)pickledPtr);
+
+ size_t result = olm_unpickle_inbound_group_session(sessionPtr,
+ (void const *)keyPtr,
+ keyLength,
+ (void*)pickledPtr,
+ pickledLength);
+ if(result == olm_error())
+ {
+ const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
+ LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_inbound_group_session() Msg=%s",errorMsgPtr);
+ errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
+ }
+ else
+ {
+ LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", result);
+ }
+ }
+
+ // free alloc
+ if(NULL != keyPtr)
+ {
+ env->ReleaseStringUTFChars(aKey, keyPtr);
+ }
+
+ if(NULL != pickledPtr)
+ {
+ env->ReleaseStringUTFChars(aSerializedData, pickledPtr);
+ }
+
+ return errorMessageRetValue;
+}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h
index 1eb8238..897ef46 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.h
@@ -29,12 +29,16 @@ extern "C" {
// session creation/destruction
JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
-JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz);
+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, jstring aSessionKey);
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);
+// 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(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jstring aSerializedData, jstring aKey);
+
#ifdef __cplusplus
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h
index 2e31bff..bb718b6 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h
@@ -30,16 +30,15 @@
/* logging macros */
#define ENABLE_LOGS
+#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
+#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
+
#ifdef ENABLE_LOGS
- #define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
- #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
#else
- #define LOGV(...)
#define LOGD(...)
#define LOGW(...)
- #define LOGE(...)
#endif
#define FUNC_DEF(class_name,func_name) JNICALL Java_org_matrix_olm_##class_name##_##func_name
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp
index 174739c..1f0c0df 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp
@@ -63,12 +63,13 @@ bool setRandomInBuffer(uint8_t **aBuffer2Ptr, size_t aRandomSize)
/**
-* Read the account instance ID of the calling object.
+* Read the instance ID of the calling object.
* @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked
+* @param aCallingClass java calling clas name
* @return the instance ID if operation succeed, -1 if instance ID was not found.
**/
-jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
+jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingClass)
{
jlong instanceId = 0;
jfieldID instanceIdField;
@@ -77,7 +78,7 @@ jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
if(NULL!=aJniEnv)
{
- requiredClass = aJniEnv->FindClass(CLASS_OLM_ACCOUNT);
+ requiredClass = aJniEnv->FindClass(aCallingClass);
if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
{
@@ -85,78 +86,56 @@ jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
}
else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject)))
{
- if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmAccountId", "J")))
+ if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeId", "J")))
{
instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField);
aJniEnv->DeleteLocalRef(loaderClass);
- LOGD("## getAccountInstanceId(): read from java instanceId=%lld",instanceId);
+ LOGD("## getInstanceId(): read from java instanceId=%lld",instanceId);
}
else
{
- LOGE("## getAccountInstanceId() ERROR! GetFieldID=null");
+ LOGE("## getInstanceId() ERROR! GetFieldID=null");
}
}
else
{
- LOGE("## getAccountInstanceId() ERROR! GetObjectClass=null");
+ LOGE("## getInstanceId() ERROR! GetObjectClass=null");
}
}
else
{
- LOGE("## getAccountInstanceId() ERROR! aJniEnv=NULL");
+ LOGE("## getInstanceId() ERROR! aJniEnv=NULL");
}
- LOGD("## getAccountInstanceId() success - instanceId=%p (jlong)(intptr_t)instanceId=%lld",(void*)instanceId, (jlong)(intptr_t)instanceId);
+ LOGD("## getInstanceId() success - instanceId=%p (jlong)(intptr_t)instanceId=%lld",(void*)instanceId, (jlong)(intptr_t)instanceId);
return instanceId;
}
/**
-* Read the session instance ID of the calling object (aJavaObject).<br>
+* Read the account instance ID of the calling object.
* @param aJniEnv pointer pointing on the JNI function table
* @param aJavaObject reference to the object on which the method is invoked
-* @return the instance ID if read succeed, -1 otherwise.
+* @return the instance ID if operation succeed, -1 if instance ID was not found.
**/
-jlong getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
+jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{
- jlong instanceId = 0;
- jfieldID instanceIdField;
- jclass loaderClass;
- jclass requiredClass = 0;
+ jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_ACCOUNT);
+ return instanceId;
+}
- if(NULL!=aJniEnv)
- {
- requiredClass = aJniEnv->FindClass(CLASS_OLM_SESSION);
- if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
- {
- LOGE("## getSessionInstanceId() failure - invalid instance of");
- }
- else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject)))
- {
- if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmSessionId", "J")))
- {
- instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField);
- aJniEnv->DeleteLocalRef(loaderClass);
- }
- else
- {
- LOGE("## getSessionInstanceId() ERROR! GetFieldID=null");
- }
- }
- else
- {
- LOGE("## getSessionInstanceId() ERROR! GetObjectClass=null");
- }
- }
- else
- {
- LOGE("## getSessionInstanceId() ERROR! aJniEnv=NULL");
- }
- //LOGD("## getSessionInstanceId() success - instanceId=%lld",instanceId);
+/**
+* Read the session instance ID of the calling object (aJavaObject).<br>
+* @param aJniEnv pointer pointing on the JNI function table
+* @param aJavaObject reference to the object on which the method is invoked
+* @return the instance ID if read succeed, -1 otherwise.
+**/
+jlong getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
+{
+ jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_SESSION);
return instanceId;
}
-
/**
* Read the inbound group session instance ID of the calling object (aJavaObject).<br>
* @param aJniEnv pointer pointing on the JNI function table
@@ -165,41 +144,7 @@ jlong getSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
**/
jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{
- jlong instanceId = 0;
- jfieldID instanceIdField;
- jclass loaderClass;
- jclass requiredClass = 0;
-
- if(NULL!=aJniEnv)
- {
- requiredClass = aJniEnv->FindClass(CLASS_OLM_INBOUND_GROUP_SESSION);
-
- if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
- {
- LOGE("## getInboundGroupSessionInstanceId() failure - invalid instance of");
- }
- else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject)))
- {
- if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmInboundGroupSessionId", "J")))
- {
- instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField);
- aJniEnv->DeleteLocalRef(loaderClass);
- }
- else
- {
- LOGE("## getInboundGroupSessionInstanceId() ERROR! GetFieldID=null");
- }
- }
- else
- {
- LOGE("## getInboundGroupSessionInstanceId() ERROR! GetObjectClass=null");
- }
- }
- else
- {
- LOGE("## getInboundGroupSessionInstanceId() ERROR! aJniEnv=NULL");
- }
-
+ jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_INBOUND_GROUP_SESSION);
return instanceId;
}
@@ -212,84 +157,23 @@ jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
**/
jlong getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{
- jlong instanceId = 0;
- jfieldID instanceIdField;
- jclass loaderClass;
- jclass requiredClass = 0;
-
- if(NULL!=aJniEnv)
- {
- requiredClass = aJniEnv->FindClass(CLASS_OLM_OUTBOUND_GROUP_SESSION);
-
- if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
- {
- LOGE("## getOutboundGroupSessionInstanceId() failure - invalid instance of");
- }
- else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject)))
- {
- if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmOutboundGroupSessionId", "J")))
- {
- instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField);
- aJniEnv->DeleteLocalRef(loaderClass);
- }
- else
- {
- LOGE("## getOutboundGroupSessionInstanceId() ERROR! GetFieldID=null");
- }
- }
- else
- {
- LOGE("## getOutboundGroupSessionInstanceId() ERROR! GetObjectClass=null");
- }
- }
- else
- {
- LOGE("## getOutboundGroupSessionInstanceId() ERROR! aJniEnv=NULL");
- }
-
+ jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_OUTBOUND_GROUP_SESSION);
return instanceId;
}
+/**
+* Read the utility instance ID of the calling object (aJavaObject).<br>
+* @param aJniEnv pointer pointing on the JNI function table
+* @param aJavaObject reference to the object on which the method is invoked
+* @return the instance ID if read succeed, -1 otherwise.
+**/
jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
{
- jlong instanceId = 0;
- jfieldID instanceIdField;
- jclass loaderClass;
- jclass requiredClass = 0;
-
- if(NULL!=aJniEnv)
- {
- requiredClass = aJniEnv->FindClass(CLASS_OLM_UTILITY);
-
- if((0 != requiredClass) && (JNI_TRUE != aJniEnv->IsInstanceOf(aJavaObject, requiredClass)))
- {
- LOGE("## getUtilityInstanceId() failure - invalid instance of");
- }
- else if(0 != (loaderClass=aJniEnv->GetObjectClass(aJavaObject)))
- {
- if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeOlmUtilityId", "J")))
- {
- instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField);
- aJniEnv->DeleteLocalRef(loaderClass);
- }
- else
- {
- LOGE("## getUtilityInstanceId() ERROR! GetFieldID=null");
- }
- }
- else
- {
- LOGE("## getUtilityInstanceId() ERROR! GetObjectClass=null");
- }
- }
- else
- {
- LOGE("## getUtilityInstanceId() ERROR! aJniEnv=NULL");
- }
-
+ jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_UTILITY);
return instanceId;
}
+
template <typename T>
jstring serializeDataWithKey(JNIEnv *env, jobject thiz,
jstring aKey,
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 67bf8bd..8ccd78e 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
@@ -38,7 +38,7 @@ JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *en
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
size_t retCode = olm_clear_outbound_group_session(sessionPtr);
- LOGD(" ## releaseSessionJni(): clear_outbound_group_session=%lu",retCode);
+ LOGI(" ## releaseSessionJni(): clear_outbound_group_session=%lu",retCode);
LOGD(" ## releaseSessionJni(): free IN");
free(sessionPtr);
@@ -52,26 +52,26 @@ JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *en
* to make the cast (OlmOutboundGroupSession* => jlong) platform independent.
* @return the initialized OlmOutboundGroupSession* instance if init succeed, NULL otherwise
**/
-JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz)
+JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz)
{
OlmOutboundGroupSession* sessionPtr = NULL;
size_t sessionSize = 0;
- LOGD("## initNewSessionJni(): outbound group session IN");
+ LOGD("## createNewSessionJni(): outbound group session IN");
sessionSize = olm_outbound_group_session_size();
if(0 == sessionSize)
{
- LOGE(" ## initNewSessionJni(): failure - outbound group session size = 0");
+ LOGE(" ## createNewSessionJni(): failure - outbound group session size = 0");
}
else if(NULL != (sessionPtr=(OlmOutboundGroupSession*)malloc(sessionSize)))
{
sessionPtr = olm_outbound_group_session(sessionPtr);
- LOGD(" ## initNewSessionJni(): success - outbound group session size=%lu",sessionSize);
+ LOGD(" ## createNewSessionJni(): success - outbound group session size=%lu",sessionSize);
}
else
{
- LOGE(" ## initNewSessionJni(): failure - outbound group session OOM");
+ LOGE(" ## createNewSessionJni(): failure - outbound group session OOM");
}
return (jlong)(intptr_t)sessionPtr;
@@ -111,8 +111,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
size_t sessionResult = olm_init_outbound_group_session(sessionPtr, randomBuffPtr, randomLength);
if(sessionResult == olm_error()) {
- const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
- LOGE(" ## initOutboundGroupSessionJni(): failure - init outbound session creation Msg=%s",errorMsgPtr);
+ LOGE(" ## initOutboundGroupSessionJni(): failure - init outbound session creation Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
}
else
{
@@ -160,8 +159,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
size_t result = olm_outbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
if (result == olm_error())
{
- const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
- LOGE(" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s",errorMsgPtr);
+ LOGE(" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
}
else
{
@@ -237,8 +235,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
size_t result = olm_outbound_group_session_key(sessionPtr, sessionKeyPtr, sessionKeyLength);
if (result == olm_error())
{
- const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
- LOGE(" ## sessionKeyJni(): failure - session key failure Msg=%s",errorMsgPtr);
+ LOGE(" ## sessionKeyJni(): failure - session key failure Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
}
else
{
@@ -301,8 +298,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
encryptedMsgLength);
if(encryptedLength == olm_error())
{
- const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
- LOGE(" ## encryptMessageJni(): failure - olm_group_encrypt Msg=%s",errorMsgPtr);
+ LOGE(" ## encryptMessageJni(): failure - olm_group_encrypt Msg=%s",(const char *)olm_outbound_group_session_last_error(sessionPtr));
}
else
{
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 22c32a7..4b59b93 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
@@ -29,7 +29,7 @@ extern "C" {
// session creation/destruction
JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
-JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initNewSessionJni)(JNIEnv *env, jobject thiz);
+JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(JNIEnv *env, jobject thiz);
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
index 9f64d2e..cfa132c 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
@@ -161,8 +161,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
(void*)randomBuffPtr,
randomSize);
if(sessionResult == olm_error()) {
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## initOutboundSessionJni(): failure - session creation Msg=%s",errorMsgPtr);
+ LOGE("## initOutboundSessionJni(): failure - session creation Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -236,8 +235,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject
sessionResult = olm_create_inbound_session(sessionPtr, accountPtr, (void*)messagePtr , messageLength);
if(sessionResult == olm_error()) {
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## initInboundSessionJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
+ LOGE("## initInboundSessionJni(): failure - init inbound session creation Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -302,8 +300,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
sessionResult = olm_create_inbound_session_from(sessionPtr, accountPtr, theirIdentityKeyPtr, theirIdentityKeyLength, (void*)messagePtr , messageLength);
if(sessionResult == olm_error()) {
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
+ LOGE("## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -355,8 +352,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobje
size_t matchResult = olm_matches_inbound_session(sessionPtr, (void*)messagePtr , messageLength);
if(matchResult == olm_error()) {
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## matchesInboundSessionJni(): failure - no match Msg=%s",errorMsgPtr);
+ LOGE("## matchesInboundSessionJni(): failure - no match Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -416,8 +412,7 @@ JNIEXPORT jint JNICALL OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(J
size_t matchResult = olm_matches_inbound_session_from(sessionPtr, (void const *)theirIdentityKeyPtr, identityKeyLength, (void*)messagePtr , messageLength);
if(matchResult == olm_error()) {
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## matchesInboundSessionFromIdKeyJni(): failure - no match Msg=%s",errorMsgPtr);
+ LOGE("## matchesInboundSessionFromIdKeyJni(): failure - no match Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -529,8 +524,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
encryptedMsgLength);
if(result == olm_error())
{
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## encryptMessageJni(): failure - Msg=%s",errorMsgPtr);
+ LOGE("## encryptMessageJni(): failure - Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -542,11 +536,10 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
// update message: encryptedMsgPtr => encryptedJstring
jstring encryptedJstring = env->NewStringUTF((const char*)encryptedMsgPtr);
- size_t encryptedUtfMsgLength = (size_t)env->GetStringUTFLength(encryptedJstring);
env->SetObjectField(aEncryptedMsg, encryptedMsgFieldId, (jobject)encryptedJstring);
retCode = ERROR_CODE_OK;
- LOGD("## encryptMessageJni(): success - result=%lu Type=%lu utfLength=%lu encryptedMsg=%s", result, messageType, encryptedUtfMsgLength, (const char*)encryptedMsgPtr);
+ LOGD("## encryptMessageJni(): success - result=%lu Type=%lu utfLength=%lu encryptedMsg=%s", result, messageType, (size_t)env->GetStringUTFLength(encryptedJstring), (const char*)encryptedMsgPtr);
}
}
}
@@ -642,8 +635,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
if(maxPlainTextLength == olm_error())
{
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## decryptMessageJni(): failure - olm_decrypt_max_plaintext_length Msg=%s",errorMsgPtr);
+ LOGE("## decryptMessageJni(): failure - olm_decrypt_max_plaintext_length Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -662,8 +654,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
maxPlainTextLength);
if(plaintextLength == olm_error())
{
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## decryptMessageJni(): failure - olm_decrypt Msg=%s",errorMsgPtr);
+ LOGE("## decryptMessageJni(): failure - olm_decrypt Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
@@ -728,8 +719,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, job
if (result == olm_error())
{
- const char *errorMsgPtr = olm_session_last_error(sessionPtr);
- LOGE("## getSessionIdentifierJni(): failure - get session identifier failure Msg=%s",errorMsgPtr);
+ LOGE("## getSessionIdentifierJni(): failure - get session identifier failure Msg=%s",(const char *)olm_session_last_error(sessionPtr));
}
else
{
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
index 6248d34..e11f7eb 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp
@@ -203,8 +203,7 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jst
hashLength);
if(result == olm_error())
{
- const char *errorMsgPtr = olm_utility_last_error(utilityPtr);
- LOGE("## sha256Jni(): failure - hash creation Msg=%s",errorMsgPtr);
+ LOGE("## sha256Jni(): failure - hash creation Msg=%s",(const char *)olm_utility_last_error(utilityPtr));
}
else
{