Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Robert Long
Olm
Commits
dcf5582f
Commit
dcf5582f
authored
Feb 15, 2022
by
Alex Baker
Committed by
Hubert Chathi
Feb 25, 2022
Browse files
Add Java wrapper for olm_session_describe
Signed-off-by:
Alex Baker
<
alex@beeper.com
>
parent
9d669659
Changes
5
Hide whitespace changes
Inline
Side-by-side
android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
View file @
dcf5582f
...
...
@@ -1011,4 +1011,75 @@ public class OlmSessionTest {
assertTrue
(
bobSession
.
isReleased
());
}
@Test
public
void
test07AliceBobSessionDescribe
()
{
// creates alice & bob accounts
OlmAccount
aliceAccount
=
null
;
OlmAccount
bobAccount
=
null
;
try
{
aliceAccount
=
new
OlmAccount
();
bobAccount
=
new
OlmAccount
();
}
catch
(
OlmException
e
)
{
fail
(
e
.
getMessage
());
}
// test accounts creation
assertTrue
(
0
!=
bobAccount
.
getOlmAccountId
());
assertTrue
(
0
!=
aliceAccount
.
getOlmAccountId
());
// CREATE ALICE SESSION
OlmSession
aliceSession
=
null
;
try
{
aliceSession
=
new
OlmSession
();
}
catch
(
OlmException
e
)
{
fail
(
"Exception Msg="
+
e
.
getMessage
());
}
assertTrue
(
0
!=
aliceSession
.
getOlmSessionId
());
// CREATE ALICE SESSION
OlmSession
bobSession
=
null
;
try
{
bobSession
=
new
OlmSession
();
}
catch
(
OlmException
e
)
{
e
.
printStackTrace
();
fail
(
e
.
getMessage
());
}
assertTrue
(
0
!=
bobSession
.
getOlmSessionId
());
String
aliceSessionDescribe
=
null
;
try
{
aliceSessionDescribe
=
aliceSession
.
sessionDescribe
();
}
catch
(
Exception
e
)
{
fail
(
e
.
getMessage
());
}
assertNotNull
(
aliceSessionDescribe
);
String
bobSessionDescribe
=
null
;
try
{
bobSessionDescribe
=
bobSession
.
sessionDescribe
();
}
catch
(
Exception
e
)
{
fail
(
e
.
getMessage
());
}
assertNotNull
(
bobSessionDescribe
);
// must be the same for both ends of the conversation
assertEquals
(
aliceSessionDescribe
,
bobSessionDescribe
);
assertEquals
(
"sender chain index: 0 receiver chain indices: skipped message keys:"
,
aliceSessionDescribe
);
aliceAccount
.
releaseAccount
();
bobAccount
.
releaseAccount
();
assertTrue
(
aliceAccount
.
isReleased
());
assertTrue
(
bobAccount
.
isReleased
());
bobSession
.
releaseSession
();
aliceSession
.
releaseSession
();
assertTrue
(
bobSession
.
isReleased
());
assertTrue
(
aliceSession
.
isReleased
());
}
}
android/olm-sdk/src/main/java/org/matrix/olm/OlmException.java
View file @
dcf5582f
...
...
@@ -60,6 +60,7 @@ public class OlmException extends IOException {
public
static
final
int
EXCEPTION_CODE_SESSION_ENCRYPT_MESSAGE
=
404
;
public
static
final
int
EXCEPTION_CODE_SESSION_DECRYPT_MESSAGE
=
405
;
public
static
final
int
EXCEPTION_CODE_SESSION_SESSION_IDENTIFIER
=
406
;
public
static
final
int
EXCEPTION_CODE_SESSION_SESSION_DESCRIBE
=
407
;
public
static
final
int
EXCEPTION_CODE_UTILITY_CREATION
=
500
;
public
static
final
int
EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE
=
501
;
...
...
android/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
View file @
dcf5582f
...
...
@@ -223,6 +223,23 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
*/
private
native
byte
[]
getSessionIdentifierJni
();
public
String
sessionDescribe
()
throws
OlmException
{
try
{
byte
[]
buffer
=
olmSessionDescribeJni
();
if
(
null
!=
buffer
)
{
return
new
String
(
buffer
,
"UTF-8"
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionDescribe(): "
+
e
.
getMessage
());
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_SESSION_SESSION_DESCRIBE
,
e
.
getMessage
());
}
return
null
;
}
private
native
byte
[]
olmSessionDescribeJni
();
/**
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br>
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
...
...
android/olm-sdk/src/main/jni/olm_session.cpp
View file @
dcf5582f
...
...
@@ -798,6 +798,58 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env,
return
returnValue
;
}
JNIEXPORT
jbyteArray
OLM_SESSION_FUNC_DEF
(
olmSessionDescribeJni
(
JNIEnv
*
env
,
jobject
thiz
))
{
const
char
*
errorMessage
=
NULL
;
jbyteArray
returnValue
=
0
;
LOGD
(
"## olmSessionDescribeJni(): IN "
);
OlmSession
*
sessionPtr
=
getSessionInstanceId
(
env
,
thiz
);
if
(
!
sessionPtr
)
{
LOGE
(
"## olmSessionDescribeJni(): failure - invalid Session ptr=NULL"
);
errorMessage
=
"invalid Session ptr=NULL"
;
}
else
{
int
maxLength
=
600
;
char
*
describePtr
=
NULL
;
describePtr
=
(
char
*
)
malloc
(
maxLength
*
sizeof
*
describePtr
);
if
(
!
describePtr
)
{
LOGE
(
"## olmSessionDescribeJni(): failure - describe allocation OOM"
);
errorMessage
=
"describe allocation OOM"
;
}
else
{
olm_session_describe
(
sessionPtr
,
describePtr
,
maxLength
);
int
length
=
strlen
(
describePtr
);
if
(
length
==
0
)
{
LOGE
(
"## olmSessionDescribeJni(): failure - get session describe"
);
}
else
{
LOGD
(
"## olmSessionDescribeJni(): success - describe=%.*s"
,
(
char
*
)
describePtr
);
returnValue
=
env
->
NewByteArray
(
length
);
env
->
SetByteArrayRegion
(
returnValue
,
0
,
length
,
(
jbyte
*
)
describePtr
);
}
free
(
describePtr
);
}
}
if
(
errorMessage
)
{
env
->
ThrowNew
(
env
->
FindClass
(
"java/lang/Exception"
),
errorMessage
);
}
return
returnValue
;
}
/**
* Serialize and encrypt session instance.<br>
* An exception is thrown if the operation fails.
...
...
android/olm-sdk/src/main/jni/olm_session.h
View file @
dcf5582f
...
...
@@ -47,6 +47,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobjec
JNIEXPORT
jbyteArray
OLM_SESSION_FUNC_DEF
(
decryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jobject
aEncryptedMsg
);
JNIEXPORT
jbyteArray
OLM_SESSION_FUNC_DEF
(
getSessionIdentifierJni
)(
JNIEnv
*
env
,
jobject
thiz
);
JNIEXPORT
jbyteArray
OLM_SESSION_FUNC_DEF
(
olmSessionDescribeJni
)(
JNIEnv
*
env
,
jobject
thiz
);
// serialization
JNIEXPORT
jbyteArray
OLM_SESSION_FUNC_DEF
(
serializeJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aKey
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment