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
de962ef8
Commit
de962ef8
authored
Jan 03, 2017
by
ylecollen
Browse files
encryptMessage : the UTF8 conversion is done on JAVA side.
parent
e7c7d77a
Changes
3
Hide whitespace changes
Inline
Side-by-side
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
View file @
de962ef8
...
...
@@ -235,12 +235,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
String
retValue
=
null
;
if
(!
TextUtils
.
isEmpty
(
aClearMsg
))
{
retValue
=
encryptMessageJni
(
aClearMsg
);
try
{
retValue
=
encryptMessageJni
(
aClearMsg
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## encryptMessage() failed "
+
e
.
getMessage
());
}
}
return
retValue
;
}
private
native
String
encryptMessageJni
(
String
aClearMsg
);
private
native
String
encryptMessageJni
(
byte
[]
aClearMsg
Buffer
);
/**
* Return true the object resources have been released.<br>
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
View file @
de962ef8
...
...
@@ -262,30 +262,30 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
}
JNIEXPORT
jstring
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
encryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
string
aClearMsg
)
JNIEXPORT
jstring
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
encryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
byteArray
aClearMsg
Buffer
)
{
LOGD
(
"## encryptMessageJni(): IN"
);
jstring
encryptedMsgRetValue
=
0
;
OlmOutboundGroupSession
*
sessionPtr
=
NULL
;
const
char
*
clearMsgPtr
=
NULL
;
jbyte
*
clearMsgPtr
=
NULL
;
if
(
!
(
sessionPtr
=
(
OlmOutboundGroupSession
*
)
getOutboundGroupSessionInstanceId
(
env
,
thiz
)))
{
LOGE
(
" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL"
);
}
else
if
(
!
aClearMsg
)
else
if
(
!
aClearMsg
Buffer
)
{
LOGE
(
" ## encryptMessageJni(): failure - invalid clear message"
);
}
else
if
(
!
(
clearMsgPtr
=
env
->
Get
StringUTFChars
(
aClearMsg
,
0
)))
else
if
(
!
(
clearMsgPtr
=
env
->
Get
ByteArrayElements
(
aClearMsgBuffer
,
NULL
)))
{
LOGE
(
" ## encryptMessageJni(): failure - clear message JNI allocation OOM"
);
}
else
{
// get clear message length
size_t
clearMsgLength
=
(
size_t
)
env
->
Get
StringUTF
Length
(
aClearMsg
);
size_t
clearMsgLength
=
(
size_t
)
env
->
Get
Array
Length
(
aClearMsg
Buffer
);
LOGD
(
" ## encryptMessageJni(): clearMsgLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
clearMsgLength
));
// compute max encrypted length
...
...
@@ -325,7 +325,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
// free alloc
if
(
clearMsgPtr
)
{
env
->
Release
StringUTFChar
s
(
aClearMsg
,
clearMsgPtr
);
env
->
Release
ByteArrayElement
s
(
aClearMsg
Buffer
,
clearMsgPtr
,
JNI_ABORT
);
}
return
encryptedMsgRetValue
;
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
View file @
de962ef8
...
...
@@ -37,7 +37,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
JNIEXPORT
jint
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
messageIndexJni
)(
JNIEnv
*
env
,
jobject
thiz
);
JNIEXPORT
jstring
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
sessionKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
);
JNIEXPORT
jstring
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
encryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
string
aClearMsg
Pt
r
);
JNIEXPORT
jstring
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
encryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
byteArray
aClearMsg
Buffe
r
);
// serialization
JNIEXPORT
jstring
OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF
(
serializeDataWithKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jstring
aKey
,
jobject
aErrorMsg
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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