Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
6b3cb69d
Commit
6b3cb69d
authored
Oct 24, 2016
by
pedroGitt
Browse files
Fix compiler warnings
- for 32bits platform target - when debug flag is not defined
parent
acafa69c
Changes
7
Hide whitespace changes
Inline
Side-by-side
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
View file @
6b3cb69d
...
...
@@ -37,7 +37,7 @@ OlmAccount* initializeAccountMemory()
if
(
NULL
!=
(
accountPtr
=
(
OlmAccount
*
)
malloc
(
accountSize
)))
{
// init account object
accountPtr
=
olm_account
(
accountPtr
);
LOGD
(
"## initializeAccountMemory(): success - OLM account size=%lu"
,
accountSize
);
LOGD
(
"## initializeAccountMemory(): success - OLM account size=%lu"
,
static_cast
<
long
unsigned
int
>
(
accountSize
)
)
;
}
else
{
...
...
@@ -107,7 +107,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(initNewAccountJni)(JNIEnv *env, jobject thi
{
// get random buffer size
randomSize
=
olm_create_account_random_length
(
accountPtr
);
LOGD
(
"## initNewAccount(): randomSize=%lu"
,
randomSize
);
LOGD
(
"## initNewAccount(): randomSize=%lu"
,
static_cast
<
long
unsigned
int
>
(
randomSize
)
)
;
// allocate random buffer
if
((
0
!=
randomSize
)
&&
!
setRandomInBuffer
(
&
randomBuffPtr
,
randomSize
))
...
...
@@ -181,7 +181,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(identityKeysJni)(JNIEnv *env, jobject
else
{
env
->
SetByteArrayRegion
(
byteArrayRetValue
,
0
/*offset*/
,
identityKeysLength
,
(
const
jbyte
*
)
identityKeysBytesPtr
);
LOGD
(
"## identityKeys(): success - result=%l
d
"
,
keysResult
);
LOGD
(
"## identityKeys(): success - result=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
keysResult
)
)
;
}
}
...
...
@@ -212,7 +212,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(maxOneTimeKeys)(JNIEnv *env, jobject thiz)
{
maxKeys
=
olm_account_max_number_of_one_time_keys
(
accountPtr
);
}
LOGD
(
"## maxOneTimeKey(): Max keys=%l
d
"
,
maxKeys
);
LOGD
(
"## maxOneTimeKey(): Max keys=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
maxKeys
)
)
;
return
(
jlong
)
maxKeys
;
}
...
...
@@ -238,7 +238,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeys)(JNIEnv *env, jobject th
else
{
// keys memory allocation
randomLength
=
olm_account_generate_one_time_keys_random_length
(
accountPtr
,
(
size_t
)
aNumberOfKeys
);
LOGD
(
"## generateOneTimeKeys(): randomLength=%l
d
"
,
randomLength
);
LOGD
(
"## generateOneTimeKeys(): randomLength=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
randomLength
)
)
;
if
((
0
!=
randomLength
)
&&
!
setRandomInBuffer
(
&
randomBufferPtr
,
randomLength
))
{
...
...
@@ -256,7 +256,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeys)(JNIEnv *env, jobject th
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
"## generateOneTimeKeys(): success - result=%l
d
"
,
result
);
LOGD
(
"## generateOneTimeKeys(): success - result=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
result
)
)
;
}
}
}
...
...
@@ -386,7 +386,7 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
}
else
{
LOGD
(
"## markOneTimeKeysAsPublishedJni(): success - retCode=%l
d
"
,
result
);
LOGD
(
"## markOneTimeKeysAsPublishedJni(): success - retCode=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
result
)
)
;
}
}
...
...
@@ -429,7 +429,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
// signature memory allocation
signatureLength
=
olm_account_signature_length
(
accountPtr
);
if
(
NULL
==
(
signedMsgPtr
=
(
void
*
)
malloc
(
signatureLength
*
sizeof
(
uint8_t
))))
if
(
NULL
==
(
signedMsgPtr
=
(
void
*
)
malloc
(
(
signatureLength
+
1
)
*
sizeof
(
uint8_t
))))
{
LOGE
(
"## signMessageJni(): failure - signature allocation OOM"
);
}
...
...
@@ -446,10 +446,11 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
}
else
{
// TODO check if signedMsgPtr needs to be null ended: signedMsgPtr[resultSign]='\0'
// 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=%l
d"
,
resultSign
);
LOGD
(
"## signMessageJni(): success - retCode=%l
u signatureLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
resultSign
),
static_cast
<
long
unsigned
int
>
(
signatureLength
)
);
}
free
(
signedMsgPtr
);
...
...
@@ -533,7 +534,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
{
size_t
pickledLength
=
olm_pickle_account_length
(
accountPtr
);
size_t
keyLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aKey
);
LOGD
(
" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu"
,
pickledLength
,
keyLength
);
LOGD
(
" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
)
,
static_cast
<
long
unsigned
int
>
(
keyLength
)
)
;
LOGD
(
" ## serializeDataWithKeyJni(): key=%s"
,(
char
const
*
)
keyPtr
);
if
(
NULL
==
(
pickledPtr
=
(
void
*
)
malloc
((
pickledLength
+
1
)
*
sizeof
(
uint8_t
))))
...
...
@@ -562,7 +563,7 @@ 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"
,
result
,
static_cast
<
char
*>
(
pickledPtr
));
LOGD
(
" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s"
,
static_cast
<
long
unsigned
int
>
(
result
)
,
static_cast
<
char
*>
(
pickledPtr
));
}
}
}
...
...
@@ -616,7 +617,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
{
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(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
)
,
static_cast
<
long
unsigned
int
>
(
keyLength
)
)
;
LOGD
(
" ## initWithSerializedDataJni(): key=%s"
,(
char
const
*
)
keyPtr
);
LOGD
(
" ## initWithSerializedDataJni(): pickled=%s"
,(
char
const
*
)
pickledPtr
);
...
...
@@ -633,7 +634,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
}
else
{
LOGD
(
" ## initWithSerializedDataJni(): success - result=%lu "
,
result
);
LOGD
(
" ## initWithSerializedDataJni(): success - result=%lu "
,
static_cast
<
long
unsigned
int
>
(
result
)
)
;
}
}
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
View file @
6b3cb69d
...
...
@@ -27,7 +27,7 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
{
OlmInboundGroupSession
*
sessionPtr
=
NULL
;
LOGD
(
"## releaseSessionJni():
intb
ound group session"
);
LOGD
(
"## releaseSessionJni():
InB
ound group session
IN
"
);
if
(
NULL
==
(
sessionPtr
=
(
OlmInboundGroupSession
*
)
getInboundGroupSessionInstanceId
(
env
,
thiz
)))
{
...
...
@@ -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
);
LOGI
(
" ## releaseSessionJni(): clear_inbound_group_session=%lu"
,
retCode
);
LOGI
(
" ## releaseSessionJni(): clear_inbound_group_session=%lu"
,
static_cast
<
long
unsigned
int
>
(
retCode
)
)
;
LOGD
(
" ## releaseSessionJni(): free IN"
);
free
(
sessionPtr
);
...
...
@@ -67,7 +67,7 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
else
if
(
NULL
!=
(
sessionPtr
=
(
OlmInboundGroupSession
*
)
malloc
(
sessionSize
)))
{
sessionPtr
=
olm_inbound_group_session
(
sessionPtr
);
LOGD
(
" ## createNewSessionJni(): success - inbound group session size=%lu"
,
sessionSize
);
LOGD
(
" ## createNewSessionJni(): success - inbound group session size=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionSize
)
)
;
}
else
{
...
...
@@ -106,7 +106,7 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
else
{
size_t
sessionKeyLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aSessionKey
);
LOGD
(
" ## initInboundSessionFromIdKeyJni(): sessionKeyLength=%lu"
,
sessionKeyLength
);
LOGD
(
" ## initInboundSessionFromIdKeyJni(): sessionKeyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionKeyLength
)
)
;
sessionResult
=
olm_init_inbound_group_session
(
sessionPtr
,
sessionKeyPtr
,
sessionKeyLength
);
if
(
sessionResult
==
olm_error
())
{
...
...
@@ -116,7 +116,7 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
" ## initInboundSessionFromIdKeyJni(): success - result=%lu"
,
sessionResult
);
LOGD
(
" ## initInboundSessionFromIdKeyJni(): success - result=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionResult
)
)
;
}
}
...
...
@@ -149,7 +149,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
{
// get the size to alloc
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"
,
static_cast
<
long
unsigned
int
>
(
lengthSessionId
)
)
;
if
(
NULL
==
(
sessionIdPtr
=
(
uint8_t
*
)
malloc
((
lengthSessionId
+
1
)
*
sizeof
(
uint8_t
))))
{
...
...
@@ -166,7 +166,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
{
// update length
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"
,
static_cast
<
long
unsigned
int
>
(
result
)
,
(
char
*
)
sessionIdPtr
);
returnValueStr
=
env
->
NewStringUTF
((
const
char
*
)
sessionIdPtr
);
}
free
(
sessionIdPtr
);
...
...
@@ -212,7 +212,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
else
{
memcpy
(
tempEncryptedPtr
,
encryptedMsgPtr
,
encryptedMsgLength
);
LOGD
(
" ## decryptMessageJni(): encryptedMsgLength=%lu encryptedMsg=%s"
,
encryptedMsgLength
,
encryptedMsgPtr
);
LOGD
(
" ## decryptMessageJni(): encryptedMsgLength=%lu encryptedMsg=%s"
,
static_cast
<
long
unsigned
int
>
(
encryptedMsgLength
)
,
encryptedMsgPtr
);
// get max plaintext length
size_t
maxPlainTextLength
=
olm_group_decrypt_max_plaintext_length
(
sessionPtr
,
...
...
@@ -224,7 +224,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
}
else
{
LOGD
(
" ## decryptMessageJni(): maxPlaintextLength=%lu"
,
maxPlainTextLength
);
LOGD
(
" ## decryptMessageJni(): maxPlaintextLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
maxPlainTextLength
)
)
;
// allocate output decrypted message
plainTextMsgPtr
=
static_cast
<
uint8_t
*>
(
malloc
((
maxPlainTextLength
+
1
)
*
sizeof
(
uint8_t
)));
...
...
@@ -245,7 +245,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
// update decrypted buffer size
plainTextMsgPtr
[
plaintextLength
]
=
static_cast
<
char
>
(
'\0'
);
LOGD
(
" ## decryptMessageJni(): decrypted returnedLg=%lu plainTextMsgPtr=%s"
,
plaintextLength
,
(
char
*
)
plainTextMsgPtr
);
LOGD
(
" ## decryptMessageJni(): decrypted returnedLg=%lu plainTextMsgPtr=%s"
,
static_cast
<
long
unsigned
int
>
(
plaintextLength
)
,
(
char
*
)
plainTextMsgPtr
);
decryptedMsgRetValue
=
env
->
NewStringUTF
((
const
char
*
)
plainTextMsgPtr
);
}
}
...
...
@@ -318,7 +318,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JN
{
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(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
)
,
static_cast
<
long
unsigned
int
>
(
keyLength
)
)
;
LOGD
(
" ## serializeDataWithKeyJni(): key=%s"
,(
char
const
*
)
keyPtr
);
if
(
NULL
==
(
pickledPtr
=
(
void
*
)
malloc
((
pickledLength
+
1
)
*
sizeof
(
uint8_t
))))
...
...
@@ -347,7 +347,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JN
// 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
));
LOGD
(
" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s"
,
static_cast
<
long
unsigned
int
>
(
result
)
,
static_cast
<
char
*>
(
pickledPtr
));
}
}
}
...
...
@@ -400,7 +400,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(
{
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(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
)
,
static_cast
<
long
unsigned
int
>
(
keyLength
)
)
;
LOGD
(
" ## initWithSerializedDataJni(): key=%s"
,(
char
const
*
)
keyPtr
);
LOGD
(
" ## initWithSerializedDataJni(): pickled=%s"
,(
char
const
*
)
pickledPtr
);
...
...
@@ -417,7 +417,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(
}
else
{
LOGD
(
" ## initWithSerializedDataJni(): success - result=%lu "
,
result
);
LOGD
(
" ## initWithSerializedDataJni(): success - result=%lu "
,
static_cast
<
long
unsigned
int
>
(
result
)
)
;
}
}
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni.h
View file @
6b3cb69d
...
...
@@ -28,12 +28,18 @@
#define TAG "OlmJniNative"
/* logging macros */
#define ENABLE_LOGS
//#define ENABLE_LOGS
#ifdef NDK_DEBUG
#warning "NDK_DEBUG is defined"
#else
#warning "NDK_DEBUG not defined"
#endif
#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
#ifdef
NDK_DEBUG
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
#else
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp
View file @
6b3cb69d
...
...
@@ -45,15 +45,12 @@ bool setRandomInBuffer(uint8_t **aBuffer2Ptr, size_t aRandomSize)
}
else
{
LOGD
(
"## setRandomInBuffer(): randomSize=%l
d
"
,
aRandomSize
);
LOGD
(
"## setRandomInBuffer(): randomSize=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
aRandomSize
)
)
;
srand
(
time
(
NULL
));
// init seed
for
(
size_t
i
=
0
;
i
<
aRandomSize
;
i
++
)
{
(
*
aBuffer2Ptr
)[
i
]
=
(
uint8_t
)(
rand
()
%
ACCOUNT_CREATION_RANDOM_MODULO
);
// debug purpose
//LOGD("## setRandomInBuffer(): randomBuffPtr[%ld]=%d",i, (*aBuffer2Ptr)[i]);
}
retCode
=
true
;
...
...
@@ -220,7 +217,7 @@ jstring serializeDataWithKey(JNIEnv *env, jobject thiz,
{
size_t
pickledLength
=
aGetLengthFunc
(
accountPtr
);
size_t
keyLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aKey
);
LOGD
(
" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu"
,
pickledLength
,
keyLength
);
LOGD
(
" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
)
,
static_cast
<
long
unsigned
int
>
(
keyLength
)
)
;
LOGD
(
" ## serializeDataWithKeyJni(): key=%s"
,(
char
const
*
)
keyPtr
);
if
(
NULL
==
(
pickledPtr
=
(
void
*
)
malloc
((
pickledLength
+
1
)
*
sizeof
(
uint8_t
))))
...
...
@@ -249,7 +246,7 @@ jstring serializeDataWithKey(JNIEnv *env, jobject thiz,
// 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
));
LOGD
(
" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s"
,
static_cast
<
long
unsigned
int
>
(
result
)
,
static_cast
<
char
*>
(
pickledPtr
));
}
}
}
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
View file @
6b3cb69d
...
...
@@ -27,7 +27,7 @@ JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *en
{
OlmOutboundGroupSession
*
sessionPtr
=
NULL
;
LOGD
(
"## releaseSessionJni():
o
ut
b
ound group session"
);
LOGD
(
"## releaseSessionJni():
O
ut
B
ound group session
IN
"
);
if
(
NULL
==
(
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
)))
{
...
...
@@ -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
);
LOGI
(
" ## releaseSessionJni(): clear_outbound_group_session=%lu"
,
retCode
);
LOGI
(
" ## releaseSessionJni(): clear_outbound_group_session=%lu"
,
static_cast
<
long
unsigned
int
>
(
retCode
)
)
;
LOGD
(
" ## releaseSessionJni(): free IN"
);
free
(
sessionPtr
);
...
...
@@ -67,7 +67,7 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv
else
if
(
NULL
!=
(
sessionPtr
=
(
OlmOutboundGroupSession
*
)
malloc
(
sessionSize
)))
{
sessionPtr
=
olm_outbound_group_session
(
sessionPtr
);
LOGD
(
" ## createNewSessionJni(): success - outbound group session size=%lu"
,
sessionSize
);
LOGD
(
" ## createNewSessionJni(): success - outbound group session size=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionSize
)
)
;
}
else
{
...
...
@@ -97,7 +97,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
{
// compute random buffer
size_t
randomLength
=
olm_init_outbound_group_session_random_length
(
sessionPtr
);
LOGW
(
" ## initOutboundGroupSessionJni(): randomLength=%lu"
,
randomLength
);
LOGW
(
" ## initOutboundGroupSessionJni(): randomLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
randomLength
)
)
;
if
((
0
!=
randomLength
)
&&
!
setRandomInBuffer
(
&
randomBuffPtr
,
randomLength
))
{
LOGE
(
" ## initOutboundGroupSessionJni(): failure - random buffer init"
);
...
...
@@ -116,7 +116,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
" ## initOutboundGroupSessionJni(): success - result=%lu"
,
sessionResult
);
LOGD
(
" ## initOutboundGroupSessionJni(): success - result=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionResult
)
)
;
}
}
}
...
...
@@ -148,7 +148,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
{
// get the size to alloc
size_t
lengthSessionId
=
olm_outbound_group_session_id_length
(
sessionPtr
);
LOGD
(
" ## sessionIdentifierJni(): outbound group session lengthSessionId=%lu"
,
lengthSessionId
);
LOGD
(
" ## sessionIdentifierJni(): outbound group session lengthSessionId=%lu"
,
static_cast
<
long
unsigned
int
>
(
lengthSessionId
)
)
;
if
(
NULL
==
(
sessionIdPtr
=
(
uint8_t
*
)
malloc
((
lengthSessionId
+
1
)
*
sizeof
(
uint8_t
))))
{
...
...
@@ -159,13 +159,13 @@ 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
())
{
LOGE
(
" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s"
,
(
const
char
*
)
olm_outbound_group_session_last_error
(
sessionPtr
));
LOGE
(
" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s"
,
reinterpret_cast
<
const
char
*>
(
olm_outbound_group_session_last_error
(
sessionPtr
))
)
;
}
else
{
// update length
sessionIdPtr
[
result
]
=
static_cast
<
char
>
(
'\0'
);
LOGD
(
" ## sessionIdentifierJni(): success - outbound group session identifier result=%lu sessionId=%s"
,
result
,
(
char
*
)
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
);
}
...
...
@@ -224,7 +224,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
{
// get the size to alloc
size_t
sessionKeyLength
=
olm_outbound_group_session_key_length
(
sessionPtr
);
LOGD
(
" ## sessionKeyJni(): sessionKeyLength=%lu"
,
sessionKeyLength
);
LOGD
(
" ## sessionKeyJni(): sessionKeyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionKeyLength
)
)
;
if
(
NULL
==
(
sessionKeyPtr
=
(
uint8_t
*
)
malloc
((
sessionKeyLength
+
1
)
*
sizeof
(
uint8_t
))))
{
...
...
@@ -241,7 +241,7 @@ 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"
,
result
,
(
char
*
)
sessionKeyPtr
);
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
);
}
...
...
@@ -279,7 +279,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
{
// get clear message length
size_t
clearMsgLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aClearMsg
);
LOGD
(
" ## encryptMessageJni(): clearMsgLength=%lu"
,
clearMsgLength
);
LOGD
(
" ## encryptMessageJni(): clearMsgLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
clearMsgLength
)
)
;
// compute max encrypted length
size_t
encryptedMsgLength
=
olm_group_encrypt_message_length
(
sessionPtr
,
clearMsgLength
);
...
...
@@ -289,7 +289,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
}
else
{
LOGD
(
" ## encryptMessageJni(): estimated encryptedMsgLength=%lu"
,
encryptedMsgLength
);
LOGD
(
" ## encryptMessageJni(): estimated encryptedMsgLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
encryptedMsgLength
)
)
;
size_t
encryptedLength
=
olm_group_encrypt
(
sessionPtr
,
(
uint8_t
*
)
clearMsgPtr
,
...
...
@@ -305,7 +305,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
// update decrypted buffer size
encryptedMsgPtr
[
encryptedLength
]
=
static_cast
<
char
>
(
'\0'
);
LOGD
(
" ## encryptMessageJni(): encrypted returnedLg=%lu plainTextMsgPtr=%s"
,
encryptedLength
,
(
char
*
)
encryptedMsgPtr
);
LOGD
(
" ## encryptMessageJni(): encrypted returnedLg=%lu plainTextMsgPtr=%s"
,
static_cast
<
long
unsigned
int
>
(
encryptedLength
)
,
reinterpret_cast
<
char
*
>
(
encryptedMsgPtr
)
)
;
encryptedMsgRetValue
=
env
->
NewStringUTF
((
const
char
*
)
encryptedMsgPtr
);
}
}
...
...
@@ -372,7 +372,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
{
size_t
pickledLength
=
olm_pickle_outbound_group_session_length
(
sessionPtr
);
size_t
keyLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aKey
);
LOGD
(
" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu"
,
pickledLength
,
keyLength
);
LOGD
(
" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
)
,
static_cast
<
long
unsigned
int
>
(
keyLength
)
)
;
LOGD
(
" ## serializeDataWithKeyJni(): key=%s"
,(
char
const
*
)
keyPtr
);
if
(
NULL
==
(
pickledPtr
=
(
void
*
)
malloc
((
pickledLength
+
1
)
*
sizeof
(
uint8_t
))))
...
...
@@ -401,7 +401,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
// 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
));
LOGD
(
" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s"
,
static_cast
<
long
unsigned
int
>
(
result
)
,
static_cast
<
char
*>
(
pickledPtr
));
}
}
}
...
...
@@ -454,7 +454,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)
{
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(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
)
,
static_cast
<
long
unsigned
int
>
(
keyLength
)
)
;
LOGD
(
" ## initWithSerializedDataJni(): key=%s"
,(
char
const
*
)
keyPtr
);
LOGD
(
" ## initWithSerializedDataJni(): pickled=%s"
,(
char
const
*
)
pickledPtr
);
...
...
@@ -471,7 +471,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)
}
else
{
LOGD
(
" ## initWithSerializedDataJni(): success - result=%lu "
,
result
);
LOGD
(
" ## initWithSerializedDataJni(): success - result=%lu "
,
static_cast
<
long
unsigned
int
>
(
result
)
)
;
}
}
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
View file @
6b3cb69d
...
...
@@ -31,7 +31,7 @@ OlmSession* initializeSessionMemory()
if
(
NULL
!=
(
sessionPtr
=
(
OlmSession
*
)
malloc
(
sessionSize
)))
{
// init session object
sessionPtr
=
olm_session
(
sessionPtr
);
LOGD
(
"## initializeSessionMemory(): success - OLM session size=%lu"
,
sessionSize
);
LOGD
(
"## initializeSessionMemory(): success - OLM session size=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionSize
)
)
;
}
else
{
...
...
@@ -54,6 +54,8 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz
{
OlmSession
*
sessionPtr
=
NULL
;
LOGD
(
"## releaseSessionJni(): IN"
);
if
(
NULL
==
(
sessionPtr
=
(
OlmSession
*
)
getSessionInstanceId
(
env
,
thiz
)))
{
LOGE
(
"## releaseSessionJni(): failure - invalid Session ptr=NULL"
);
...
...
@@ -62,10 +64,8 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz
{
olm_clear_session
(
sessionPtr
);
LOGD
(
"## releaseSessionJni(): IN"
);
// even if free(NULL) does not crash, logs are performed for debug purpose
free
(
sessionPtr
);
LOGD
(
"## releaseSessionJni(): OUT"
);
}
}
...
...
@@ -131,7 +131,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
else
{
// allocate random buffer
size_t
randomSize
=
olm_create_outbound_session_random_length
(
sessionPtr
);
LOGD
(
"## initOutboundSessionJni(): randomSize=%lu"
,
randomSize
);
LOGD
(
"## initOutboundSessionJni(): randomSize=%lu"
,
static_cast
<
long
unsigned
int
>
(
randomSize
)
)
;
if
((
0
!=
randomSize
)
&&
!
setRandomInBuffer
(
&
randomBuffPtr
,
randomSize
))
{
LOGE
(
"## initOutboundSessionJni(): failure - random buffer init"
);
...
...
@@ -166,7 +166,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
"## initOutboundSessionJni(): success - result=%l
d
"
,
sessionResult
);
LOGD
(
"## initOutboundSessionJni(): success - result=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
sessionResult
)
)
;
}
}
}
...
...
@@ -231,7 +231,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject
else
{
size_t
messageLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aOneTimeKeyMsg
);
LOGD
(
"## initInboundSessionJni(): messageLength=%lu message=%s"
,
messageLength
,
messagePtr
);
LOGD
(
"## initInboundSessionJni(): messageLength=%lu message=%s"
,
static_cast
<
long
unsigned
int
>
(
messageLength
)
,
messagePtr
);
sessionResult
=
olm_create_inbound_session
(
sessionPtr
,
accountPtr
,
(
void
*
)
messagePtr
,
messageLength
);
if
(
sessionResult
==
olm_error
())
{
...
...
@@ -240,7 +240,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
"## initInboundSessionJni(): success - result=%l
d
"
,
sessionResult
);
LOGD
(
"## initInboundSessionJni(): success - result=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
sessionResult
)
)
;
}
// free local alloc
...
...
@@ -296,7 +296,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
size_t
messageLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aOneTimeKeyMsg
);
size_t
theirIdentityKeyLength
=
(
size_t
)
env
->
GetStringUTFLength
(
aTheirIdentityKey
);
LOGD
(
"## initInboundSessionFromIdKeyJni(): message=%s messageLength=%lu"
,
messagePtr
,
messageLength
);
LOGD
(
"## initInboundSessionFromIdKeyJni(): message=%s messageLength=%lu"
,
messagePtr
,
static_cast
<
long
unsigned
int
>
(
messageLength
)
)
;
sessionResult
=
olm_create_inbound_session_from
(
sessionPtr
,
accountPtr
,
theirIdentityKeyPtr
,
theirIdentityKeyLength
,
(
void
*
)
messagePtr
,
messageLength
);
if
(
sessionResult
==
olm_error
())
{
...
...
@@ -305,7 +305,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
"## initInboundSessionFromIdKeyJni(): success - result=%l
d
"
,
sessionResult
);
LOGD
(
"## initInboundSessionFromIdKeyJni(): success - result=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
sessionResult
)
)
;
}
}
...
...
@@ -357,7 +357,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobje
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
"## matchesInboundSessionJni(): success - result=%l
d
"
,
matchResult
);
LOGD
(
"## matchesInboundSessionJni(): success - result=%l
u
"
,
static_cast
<
long
unsigned
int
>
(
matchResult
)
)
;
}
}
...
...
@@ -417,7 +417,7 @@ JNIEXPORT jint JNICALL OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(J
else
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
"## matchesInboundSessionFromIdKeyJni(): success - result=%lu"
,
matchResult
);
LOGD
(
"## matchesInboundSessionFromIdKeyJni(): success - result=%lu"
,
static_cast
<
long
unsigned
int
>
(
matchResult
)
)
;
}
}
...
...
@@ -492,7 +492,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
// Note: olm_encrypt_random_length() can return 0, which means
// it just does not need new random data to encrypt a new message
size_t
randomLength
=
olm_encrypt_random_length
(
sessionPtr
);
LOGD
(
"## encryptMessageJni(): randomLength=%lu"
,
randomLength
);
LOGD
(
"## encryptMessageJni(): randomLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
randomLength
)
)
;
if
((
0
!=
randomLength
)
&&
!
setRandomInBuffer
(
&
randomBuffPtr
,
randomLength
))
{
LOGE
(
"## encryptMessageJni(): failure - random buffer init"
);
...
...
@@ -513,7 +513,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
LOGW
(
"## encryptMessageJni(): random buffer is not required"
);
}
LOGD
(
"## encryptMessageJni(): messageType=%lu randomLength=%lu clearMsgLength=%lu encryptedMsgLength=%lu"
,
messageType
,
randomLength
,
clearMsgLength
,
encryptedMsgLength
);
LOGD
(
"## encryptMessageJni(): messageType=%lu randomLength=%lu clearMsgLength=%lu encryptedMsgLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
messageType
),
static_cast
<
long
unsigned
int
>
(
randomLength
)
,
static_cast
<
long
unsigned
int
>
(
clearMsgLength
)
,
static_cast
<
long
unsigned
int
>
(
encryptedMsgLength
)
)
;
// encrypt message
size_t
result
=
olm_encrypt
(
sessionPtr
,
(
void
const
*
)
clearMsgPtr
,
...
...
@@ -539,7 +539,7 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
env
->
SetObjectField
(
aEncryptedMsg
,
encryptedMsgFieldId
,
(
jobject
)
encryptedJstring
);
retCode
=
ERROR_CODE_OK
;
LOGD
(
"## encryptMessageJni(): success - result=%lu Type=%lu utfLength=%lu encryptedMsg=%s"
,
result
,
messageType
,
(
size_t
)
env
->
GetStringUTFLength
(
encryptedJstring
),
(
const
char
*
)
encryptedMsgPtr
);
LOGD
(
"## encryptMessageJni(): success - result=%lu Type=%lu utfLength=%lu encryptedMsg=%s"
,
static_cast
<
long
unsigned
int
>
(
result
)
,
static_cast
<
long
unsigned
int
>
(
messageType
)
,
static_cast
<
long
unsigned
int
>
(
(
size_t
)
env
->
GetStringUTFLength
(
encryptedJstring
)
)
,
(
const
char
*
)
encryptedMsgPtr
);
}
}
}
...
...
@@ -624,7 +624,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
// create a dedicated temp buffer to be used in next Olm API calls
tempEncryptedPtr
=
static_cast
<
char
*>
(
malloc
(
encryptedMsgLength
*
sizeof
(
uint8_t
)));
memcpy
(
tempEncryptedPtr
,
encryptedMsgPtr
,
encryptedMsgLength
);
LOGD
(
"## decryptMessageJni(): MsgType=%l
d
encryptedMsgLength=%lu encryptedMsg=%s"
,
encryptedMsgType
,
encryptedMsgLength
,
encryptedMsgPtr
);
LOGD
(
"## decryptMessageJni(): MsgType=%l
u
encryptedMsgLength=%lu encryptedMsg=%s"
,
static_cast
<
long
unsigned
int
>
(
encryptedMsgType
),
static_cast
<
long
unsigned
int
>
(
encryptedMsgLength
)
,
encryptedMsgPtr
);
// get max plaintext length
size_t
maxPlainTextLength
=
olm_decrypt_max_plaintext_length
(
sessionPtr
,
...
...
@@ -639,7 +639,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t