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
846ea49a
Commit
846ea49a
authored
Jan 04, 2017
by
ylecollen
Browse files
the OlmOutboundGroupSession methods trigger an exception when they fail
parent
261c0808
Changes
6
Show whitespace changes
Inline
Side-by-side
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
View file @
846ea49a
...
@@ -90,7 +90,14 @@ public class OlmGroupSessionTest {
...
@@ -90,7 +90,14 @@ public class OlmGroupSessionTest {
@Test
@Test
public
void
test02GetOutboundGroupSessionIdentifier
()
{
public
void
test02GetOutboundGroupSessionIdentifier
()
{
// test session ID
// test session ID
mAliceSessionIdentifier
=
null
;
try
{
mAliceSessionIdentifier
=
mAliceOutboundGroupSession
.
sessionIdentifier
();
mAliceSessionIdentifier
=
mAliceOutboundGroupSession
.
sessionIdentifier
();
}
catch
(
Exception
e
)
{
assertTrue
(
e
.
getMessage
(),
false
);
}
assertNotNull
(
mAliceSessionIdentifier
);
assertNotNull
(
mAliceSessionIdentifier
);
assertTrue
(
mAliceSessionIdentifier
.
length
()
>
0
);
assertTrue
(
mAliceSessionIdentifier
.
length
()
>
0
);
}
}
...
@@ -98,7 +105,13 @@ public class OlmGroupSessionTest {
...
@@ -98,7 +105,13 @@ public class OlmGroupSessionTest {
@Test
@Test
public
void
test03GetOutboundGroupSessionKey
()
{
public
void
test03GetOutboundGroupSessionKey
()
{
// test session Key
// test session Key
mAliceOutboundSessionKey
=
null
;
try
{
mAliceOutboundSessionKey
=
mAliceOutboundGroupSession
.
sessionKey
();
mAliceOutboundSessionKey
=
mAliceOutboundGroupSession
.
sessionKey
();
}
catch
(
Exception
e
)
{
assertTrue
(
e
.
getMessage
(),
false
);
}
assertNotNull
(
mAliceOutboundSessionKey
);
assertNotNull
(
mAliceOutboundSessionKey
);
assertTrue
(
mAliceOutboundSessionKey
.
length
()
>
0
);
assertTrue
(
mAliceOutboundSessionKey
.
length
()
>
0
);
}
}
...
@@ -115,7 +128,7 @@ public class OlmGroupSessionTest {
...
@@ -115,7 +128,7 @@ public class OlmGroupSessionTest {
// alice encrypts a message to bob
// alice encrypts a message to bob
try
{
try
{
mAliceToBobMessage
=
mAliceOutboundGroupSession
.
encryptMessage
(
CLEAR_MESSAGE1
);
mAliceToBobMessage
=
mAliceOutboundGroupSession
.
encryptMessage
(
CLEAR_MESSAGE1
);
}
catch
(
OlmOutboundGroupSession
.
EncryptMessage
Exception
e
)
{
}
catch
(
Exception
e
)
{
assertTrue
(
"Exception in bob encryptMessage, Exception code="
+
e
.
getMessage
(),
false
);
assertTrue
(
"Exception in bob encryptMessage, Exception code="
+
e
.
getMessage
(),
false
);
}
}
assertFalse
(
TextUtils
.
isEmpty
(
mAliceToBobMessage
));
assertFalse
(
TextUtils
.
isEmpty
(
mAliceToBobMessage
));
...
@@ -275,7 +288,13 @@ public class OlmGroupSessionTest {
...
@@ -275,7 +288,13 @@ public class OlmGroupSessionTest {
assertNotNull
(
aliceOutboundGroupSession
);
assertNotNull
(
aliceOutboundGroupSession
);
// get the session key from the outbound group session
// get the session key from the outbound group session
String
sessionKeyRef
=
aliceOutboundGroupSession
.
sessionKey
();
String
sessionKeyRef
=
null
;
try
{
sessionKeyRef
=
aliceOutboundGroupSession
.
sessionKey
();
}
catch
(
Exception
e
)
{
assertTrue
(
e
.
getMessage
(),
false
);
}
assertNotNull
(
sessionKeyRef
);
assertNotNull
(
sessionKeyRef
);
// bob creates INBOUND GROUP SESSION
// bob creates INBOUND GROUP SESSION
...
@@ -286,7 +305,6 @@ public class OlmGroupSessionTest {
...
@@ -286,7 +305,6 @@ public class OlmGroupSessionTest {
}
}
assertNotNull
(
bobInboundGroupSessionRef
);
assertNotNull
(
bobInboundGroupSessionRef
);
// serialize alice session
// serialize alice session
Context
context
=
getInstrumentation
().
getContext
();
Context
context
=
getInstrumentation
().
getContext
();
try
{
try
{
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmException.java
View file @
846ea49a
...
@@ -49,6 +49,9 @@ public class OlmException extends IOException {
...
@@ -49,6 +49,9 @@ public class OlmException extends IOException {
public
static
final
int
EXCEPTION_CODE_SESSION_IDENTIFIER
=
30
;
public
static
final
int
EXCEPTION_CODE_SESSION_IDENTIFIER
=
30
;
public
static
final
int
EXCEPTION_CODE_SESSION_DECRYPT_SESSION
=
31
;
public
static
final
int
EXCEPTION_CODE_SESSION_DECRYPT_SESSION
=
31
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_IDENTIFIER
=
40
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_KEY
=
41
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_ENCRYPT_MESSAGE
=
42
;
// exception human readable messages
// exception human readable messages
public
static
final
String
EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION
=
"createNewSession() failed"
;
public
static
final
String
EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION
=
"createNewSession() failed"
;
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
View file @
846ea49a
...
@@ -209,8 +209,6 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -209,8 +209,6 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
protected
String
serialize
(
String
aKey
,
StringBuffer
aErrorMsg
)
{
protected
String
serialize
(
String
aKey
,
StringBuffer
aErrorMsg
)
{
String
pickleRetValue
=
null
;
String
pickleRetValue
=
null
;
aErrorMsg
.
setLength
(
0
);
// sanity check
// sanity check
if
(
null
==
aErrorMsg
)
{
if
(
null
==
aErrorMsg
)
{
Log
.
e
(
LOG_TAG
,
"## serialize(): invalid parameter - aErrorMsg=null"
);
Log
.
e
(
LOG_TAG
,
"## serialize(): invalid parameter - aErrorMsg=null"
);
...
@@ -218,6 +216,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -218,6 +216,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
}
else
if
(
TextUtils
.
isEmpty
(
aKey
))
{
}
else
if
(
TextUtils
.
isEmpty
(
aKey
))
{
aErrorMsg
.
append
(
"Invalid input parameters in serialize()"
);
aErrorMsg
.
append
(
"Invalid input parameters in serialize()"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
try
{
try
{
pickleRetValue
=
new
String
(
serializeJni
(
aKey
.
getBytes
(
"UTF-8"
)),
"UTF-8"
);
pickleRetValue
=
new
String
(
serializeJni
(
aKey
.
getBytes
(
"UTF-8"
)),
"UTF-8"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
View file @
846ea49a
...
@@ -42,15 +42,6 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -42,15 +42,6 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
*/
*/
private
transient
long
mNativeId
;
private
transient
long
mNativeId
;
/**
* Exception triggered in {@link #encryptMessage(String)}
*/
static
public
class
EncryptMessageException
extends
Exception
{
public
EncryptMessageException
(
String
message
)
{
super
(
message
);
}
}
/**
/**
* Constructor.<br>
* Constructor.<br>
* Create and save a new session native instance ID and
* Create and save a new session native instance ID and
...
@@ -60,10 +51,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -60,10 +51,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
*/
*/
public
OlmOutboundGroupSession
()
throws
OlmException
{
public
OlmOutboundGroupSession
()
throws
OlmException
{
if
(
createNewSession
())
{
if
(
createNewSession
())
{
if
(
0
!=
initOutboundGroupSession
())
{
initOutboundGroupSession
();
releaseSession
();
// prevent memory leak before throwing
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION
,
OlmException
.
EXCEPTION_MSG_INIT_OUTBOUND_GROUP_SESSION
);
}
}
else
{
}
else
{
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION
,
OlmException
.
EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION
);
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION
,
OlmException
.
EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION
);
}
}
...
@@ -114,25 +102,29 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -114,25 +102,29 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
/**
/**
* Start a new outbound group session.<br>
* Start a new outbound group session.<br>
* @
return 0 if operation succeed, -1 otherwise
* @
exception OlmException the failre reason
*/
*/
private
int
initOutboundGroupSession
()
{
private
void
initOutboundGroupSession
()
throws
OlmException
{
return
initOutboundGroupSessionJni
();
try
{
initOutboundGroupSessionJni
();
}
catch
(
Exception
e
)
{
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION
,
e
.
getMessage
());
}
}
}
private
native
int
initOutboundGroupSessionJni
();
private
native
void
initOutboundGroupSessionJni
();
/**
/**
* Get a base64-encoded identifier for this session.
* Get a base64-encoded identifier for this session.
* @return session identifier
if operation succeed, null otherwise.
* @return session identifier
*/
*/
public
String
sessionIdentifier
()
{
public
String
sessionIdentifier
()
throws
OlmException
{
try
{
try
{
return
new
String
(
sessionIdentifierJni
(),
"UTF-8"
);
return
new
String
(
sessionIdentifierJni
(),
"UTF-8"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionIdentifier() failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## sessionIdentifier() failed "
+
e
.
getMessage
());
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_IDENTIFIER
,
e
.
getMessage
());
}
}
return
null
;
}
}
private
native
byte
[]
sessionIdentifierJni
();
private
native
byte
[]
sessionIdentifierJni
();
...
@@ -153,15 +145,15 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -153,15 +145,15 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* Each message is sent with a different ratchet key. This method returns the
* Each message is sent with a different ratchet key. This method returns the
* ratchet key that will be used for the next message.
* ratchet key that will be used for the next message.
* @return outbound session key
* @return outbound session key
* @exception OlmException the failure reason
*/
*/
public
String
sessionKey
()
{
public
String
sessionKey
()
throws
OlmException
{
try
{
try
{
return
new
String
(
sessionKeyJni
(),
"UTF-8"
);
return
new
String
(
sessionKeyJni
(),
"UTF-8"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionKey() failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## sessionKey() failed "
+
e
.
getMessage
());
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_KEY
,
e
.
getMessage
());
}
}
return
null
;
}
}
private
native
byte
[]
sessionKeyJni
();
private
native
byte
[]
sessionKeyJni
();
...
@@ -171,33 +163,27 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -171,33 +163,27 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* The message given as parameter is encrypted and returned as the return value.
* The message given as parameter is encrypted and returned as the return value.
* @param aClearMsg message to be encrypted
* @param aClearMsg message to be encrypted
* @return the encrypted message
* @return the encrypted message
* @exception
EncryptMessage
Exception the encryption failure reason
* @exception
Olm
Exception the encryption failure reason
*/
*/
public
String
encryptMessage
(
String
aClearMsg
)
throws
EncryptMessage
Exception
{
public
String
encryptMessage
(
String
aClearMsg
)
throws
Olm
Exception
{
String
retValue
=
null
;
String
retValue
=
null
;
if
(!
TextUtils
.
isEmpty
(
aClearMsg
))
{
if
(!
TextUtils
.
isEmpty
(
aClearMsg
))
{
StringBuffer
errorMsg
=
new
StringBuffer
();
try
{
try
{
byte
[]
encryptedBuffer
=
encryptMessageJni
(
aClearMsg
.
getBytes
(
"UTF-8"
)
,
errorMsg
);
byte
[]
encryptedBuffer
=
encryptMessageJni
(
aClearMsg
.
getBytes
(
"UTF-8"
));
if
(
null
!=
encryptedBuffer
)
{
if
(
null
!=
encryptedBuffer
)
{
retValue
=
new
String
(
encryptedBuffer
,
"UTF-8"
);
retValue
=
new
String
(
encryptedBuffer
,
"UTF-8"
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## encryptMessage() failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## encryptMessage() failed "
+
e
.
getMessage
());
errorMsg
.
append
(
e
.
getMessage
());
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_OUTBOUND_GROUP_ENCRYPT_MESSAGE
,
e
.
getMessage
());
}
if
(
0
!=
errorMsg
.
length
())
{
throw
new
EncryptMessageException
(
errorMsg
.
toString
());
}
}
}
}
return
retValue
;
return
retValue
;
}
}
private
native
byte
[]
encryptMessageJni
(
byte
[]
aClearMsgBuffer
,
StringBuffer
aErrorMsg
);
private
native
byte
[]
encryptMessageJni
(
byte
[]
aClearMsgBuffer
);
//==============================================================================================================
//==============================================================================================================
...
@@ -242,9 +228,8 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -242,9 +228,8 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
}
else
if
(
TextUtils
.
isEmpty
(
aKey
))
{
}
else
if
(
TextUtils
.
isEmpty
(
aKey
))
{
aErrorMsg
.
append
(
"Invalid input parameters in serialize()"
);
aErrorMsg
.
append
(
"Invalid input parameters in serialize()"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
try
{
try
{
pickleRetValue
=
serializeJni
(
aKey
.
getBytes
(
"UTF-8"
)
,
aErrorMsg
);
pickleRetValue
=
serializeJni
(
aKey
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## serialize(): failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## serialize(): failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
...
@@ -253,7 +238,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -253,7 +238,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return
pickleRetValue
;
return
pickleRetValue
;
}
}
private
native
String
serializeJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
private
native
String
serializeJni
(
byte
[]
aKey
);
/**
/**
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
View file @
846ea49a
...
@@ -84,11 +84,10 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv
...
@@ -84,11 +84,10 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv
/**
/**
* Start a new outbound session.<br>
* Start a new outbound session.<br>
* @return ERROR_CODE_OK if operation succeed, ERROR_CODE_KO otherwise
*/
*/
JNIEXPORT
jint
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
initOutboundGroupSessionJni
)(
JNIEnv
*
env
,
jobject
thiz
)
JNIEXPORT
void
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
initOutboundGroupSessionJni
)(
JNIEnv
*
env
,
jobject
thiz
)
{
{
jint
retCode
=
ERROR_CODE_KO
;
const
char
*
errorMessage
=
NULL
;
LOGD
(
"## initOutboundGroupSessionJni(): IN"
);
LOGD
(
"## initOutboundGroupSessionJni(): IN"
);
...
@@ -97,6 +96,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
...
@@ -97,6 +96,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
if
(
!
sessionPtr
)
if
(
!
sessionPtr
)
{
{
LOGE
(
" ## initOutboundGroupSessionJni(): failure - invalid outbound group session instance"
);
LOGE
(
" ## initOutboundGroupSessionJni(): failure - invalid outbound group session instance"
);
errorMessage
=
"invalid outbound group session instance"
;
}
}
else
else
{
{
...
@@ -109,6 +109,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
...
@@ -109,6 +109,7 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
if
((
0
!=
randomLength
)
&&
!
setRandomInBuffer
(
env
,
&
randomBuffPtr
,
randomLength
))
if
((
0
!=
randomLength
)
&&
!
setRandomInBuffer
(
env
,
&
randomBuffPtr
,
randomLength
))
{
{
LOGE
(
" ## initOutboundGroupSessionJni(): failure - random buffer init"
);
LOGE
(
" ## initOutboundGroupSessionJni(): failure - random buffer init"
);
errorMessage
=
"random buffer init"
;
}
}
else
else
{
{
...
@@ -120,11 +121,11 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
...
@@ -120,11 +121,11 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
size_t
sessionResult
=
olm_init_outbound_group_session
(
sessionPtr
,
randomBuffPtr
,
randomLength
);
size_t
sessionResult
=
olm_init_outbound_group_session
(
sessionPtr
,
randomBuffPtr
,
randomLength
);
if
(
sessionResult
==
olm_error
())
{
if
(
sessionResult
==
olm_error
())
{
LOGE
(
" ## initOutboundGroupSessionJni(): failure - init outbound session creation Msg=%s"
,(
const
char
*
)
olm_outbound_group_session_last_error
(
sessionPtr
));
errorMessage
=
(
const
char
*
)
olm_outbound_group_session_last_error
(
sessionPtr
);
LOGE
(
" ## initOutboundGroupSessionJni(): failure - init outbound session creation Msg=%s"
,
errorMessage
);
}
}
else
else
{
{
retCode
=
ERROR_CODE_OK
;
LOGD
(
" ## initOutboundGroupSessionJni(): success - result=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionResult
));
LOGD
(
" ## initOutboundGroupSessionJni(): success - result=%lu"
,
static_cast
<
long
unsigned
int
>
(
sessionResult
));
}
}
...
@@ -132,7 +133,10 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
...
@@ -132,7 +133,10 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
}
}
}
}
return
retCode
;
if
(
errorMessage
)
{
env
->
ThrowNew
(
env
->
FindClass
(
"java/lang/Exception"
),
errorMessage
);
}
}
}
/**
/**
...
@@ -142,12 +146,14 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
...
@@ -142,12 +146,14 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
{
{
LOGD
(
"## sessionIdentifierJni(): outbound group session IN"
);
LOGD
(
"## sessionIdentifierJni(): outbound group session IN"
);
const
char
*
errorMessage
=
NULL
;
OlmOutboundGroupSession
*
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
);
OlmOutboundGroupSession
*
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
);
jbyteArray
returnValue
=
0
;
jbyteArray
returnValue
=
0
;
if
(
!
sessionPtr
)
if
(
!
sessionPtr
)
{
{
LOGE
(
" ## sessionIdentifierJni(): failure - invalid outbound group session instance"
);
LOGE
(
" ## sessionIdentifierJni(): failure - invalid outbound group session instance"
);
errorMessage
=
"invalid outbound group session instance"
;
}
}
else
else
{
{
...
@@ -160,6 +166,7 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
...
@@ -160,6 +166,7 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
if
(
!
sessionIdPtr
)
if
(
!
sessionIdPtr
)
{
{
LOGE
(
" ## sessionIdentifierJni(): failure - outbound identifier allocation OOM"
);
LOGE
(
" ## sessionIdentifierJni(): failure - outbound identifier allocation OOM"
);
errorMessage
=
"outbound identifier allocation OOM"
;
}
}
else
else
{
{
...
@@ -167,7 +174,8 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
...
@@ -167,7 +174,8 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
if
(
result
==
olm_error
())
if
(
result
==
olm_error
())
{
{
LOGE
(
" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s"
,
reinterpret_cast
<
const
char
*>
(
olm_outbound_group_session_last_error
(
sessionPtr
)));
errorMessage
=
reinterpret_cast
<
const
char
*>
(
olm_outbound_group_session_last_error
(
sessionPtr
));
LOGE
(
" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s"
,
errorMessage
);
}
}
else
else
{
{
...
@@ -185,6 +193,11 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
...
@@ -185,6 +193,11 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(J
}
}
}
}
if
(
errorMessage
)
{
env
->
ThrowNew
(
env
->
FindClass
(
"java/lang/Exception"
),
errorMessage
);
}
return
returnValue
;
return
returnValue
;
}
}
...
@@ -223,12 +236,14 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
...
@@ -223,12 +236,14 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
{
{
LOGD
(
"## sessionKeyJni(): outbound group session IN"
);
LOGD
(
"## sessionKeyJni(): outbound group session IN"
);
const
char
*
errorMessage
=
NULL
;
OlmOutboundGroupSession
*
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
);
OlmOutboundGroupSession
*
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
);
jbyteArray
returnValue
=
0
;
jbyteArray
returnValue
=
0
;
if
(
!
sessionPtr
)
if
(
!
sessionPtr
)
{
{
LOGE
(
" ## sessionKeyJni(): failure - invalid outbound group session instance"
);
LOGE
(
" ## sessionKeyJni(): failure - invalid outbound group session instance"
);
errorMessage
=
"invalid outbound group session instance"
;
}
}
else
else
{
{
...
@@ -241,6 +256,7 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
...
@@ -241,6 +256,7 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
if
(
!
sessionKeyPtr
)
if
(
!
sessionKeyPtr
)
{
{
LOGE
(
" ## sessionKeyJni(): failure - session key allocation OOM"
);
LOGE
(
" ## sessionKeyJni(): failure - session key allocation OOM"
);
errorMessage
=
"session key allocation OOM"
;
}
}
else
else
{
{
...
@@ -248,7 +264,8 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
...
@@ -248,7 +264,8 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
if
(
result
==
olm_error
())
if
(
result
==
olm_error
())
{
{
LOGE
(
" ## sessionKeyJni(): failure - session key failure Msg=%s"
,(
const
char
*
)
olm_outbound_group_session_last_error
(
sessionPtr
));
errorMessage
=
(
const
char
*
)
olm_outbound_group_session_last_error
(
sessionPtr
);
LOGE
(
" ## sessionKeyJni(): failure - session key failure Msg=%s"
,
errorMessage
);
}
}
else
else
{
{
...
@@ -265,44 +282,38 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
...
@@ -265,44 +282,38 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
}
}
}
}
if
(
errorMessage
)
{
env
->
ThrowNew
(
env
->
FindClass
(
"java/lang/Exception"
),
errorMessage
);
}
return
returnValue
;
return
returnValue
;
}
}
JNIEXPORT
jbyteArray
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
encryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aClearMsgBuffer
,
jobject
aErrorMsg
)
JNIEXPORT
jbyteArray
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
encryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aClearMsgBuffer
)
{
{
LOGD
(
"## encryptMessageJni(): IN"
);
LOGD
(
"## encryptMessageJni(): IN"
);
const
char
*
errorMessage
=
NULL
;
jbyteArray
encryptedMsgRet
=
0
;
jbyteArray
encryptedMsgRet
=
0
;
OlmOutboundGroupSession
*
sessionPtr
=
NULL
;
OlmOutboundGroupSession
*
sessionPtr
=
NULL
;
jbyte
*
clearMsgPtr
=
NULL
;
jbyte
*
clearMsgPtr
=
NULL
;
jclass
errorMsgJClass
=
0
;
jmethodID
errorMsgMethodId
=
0
;
if
(
!
(
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
)))
if
(
!
(
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
)))
{
{
LOGE
(
" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL"
);
LOGE
(
" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL"
);
}
errorMessage
=
"invalid outbound group session ptr=NULL"
;
else
if
(
!
aErrorMsg
)
{
LOGE
(
" ## encryptMessageJni(): failure - invalid error output"
);
}