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
9552e14f
Commit
9552e14f
authored
Jan 03, 2017
by
ylecollen
Browse files
-> the byte[] to String conversions are done on Java level (when it is possible)
-> remove javaCStringToUtf8
parent
765647cd
Changes
17
Show whitespace changes
Inline
Side-by-side
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
View file @
9552e14f
...
@@ -118,7 +118,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
...
@@ -118,7 +118,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
try
{
try
{
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
);
pickleRetValue
=
new
String
(
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
)
,
"UTF-8"
)
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey() failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey() failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
...
@@ -127,7 +127,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
...
@@ -127,7 +127,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
return
pickleRetValue
;
return
pickleRetValue
;
}
}
private
native
String
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
private
native
byte
[]
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
/**
/**
...
@@ -164,6 +164,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
...
@@ -164,6 +164,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
return
retCode
;
return
retCode
;
}
}
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedDataBuffer
,
byte
[]
aKeyBuffer
);
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedDataBuffer
,
byte
[]
aKeyBuffer
);
/**
/**
...
@@ -363,25 +364,34 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
...
@@ -363,25 +364,34 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
* @return the signed message if operation succeed, null otherwise
* @return the signed message if operation succeed, null otherwise
*/
*/
public
String
signMessage
(
String
aMessage
)
{
public
String
signMessage
(
String
aMessage
)
{
if
(
null
==
aMessage
)
{
String
result
=
null
;
return
null
;
}
if
(
null
!=
aMessage
)
{
byte
[]
utf8String
=
null
;
byte
[]
utf8String
=
null
;
try
{
try
{
utf8String
=
aMessage
.
getBytes
(
"UTF-8"
);
utf8String
=
aMessage
.
getBytes
(
"UTF-8"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
d
(
LOG_TAG
,
"## signMessage(): failed ="
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## signMessage(): failed ="
+
e
.
getMessage
());
}
}
if
(
null
==
utf8String
)
{
if
(
null
!=
utf8String
)
{
return
null
;
byte
[]
signedMessage
=
signMessageJni
(
utf8String
);
if
(
null
!=
signedMessage
)
{
try
{
result
=
new
String
(
signedMessage
,
"UTF-8"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## signMessage(): failed ="
+
e
.
getMessage
());
}
}
}
}
}
return
signMessageJni
(
utf8String
)
;
return
result
;
}
}
private
native
String
signMessageJni
(
byte
[]
aMessage
);
private
native
byte
[]
signMessageJni
(
byte
[]
aMessage
);
/**
/**
* Return true the object resources have been released.<br>
* Return true the object resources have been released.<br>
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
View file @
9552e14f
...
@@ -144,10 +144,16 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -144,10 +144,16 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @return the session ID if operation succeed, null otherwise
* @return the session ID if operation succeed, null otherwise
*/
*/
public
String
sessionIdentifier
()
{
public
String
sessionIdentifier
()
{
return
sessionIdentifierJni
();
try
{
return
new
String
(
sessionIdentifierJni
(),
"UTF-8"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionIdentifier() failed "
+
e
.
getMessage
());
}
return
null
;
}
}
private
native
String
sessionIdentifierJni
();
private
native
byte
[]
sessionIdentifierJni
();
/**
/**
* Decrypt the message passed in parameter.<br>
* Decrypt the message passed in parameter.<br>
...
@@ -161,9 +167,14 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -161,9 +167,14 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
StringBuffer
errorMsg
=
new
StringBuffer
();
StringBuffer
errorMsg
=
new
StringBuffer
();
try
{
try
{
result
.
mDecryptedMessage
=
decryptMessageJni
(
aEncryptedMsg
.
getBytes
(
"UTF-8"
),
result
,
errorMsg
);
byte
[]
decryptedMessageBuffer
=
decryptMessageJni
(
aEncryptedMsg
.
getBytes
(
"UTF-8"
),
result
,
errorMsg
);
if
(
null
!=
decryptedMessageBuffer
)
{
result
.
mDecryptedMessage
=
new
String
(
decryptedMessageBuffer
,
"UTF-8"
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## decryptMessage() failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## decryptMessage() failed "
+
e
.
getMessage
());
errorMsg
.
append
(
e
.
getMessage
());
}
}
// check if there is an error while decrypting
// check if there is an error while decrypting
...
@@ -174,7 +185,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -174,7 +185,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
return
result
;
return
result
;
}
}
private
native
String
decryptMessageJni
(
byte
[]
aEncryptedMsg
,
DecryptMessageResult
aDecryptMessageResult
,
StringBuffer
aErrorMsg
);
private
native
byte
[]
decryptMessageJni
(
byte
[]
aEncryptedMsg
,
DecryptMessageResult
aDecryptMessageResult
,
StringBuffer
aErrorMsg
);
/**
/**
* Kick off the serialization mechanism.
* Kick off the serialization mechanism.
...
@@ -226,9 +237,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -226,9 +237,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
try
{
try
{
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
);
pickleRetValue
=
new
String
(
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
)
,
"UTF-8"
)
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey() failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey() failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
}
...
@@ -240,7 +252,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -240,7 +252,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @param aErrorMsg error message description
* @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise
* @return pickled base64 string if operation succeed, null otherwise
*/
*/
private
native
String
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
private
native
byte
[]
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
/**
/**
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
View file @
9552e14f
...
@@ -208,10 +208,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -208,10 +208,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return session identifier if operation succeed, null otherwise.
* @return session identifier if operation succeed, null otherwise.
*/
*/
public
String
sessionIdentifier
()
{
public
String
sessionIdentifier
()
{
return
sessionIdentifierJni
();
try
{
return
new
String
(
sessionIdentifierJni
(),
"UTF-8"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionIdentifier() failed "
+
e
.
getMessage
());
}
}
private
native
String
sessionIdentifierJni
();
return
null
;
}
private
native
byte
[]
sessionIdentifierJni
();
/**
/**
* Get the current message index for this session.<br>
* Get the current message index for this session.<br>
...
@@ -231,9 +237,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -231,9 +237,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
* @return outbound session key
* @return outbound session key
*/
*/
public
String
sessionKey
()
{
public
String
sessionKey
()
{
return
sessionKeyJni
();
try
{
return
new
String
(
sessionKeyJni
(),
"UTF-8"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionKey() failed "
+
e
.
getMessage
());
}
return
null
;
}
}
private
native
String
sessionKeyJni
();
private
native
byte
[]
sessionKeyJni
();
/**
/**
* Encrypt some plain-text message.<br>
* Encrypt some plain-text message.<br>
...
@@ -246,7 +259,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -246,7 +259,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
if
(!
TextUtils
.
isEmpty
(
aClearMsg
))
{
if
(!
TextUtils
.
isEmpty
(
aClearMsg
))
{
try
{
try
{
retValue
=
encryptMessageJni
(
aClearMsg
.
getBytes
(
"UTF-8"
));
retValue
=
new
String
(
encryptMessageJni
(
aClearMsg
.
getBytes
(
"UTF-8"
))
,
"UTF-8"
)
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## encryptMessage() failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## encryptMessage() failed "
+
e
.
getMessage
());
}
}
...
@@ -254,7 +267,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -254,7 +267,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return
retValue
;
return
retValue
;
}
}
private
native
String
encryptMessageJni
(
byte
[]
aClearMsgBuffer
);
private
native
byte
[]
encryptMessageJni
(
byte
[]
aClearMsgBuffer
);
/**
/**
* Return true the object resources have been released.<br>
* Return true the object resources have been released.<br>
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
View file @
9552e14f
...
@@ -302,10 +302,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -302,10 +302,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @return the session ID as a String if operation succeed, null otherwise
* @return the session ID as a String if operation succeed, null otherwise
*/
*/
public
String
sessionIdentifier
()
{
public
String
sessionIdentifier
()
{
return
getSessionIdentifierJni
();
try
{
return
new
String
(
getSessionIdentifierJni
(),
"UTF-8"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionIdentifier(): "
+
e
.
getMessage
());
}
return
null
;
}
}
private
native
String
getSessionIdentifierJni
();
private
native
byte
[]
getSessionIdentifierJni
();
/**
/**
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br>
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br>
...
@@ -383,10 +389,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -383,10 +389,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
* @return the decrypted message if operation succeed, null otherwise
* @return the decrypted message if operation succeed, null otherwise
*/
*/
public
String
decryptMessage
(
OlmMessage
aEncryptedMsg
)
{
public
String
decryptMessage
(
OlmMessage
aEncryptedMsg
)
{
return
decryptMessageJni
(
aEncryptedMsg
);
try
{
return
new
String
(
decryptMessageJni
(
aEncryptedMsg
),
"UTF-8"
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## decryptMessage(): failed "
+
e
.
getMessage
());
}
return
null
;
}
}
private
native
String
decryptMessageJni
(
OlmMessage
aEncryptedMsg
);
private
native
byte
[]
decryptMessageJni
(
OlmMessage
aEncryptedMsg
);
/**
/**
* Return true the object resources have been released.<br>
* Return true the object resources have been released.<br>
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
View file @
9552e14f
...
@@ -121,7 +121,7 @@ public class OlmUtility {
...
@@ -121,7 +121,7 @@ public class OlmUtility {
if
(
null
!=
aMessageToHash
)
{
if
(
null
!=
aMessageToHash
)
{
try
{
try
{
hashRetValue
=
sha256Jni
(
aMessageToHash
.
getBytes
(
"UTF-8"
));
hashRetValue
=
new
String
(
sha256Jni
(
aMessageToHash
.
getBytes
(
"UTF-8"
))
,
"UTF-8"
)
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sha256(): failed "
+
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
"## sha256(): failed "
+
e
.
getMessage
());
}
}
...
@@ -130,7 +130,7 @@ public class OlmUtility {
...
@@ -130,7 +130,7 @@ public class OlmUtility {
return
hashRetValue
;
return
hashRetValue
;
}
}
private
native
String
sha256Jni
(
byte
[]
aMessage
);
private
native
byte
[]
sha256Jni
(
byte
[]
aMessage
);
/**
/**
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
View file @
9552e14f
...
@@ -405,10 +405,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
...
@@ -405,10 +405,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
* @param aMessage message to sign
* @param aMessage message to sign
* @return the signed message, null otherwise
* @return the signed message, null otherwise
**/
**/
JNIEXPORT
j
string
OLM_ACCOUNT_FUNC_DEF
(
signMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aMessage
)
JNIEXPORT
j
byteArray
OLM_ACCOUNT_FUNC_DEF
(
signMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aMessage
)
{
{
OlmAccount
*
accountPtr
=
NULL
;
OlmAccount
*
accountPtr
=
NULL
;
j
string
signedMsgRetValue
=
NULL
;
j
byteArray
signedMsgRetValue
Buffer
=
NULL
;
if
(
!
aMessage
)
if
(
!
aMessage
)
{
{
...
@@ -425,7 +425,8 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
...
@@ -425,7 +425,8 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
// signature memory allocation
// signature memory allocation
size_t
signatureLength
=
olm_account_signature_length
(
accountPtr
);
size_t
signatureLength
=
olm_account_signature_length
(
accountPtr
);
void
*
signedMsgPtr
=
malloc
((
signatureLength
+
1
)
*
sizeof
(
uint8_t
));
size_t
bufferLen
=
signatureLength
+
1
;
void
*
signedMsgPtr
=
malloc
(
bufferLen
*
sizeof
(
uint8_t
));
if
(
!
signedMsgPtr
)
if
(
!
signedMsgPtr
)
{
{
...
@@ -448,9 +449,12 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
...
@@ -448,9 +449,12 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
{
{
// info: signatureLength is always equal to resultSign
// info: signatureLength is always equal to resultSign
(
static_cast
<
char
*>
(
signedMsgPtr
))[
signatureLength
]
=
static_cast
<
char
>
(
'\0'
);
(
static_cast
<
char
*>
(
signedMsgPtr
))[
signatureLength
]
=
static_cast
<
char
>
(
'\0'
);
// convert to jstring
signedMsgRetValue
=
env
->
NewStringUTF
((
const
char
*
)
signedMsgPtr
);
// UTF8
LOGD
(
"## signMessageJni(): success - retCode=%lu signatureLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
resultSign
),
static_cast
<
long
unsigned
int
>
(
signatureLength
));
LOGD
(
"## signMessageJni(): success - retCode=%lu signatureLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
resultSign
),
static_cast
<
long
unsigned
int
>
(
signatureLength
));
signedMsgRetValueBuffer
=
env
->
NewByteArray
(
signatureLength
);
env
->
SetByteArrayRegion
(
signedMsgRetValueBuffer
,
0
,
signatureLength
,
(
jbyte
*
)
signedMsgPtr
);
}
}
free
(
signedMsgPtr
);
free
(
signedMsgPtr
);
...
@@ -463,7 +467,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
...
@@ -463,7 +467,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
}
}
}
}
return
signedMsgRetValue
;
return
signedMsgRetValue
Buffer
;
}
}
/**
/**
...
@@ -472,9 +476,9 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
...
@@ -472,9 +476,9 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
* @param[out] aErrorMsg error message set if operation failed
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
* @return a base64 string if operation succeed, null otherwise
**/
**/
JNIEXPORT
j
string
OLM_ACCOUNT_FUNC_DEF
(
serializeDataWithKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aKeyBuffer
,
jobject
aErrorMsg
)
JNIEXPORT
j
byteArray
OLM_ACCOUNT_FUNC_DEF
(
serializeDataWithKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aKeyBuffer
,
jobject
aErrorMsg
)
{
{
j
string
pickledDataRetValue
=
0
;
j
byteArray
pickledDataRetValue
=
0
;
jclass
errorMsgJClass
=
0
;
jclass
errorMsgJClass
=
0
;
jmethodID
errorMsgMethodId
=
0
;
jmethodID
errorMsgMethodId
=
0
;
jstring
errorJstring
=
0
;
jstring
errorJstring
=
0
;
...
@@ -541,8 +545,11 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
...
@@ -541,8 +545,11 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
{
{
// build success output
// build success output
(
static_cast
<
char
*>
(
pickledPtr
))[
pickledLength
]
=
static_cast
<
char
>
(
'\0'
);
(
static_cast
<
char
*>
(
pickledPtr
))[
pickledLength
]
=
static_cast
<
char
>
(
'\0'
);
pickledDataRetValue
=
env
->
NewStringUTF
((
const
char
*
)
pickledPtr
);
LOGD
(
" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s"
,
static_cast
<
long
unsigned
int
>
(
result
),
static_cast
<
char
*>
(
pickledPtr
));
LOGD
(
" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s"
,
static_cast
<
long
unsigned
int
>
(
result
),
static_cast
<
char
*>
(
pickledPtr
));
pickledDataRetValue
=
env
->
NewByteArray
(
pickledLength
+
1
);
env
->
SetByteArrayRegion
(
pickledDataRetValue
,
0
,
pickledLength
+
1
,
(
jbyte
*
)
pickledPtr
);
}
}
free
(
pickledPtr
);
free
(
pickledPtr
);
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.h
View file @
9552e14f
...
@@ -44,10 +44,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysForSessionJni)(JNIEnv *env,
...
@@ -44,10 +44,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysForSessionJni)(JNIEnv *env,
JNIEXPORT
jint
OLM_ACCOUNT_FUNC_DEF
(
markOneTimeKeysAsPublishedJni
)(
JNIEnv
*
env
,
jobject
thiz
);
JNIEXPORT
jint
OLM_ACCOUNT_FUNC_DEF
(
markOneTimeKeysAsPublishedJni
)(
JNIEnv
*
env
,
jobject
thiz
);
// signing
// signing
JNIEXPORT
j
string
OLM_ACCOUNT_FUNC_DEF
(
signMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aMessage
);
JNIEXPORT
j
byteArray
OLM_ACCOUNT_FUNC_DEF
(
signMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aMessage
);
// serialization
// serialization
JNIEXPORT
j
string
OLM_ACCOUNT_FUNC_DEF
(
serializeDataWithKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aKeyBuffer
,
jobject
aErrorMsg
);
JNIEXPORT
j
byteArray
OLM_ACCOUNT_FUNC_DEF
(
serializeDataWithKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aKeyBuffer
,
jobject
aErrorMsg
);
JNIEXPORT
jstring
OLM_ACCOUNT_FUNC_DEF
(
initWithSerializedDataJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aSerializedDataBuffer
,
jbyteArray
aKeyBuffer
);
JNIEXPORT
jstring
OLM_ACCOUNT_FUNC_DEF
(
initWithSerializedDataJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aSerializedDataBuffer
,
jbyteArray
aKeyBuffer
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
View file @
9552e14f
...
@@ -137,10 +137,10 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
...
@@ -137,10 +137,10 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
/**
/**
* Get a base64-encoded identifier for this inbound group session.
* Get a base64-encoded identifier for this inbound group session.
*/
*/
JNIEXPORT
j
string
OLM_INBOUND_GROUP_SESSION_FUNC_DEF
(
sessionIdentifierJni
)(
JNIEnv
*
env
,
jobject
thiz
)
JNIEXPORT
j
byteArray
OLM_INBOUND_GROUP_SESSION_FUNC_DEF
(
sessionIdentifierJni
)(
JNIEnv
*
env
,
jobject
thiz
)
{
{
OlmInboundGroupSession
*
sessionPtr
=
NULL
;
OlmInboundGroupSession
*
sessionPtr
=
NULL
;
j
string
returnValue
Str
=
0
;
j
byteArray
returnValue
=
0
;
LOGD
(
"## sessionIdentifierJni(): inbound group session IN"
);
LOGD
(
"## sessionIdentifierJni(): inbound group session IN"
);
...
@@ -170,22 +170,26 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
...
@@ -170,22 +170,26 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
}
}
else
else
{
{
// update length
sessionIdPtr
[
result
]
=
static_cast
<
char
>
(
'\0'
);
sessionIdPtr
[
result
]
=
static_cast
<
char
>
(
'\0'
);
LOGD
(
" ## sessionIdentifierJni(): success - inbound group session result=%lu sessionId=%s"
,
static_cast
<
long
unsigned
int
>
(
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
);
returnValue
=
env
->
NewByteArray
(
result
);
env
->
SetByteArrayRegion
(
returnValue
,
0
,
result
,
(
jbyte
*
)
sessionIdPtr
);
}
}
free
(
sessionIdPtr
);
free
(
sessionIdPtr
);
}
}
}
}
return
returnValue
Str
;
return
returnValue
;
}
}
JNIEXPORT
j
string
OLM_INBOUND_GROUP_SESSION_FUNC_DEF
(
decryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aEncryptedMsgBuffer
,
jobject
aDecryptionResult
,
jobject
aErrorMsg
)
JNIEXPORT
j
byteArray
OLM_INBOUND_GROUP_SESSION_FUNC_DEF
(
decryptMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aEncryptedMsgBuffer
,
jobject
aDecryptionResult
,
jobject
aErrorMsg
)
{
{
jstring
decryptedMsgRetValue
=
0
;
jbyteArray
decryptedMsgBuffer
=
0
;
OlmInboundGroupSession
*
sessionPtr
=
NULL
;
OlmInboundGroupSession
*
sessionPtr
=
NULL
;
jbyte
*
encryptedMsgPtr
=
NULL
;
jbyte
*
encryptedMsgPtr
=
NULL
;
jclass
indexObjJClass
=
0
;
jclass
indexObjJClass
=
0
;
...
@@ -298,18 +302,11 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
...
@@ -298,18 +302,11 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
// update index
// update index
env
->
SetLongField
(
aDecryptionResult
,
indexMsgFieldId
,
(
jlong
)
messageIndex
);
env
->
SetLongField
(
aDecryptionResult
,
indexMsgFieldId
,
(
jlong
)
messageIndex
);
// convert to utf8
decryptedMsgBuffer
=
env
->
NewByteArray
(
plaintextLength
);
decryptedMsgRetValue
=
javaCStringToUtf8
(
env
,
plain
T
ext
MsgPtr
,
plain
t
ext
Length
);
env
->
SetByteArrayRegion
(
decryptedMsgBuffer
,
0
,
plain
t
ext
Length
,
(
jbyte
*
)
plain
T
ext
MsgPtr
);
if
(
!
decryptedMsgRetValue
)
{
LOGE
(
" ## decryptMessageJni(): UTF-8 Conversion failure - javaCStringToUtf8() returns null"
);
}
else
{
LOGD
(
" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK"
,
static_cast
<
long
unsigned
int
>
(
plaintextLength
));
LOGD
(
" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK"
,
static_cast
<
long
unsigned
int
>
(
plaintextLength
));
}
}
}
if
(
plainTextMsgPtr
)
if
(
plainTextMsgPtr
)
{
{
...
@@ -330,7 +327,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
...
@@ -330,7 +327,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
env
->
ReleaseByteArrayElements
(
aEncryptedMsgBuffer
,
encryptedMsgPtr
,
JNI_ABORT
);
env
->
ReleaseByteArrayElements
(
aEncryptedMsgBuffer
,
encryptedMsgPtr
,
JNI_ABORT
);
}
}
return
decryptedMsg
RetValue
;
return
decryptedMsg
Buffer
;
}
}
...
@@ -340,9 +337,10 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
...
@@ -340,9 +337,10 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
* @param[out] aErrorMsg error message set if operation failed
* @param[out] aErrorMsg error message set if operation failed