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
765647cd
Commit
765647cd
authored
Jan 03, 2017
by
ylecollen
Browse files
There is more GetStringUTFChars call.
parent
de962ef8
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
View file @
765647cd
...
@@ -117,12 +117,17 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
...
@@ -117,12 +117,17 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
,
aErrorMsg
);
try
{
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey() failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
return
pickleRetValue
;
return
pickleRetValue
;
}
}
private
native
String
serializeDataWithKeyJni
(
String
aKey
,
StringBuffer
aErrorMsg
);
private
native
String
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
/**
/**
...
@@ -138,23 +143,28 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
...
@@ -138,23 +143,28 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
boolean
retCode
=
false
;
boolean
retCode
=
false
;
String
jniError
;
String
jniError
;
if
(
null
==
aErrorMsg
)
{
if
(
null
==
aErrorMsg
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input error parameter"
);
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input error parameter"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
try
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
retCode
=
true
;
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
}
else
{
retCode
=
true
;
aErrorMsg
.
append
(
jniError
);
}
else
{
aErrorMsg
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData() failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
}
return
retCode
;
return
retCode
;
}
}
private
native
String
initWithSerializedDataJni
(
String
aSerializedData
,
String
aKey
);
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedData
Buffer
,
byte
[]
aKeyBuffer
);
/**
/**
* Getter on the account ID.
* Getter on the account ID.
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
View file @
765647cd
...
@@ -127,12 +127,16 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -127,12 +127,16 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
if
(
TextUtils
.
isEmpty
(
aSessionKey
)){
if
(
TextUtils
.
isEmpty
(
aSessionKey
)){
Log
.
e
(
LOG_TAG
,
"## initInboundGroupSessionWithSessionKey(): invalid session key"
);
Log
.
e
(
LOG_TAG
,
"## initInboundGroupSessionWithSessionKey(): invalid session key"
);
}
else
{
}
else
{
retCode
=
initInboundGroupSessionWithSessionKeyJni
(
aSessionKey
);
try
{
retCode
=
initInboundGroupSessionWithSessionKeyJni
(
aSessionKey
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initInboundGroupSessionWithSessionKey() failed "
+
e
.
getMessage
());
}
}
}
return
retCode
;
return
retCode
;
}
}
private
native
int
initInboundGroupSessionWithSessionKeyJni
(
String
aSessionKey
);
private
native
int
initInboundGroupSessionWithSessionKeyJni
(
byte
[]
aSessionKey
Buffer
);
/**
/**
...
@@ -156,7 +160,11 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -156,7 +160,11 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
DecryptMessageResult
result
=
new
DecryptMessageResult
();
DecryptMessageResult
result
=
new
DecryptMessageResult
();
StringBuffer
errorMsg
=
new
StringBuffer
();
StringBuffer
errorMsg
=
new
StringBuffer
();
result
.
mDecryptedMessage
=
decryptMessageJni
(
aEncryptedMsg
,
result
,
errorMsg
);
try
{
result
.
mDecryptedMessage
=
decryptMessageJni
(
aEncryptedMsg
.
getBytes
(
"UTF-8"
),
result
,
errorMsg
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## decryptMessage() failed "
+
e
.
getMessage
());
}
// check if there is an error while decrypting
// check if there is an error while decrypting
if
(
0
!=
errorMsg
.
length
())
{
if
(
0
!=
errorMsg
.
length
())
{
...
@@ -166,7 +174,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -166,7 +174,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
return
result
;
return
result
;
}
}
private
native
String
decryptMessageJni
(
String
aEncryptedMsg
,
DecryptMessageResult
aDecryptMessageResult
,
StringBuffer
aErrorMsg
);
private
native
String
decryptMessageJni
(
byte
[]
aEncryptedMsg
,
DecryptMessageResult
aDecryptMessageResult
,
StringBuffer
aErrorMsg
);
/**
/**
* Kick off the serialization mechanism.
* Kick off the serialization mechanism.
...
@@ -217,7 +225,11 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -217,7 +225,11 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
,
aErrorMsg
);
try
{
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey() failed "
+
e
.
getMessage
());
}
}
}
return
pickleRetValue
;
return
pickleRetValue
;
...
@@ -228,7 +240,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -228,7 +240,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
(
String
aKey
,
StringBuffer
aErrorMsg
);
private
native
String
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
/**
/**
...
@@ -248,13 +260,17 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -248,13 +260,17 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input error parameter"
);
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input error parameter"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
try
{
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
retCode
=
true
;
retCode
=
true
;
}
else
{
}
else
{
aErrorMsg
.
append
(
jniError
);
aErrorMsg
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData() failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
}
...
@@ -266,7 +282,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
...
@@ -266,7 +282,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @param aKey key used to encrypted in {@link #serializeDataWithKey(String, StringBuffer)}
* @param aKey key used to encrypted in {@link #serializeDataWithKey(String, StringBuffer)}
* @return null if operation succeed, an error message if operation failed
* @return null if operation succeed, an error message if operation failed
*/
*/
private
native
String
initWithSerializedDataJni
(
String
aSerializedData
,
String
aKey
);
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedData
,
byte
[]
aKey
);
/**
/**
* 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/OlmOutboundGroupSession.java
View file @
765647cd
...
@@ -109,12 +109,17 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -109,12 +109,17 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
,
aErrorMsg
);
try
{
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey(): failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
return
pickleRetValue
;
return
pickleRetValue
;
}
}
private
native
String
serializeDataWithKeyJni
(
String
aKey
,
StringBuffer
aErrorMsg
);
private
native
String
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
/**
/**
...
@@ -135,18 +140,23 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
...
@@ -135,18 +140,23 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
try
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
retCode
=
true
;
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
}
else
{
retCode
=
true
;
aErrorMsg
.
append
(
jniError
);
}
else
{
aErrorMsg
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
}
return
retCode
;
return
retCode
;
}
}
private
native
String
initWithSerializedDataJni
(
String
aSerializedData
,
String
aKey
);
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedData
,
byte
[]
aKey
);
/**
/**
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
View file @
765647cd
...
@@ -97,12 +97,17 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -97,12 +97,17 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
,
aErrorMsg
);
try
{
pickleRetValue
=
serializeDataWithKeyJni
(
aKey
.
getBytes
(
"UTF-8"
),
aErrorMsg
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## serializeDataWithKey(): failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
return
pickleRetValue
;
return
pickleRetValue
;
}
}
private
native
String
serializeDataWithKeyJni
(
String
aKey
,
StringBuffer
aErrorMsg
);
private
native
String
serializeDataWithKeyJni
(
byte
[]
aKey
,
StringBuffer
aErrorMsg
);
/**
/**
...
@@ -123,18 +128,23 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -123,18 +128,23 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
}
else
{
}
else
{
aErrorMsg
.
setLength
(
0
);
aErrorMsg
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
try
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
retCode
=
true
;
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
}
else
{
retCode
=
true
;
aErrorMsg
.
append
(
jniError
);
}
else
{
aErrorMsg
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
}
}
return
retCode
;
return
retCode
;
}
}
private
native
String
initWithSerializedDataJni
(
String
aSerializedData
,
String
aKey
);
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedData
,
byte
[]
aKey
);
/**
/**
* Getter on the session ID.
* Getter on the session ID.
...
@@ -215,43 +225,50 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -215,43 +225,50 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aTheirIdentityKey
)
||
TextUtils
.
isEmpty
(
aTheirOneTimeKey
)){
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aTheirIdentityKey
)
||
TextUtils
.
isEmpty
(
aTheirOneTimeKey
)){
Log
.
e
(
LOG_TAG
,
"## initOutboundSession(): invalid input parameters"
);
Log
.
e
(
LOG_TAG
,
"## initOutboundSession(): invalid input parameters"
);
}
else
{
}
else
{
retCode
=
initOutboundSessionJni
(
aAccount
.
getOlmAccountId
(),
aTheirIdentityKey
,
aTheirOneTimeKey
);
try
{
retCode
=
initOutboundSessionJni
(
aAccount
.
getOlmAccountId
(),
aTheirIdentityKey
.
getBytes
(
"UTF-8"
),
aTheirOneTimeKey
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initOutboundSessionWithAccount(): "
+
e
.
getMessage
());
}
}
}
return
retCode
;
return
retCode
;
}
}
private
native
int
initOutboundSessionJni
(
long
aOlmAccountId
,
String
aTheirIdentityKey
,
String
aTheirOneTimeKey
);
private
native
int
initOutboundSessionJni
(
long
aOlmAccountId
,
byte
[]
aTheirIdentityKey
,
byte
[]
aTheirOneTimeKey
);
/**
/**
* Create a new in-bound session for sending/receiving messages from an
* Create a new in-bound session for sending/receiving messages from an
* incoming PRE_KEY message ({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}).<br>
* incoming PRE_KEY message ({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}).<br>
* Public API for {@link #initInboundSessionJni(long,
String
)}.
* Public API for {@link #initInboundSessionJni(long,
byte[]
)}.
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* @param aAccount the account to associate with this session
* @param aAccount the account to associate with this session
* @param aPreKeyMsg PRE KEY message
* @param aPreKeyMsg PRE KEY message
* @return 0 if operation succeed, -1 otherwise
* @return 0 if operation succeed, -1 otherwise
*/
*/
public
int
initInboundSessionWithAccount
(
OlmAccount
aAccount
,
String
aPreKeyMsg
)
{
public
int
initInboundSessionWithAccount
(
OlmAccount
aAccount
,
String
aPreKeyMsg
)
{
int
retCode
=
-
1
;
int
retCode
=
-
1
;
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aPreKeyMsg
)){
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aPreKeyMsg
)){
Log
.
e
(
LOG_TAG
,
"## initInboundSessionWithAccount(): invalid input parameters"
);
Log
.
e
(
LOG_TAG
,
"## initInboundSessionWithAccount(): invalid input parameters"
);
}
else
{
}
else
{
retCode
=
initInboundSessionJni
(
aAccount
.
getOlmAccountId
(),
aPreKeyMsg
);
try
{
retCode
=
initInboundSessionJni
(
aAccount
.
getOlmAccountId
(),
aPreKeyMsg
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initInboundSessionWithAccount(): "
+
e
.
getMessage
());
}
}
}
return
retCode
;
return
retCode
;
}
}
private
native
int
initInboundSessionJni
(
long
aOlmAccountId
,
String
aOneTimeKeyMsg
);
private
native
int
initInboundSessionJni
(
long
aOlmAccountId
,
byte
[]
aOneTimeKeyMsg
);
/**
/**
* Create a new in-bound session for sending/receiving messages from an
* Create a new in-bound session for sending/receiving messages from an
* incoming PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message based on the sender identity key.<br>
* incoming PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message based on the sender identity key.<br>
* Public API for {@link #initInboundSessionFromIdKeyJni(long,
String, String
)}.
* Public API for {@link #initInboundSessionFromIdKeyJni(long,
byte[], byte[]
)}.
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* This method must only be called the first time a pre-key message is received from an inbound session.
* This method must only be called the first time a pre-key message is received from an inbound session.
* @param aAccount the account to associate with this session
* @param aAccount the account to associate with this session
...
@@ -265,13 +282,17 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -265,13 +282,17 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aPreKeyMsg
)){
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aPreKeyMsg
)){
Log
.
e
(
LOG_TAG
,
"## initInboundSessionWithAccount(): invalid input parameters"
);
Log
.
e
(
LOG_TAG
,
"## initInboundSessionWithAccount(): invalid input parameters"
);
}
else
{
}
else
{
retCode
=
initInboundSessionFromIdKeyJni
(
aAccount
.
getOlmAccountId
(),
aTheirIdentityKey
,
aPreKeyMsg
);
try
{
retCode
=
initInboundSessionFromIdKeyJni
(
aAccount
.
getOlmAccountId
(),
aTheirIdentityKey
.
getBytes
(
"UTF-8"
),
aPreKeyMsg
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initInboundSessionWithAccountFrom(): "
+
e
.
getMessage
());
}
}
}
return
retCode
;
return
retCode
;
}
}
private
native
int
initInboundSessionFromIdKeyJni
(
long
aOlmAccountId
,
String
aTheirIdentityKey
,
String
aOneTimeKeyMsg
);
private
native
int
initInboundSessionFromIdKeyJni
(
long
aOlmAccountId
,
byte
[]
aTheirIdentityKey
,
byte
[]
aOneTimeKeyMsg
);
/**
/**
* Get the session identifier.<br> Will be the same for both ends of the
* Get the session identifier.<br> Will be the same for both ends of the
...
@@ -289,26 +310,29 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -289,26 +310,29 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
/**
/**
* 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>
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* Public API for {@link #matchesInboundSessionJni(
String
)}.
* Public API for {@link #matchesInboundSessionJni(
byte[]
)}.
* @param aOneTimeKeyMsg PRE KEY message
* @param aOneTimeKeyMsg PRE KEY message
* @return this if operation succeed, null otherwise
* @return this if operation succeed, null otherwise
*/
*/
public
boolean
matchesInboundSession
(
String
aOneTimeKeyMsg
)
{
public
boolean
matchesInboundSession
(
String
aOneTimeKeyMsg
)
{
boolean
retCode
=
false
;
boolean
retCode
=
false
;
if
(
0
==
matchesInboundSessionJni
(
aOneTimeKeyMsg
)){
try
{
retCode
=
true
;
retCode
=
(
0
==
matchesInboundSessionJni
(
aOneTimeKeyMsg
.
getBytes
(
"UTF-8"
)));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## matchesInboundSession(): failed "
+
e
.
getMessage
());
}
}
return
retCode
;
return
retCode
;
}
}
private
native
int
matchesInboundSessionJni
(
String
aOneTimeKeyMsg
);
private
native
int
matchesInboundSessionJni
(
byte
[]
aOneTimeKeyMsg
);
/**
/**
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session based on the sender identity key.<br>
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session based on the sender identity key.<br>
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* This API may be used to process a "m.room.encrypted" event when type = 1 (PRE_KEY).
* Public API for {@link #matchesInboundSessionJni(
String
)}.
* Public API for {@link #matchesInboundSessionJni(
byte[]
)}.
* @param aTheirIdentityKey the sender identity key
* @param aTheirIdentityKey the sender identity key
* @param aOneTimeKeyMsg PRE KEY message
* @param aOneTimeKeyMsg PRE KEY message
* @return this if operation succeed, null otherwise
* @return this if operation succeed, null otherwise
...
@@ -316,33 +340,41 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
...
@@ -316,33 +340,41 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
public
boolean
matchesInboundSessionFrom
(
String
aTheirIdentityKey
,
String
aOneTimeKeyMsg
)
{
public
boolean
matchesInboundSessionFrom
(
String
aTheirIdentityKey
,
String
aOneTimeKeyMsg
)
{
boolean
retCode
=
false
;
boolean
retCode
=
false
;
if
(
0
==
matchesInboundSessionFromIdKeyJni
(
aTheirIdentityKey
,
aOneTimeKeyMsg
)){
try
{
retCode
=
true
;
retCode
=
(
0
==
matchesInboundSessionFromIdKeyJni
(
aTheirIdentityKey
.
getBytes
(
"UTF-8"
),
aOneTimeKeyMsg
.
getBytes
(
"UTF-8"
)));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## matchesInboundSessionFrom(): failed "
+
e
.
getMessage
());
}
}
return
retCode
;
return
retCode
;
}
}
private
native
int
matchesInboundSessionFromIdKeyJni
(
String
aTheirIdentityKey
,
String
aOneTimeKeyMsg
);
private
native
int
matchesInboundSessionFromIdKeyJni
(
byte
[]
aTheirIdentityKey
,
byte
[]
aOneTimeKeyMsg
);
/**
/**
* Encrypt a message using the session.<br>
* Encrypt a message using the session.<br>
* The encrypted message is returned in a OlmMessage object.
* The encrypted message is returned in a OlmMessage object.
* Public API for {@link #encryptMessageJni(
String
, OlmMessage)}.
* Public API for {@link #encryptMessageJni(
byte[]
, OlmMessage)}.
* @param aClearMsg message to encrypted
* @param aClearMsg message to encrypted
* @return the encrypted message if operation succeed, null otherwise
* @return the encrypted message if operation succeed, null otherwise
*/
*/
public
OlmMessage
encryptMessage
(
String
aClearMsg
)
{
public
OlmMessage
encryptMessage
(
String
aClearMsg
)
{
OlmMessage
encryptedMsgRetValue
=
new
OlmMessage
();
OlmMessage
encryptedMsgRetValue
=
new
OlmMessage
();
if
(
0
!=
encryptMessageJni
(
aClearMsg
,
encryptedMsgRetValue
)){
try
{
if
(
0
!=
encryptMessageJni
(
aClearMsg
.
getBytes
(
"UTF-8"
),
encryptedMsgRetValue
))
{
encryptedMsgRetValue
=
null
;
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## encryptMessage(): failed "
+
e
.
getMessage
());
encryptedMsgRetValue
=
null
;
encryptedMsgRetValue
=
null
;
}
}
return
encryptedMsgRetValue
;
return
encryptedMsgRetValue
;
}
}
private
native
int
encryptMessageJni
(
String
aClearMsg
,
OlmMessage
aEncryptedMsg
);
private
native
int
encryptMessageJni
(
byte
[]
aClearMsg
,
OlmMessage
aEncryptedMsg
);