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 {
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
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
;
}
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 {
boolean
retCode
=
false
;
String
jniError
;
if
(
null
==
aErrorMsg
)
{
if
(
null
==
aErrorMsg
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input error parameter"
);
}
else
{
aErrorMsg
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
retCode
=
true
;
}
else
{
aErrorMsg
.
append
(
jniError
);
try
{
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
retCode
=
true
;
}
else
{
aErrorMsg
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData() failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
return
retCode
;
}
private
native
String
initWithSerializedDataJni
(
String
aSerializedData
,
String
aKey
);
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedData
Buffer
,
byte
[]
aKeyBuffer
);
/**
* 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
if
(
TextUtils
.
isEmpty
(
aSessionKey
)){
Log
.
e
(
LOG_TAG
,
"## initInboundGroupSessionWithSessionKey(): invalid session key"
);
}
else
{
retCode
=
initInboundGroupSessionWithSessionKeyJni
(
aSessionKey
);
try
{
retCode
=
initInboundGroupSessionWithSessionKeyJni
(
aSessionKey
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initInboundGroupSessionWithSessionKey() failed "
+
e
.
getMessage
());
}
}
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
DecryptMessageResult
result
=
new
DecryptMessageResult
();
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
if
(
0
!=
errorMsg
.
length
())
{
...
...
@@ -166,7 +174,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
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.
...
...
@@ -217,7 +225,11 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
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
;
...
...
@@ -228,7 +240,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
* @param aErrorMsg error message description
* @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
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input error parameter"
);
}
else
{
aErrorMsg
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
retCode
=
true
;
}
else
{
aErrorMsg
.
append
(
jniError
);
try
{
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
retCode
=
true
;
}
else
{
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
* @param aKey key used to encrypted in {@link #serializeDataWithKey(String, StringBuffer)}
* @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>
...
...
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
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
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
;
}
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
}
else
{
aErrorMsg
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
retCode
=
true
;
}
else
{
aErrorMsg
.
append
(
jniError
);
try
{
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
retCode
=
true
;
}
else
{
aErrorMsg
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
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 {
aErrorMsg
.
append
(
"Invalid input parameters in serializeDataWithKey()"
);
}
else
{
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
;
}
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 {
}
else
{
aErrorMsg
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
,
aKey
)))
{
retCode
=
true
;
}
else
{
aErrorMsg
.
append
(
jniError
);
try
{
if
(
TextUtils
.
isEmpty
(
aSerializedData
)
||
TextUtils
.
isEmpty
(
aKey
))
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
initWithSerializedDataJni
(
aSerializedData
.
getBytes
(
"UTF-8"
),
aKey
.
getBytes
(
"UTF-8"
))))
{
retCode
=
true
;
}
else
{
aErrorMsg
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## initWithSerializedData(): failed "
+
e
.
getMessage
());
aErrorMsg
.
append
(
e
.
getMessage
());
}
}
return
retCode
;
}
private
native
String
initWithSerializedDataJni
(
String
aSerializedData
,
String
aKey
);
private
native
String
initWithSerializedDataJni
(
byte
[]
aSerializedData
,
byte
[]
aKey
);
/**
* Getter on the session ID.
...
...
@@ -215,43 +225,50 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aTheirIdentityKey
)
||
TextUtils
.
isEmpty
(
aTheirOneTimeKey
)){
Log
.
e
(
LOG_TAG
,
"## initOutboundSession(): invalid input parameters"
);
}
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
;
}
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
* 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).
* @param aAccount the account to associate with this session
* @param aPreKeyMsg PRE KEY message
* @return 0 if operation succeed, -1 otherwise
*/
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"
);
}
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
;
}
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
* 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 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
...
...
@@ -265,13 +282,17 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
if
((
null
==
aAccount
)
||
TextUtils
.
isEmpty
(
aPreKeyMsg
)){
Log
.
e
(
LOG_TAG
,
"## initInboundSessionWithAccount(): invalid input parameters"
);
}
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
;
}
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
...
...
@@ -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>
* 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
* @return this if operation succeed, null otherwise
*/
public
boolean
matchesInboundSession
(
String
aOneTimeKeyMsg
)
{
boolean
retCode
=
false
;
if
(
0
==
matchesInboundSessionJni
(
aOneTimeKeyMsg
)){
retCode
=
true
;
try
{
retCode
=
(
0
==
matchesInboundSessionJni
(
aOneTimeKeyMsg
.
getBytes
(
"UTF-8"
)));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## matchesInboundSession(): failed "
+
e
.
getMessage
());
}
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>
* 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 aOneTimeKeyMsg PRE KEY message
* @return this if operation succeed, null otherwise
...
...
@@ -316,33 +340,41 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
public
boolean
matchesInboundSessionFrom
(
String
aTheirIdentityKey
,
String
aOneTimeKeyMsg
)
{
boolean
retCode
=
false
;
if
(
0
==
matchesInboundSessionFromIdKeyJni
(
aTheirIdentityKey
,
aOneTimeKeyMsg
)){
retCode
=
true
;
try
{
retCode
=
(
0
==
matchesInboundSessionFromIdKeyJni
(
aTheirIdentityKey
.
getBytes
(
"UTF-8"
),
aOneTimeKeyMsg
.
getBytes
(
"UTF-8"
)));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## matchesInboundSessionFrom(): failed "
+
e
.
getMessage
());
}
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>
* 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
* @return the encrypted message if operation succeed, null otherwise
*/
public
OlmMessage
encryptMessage
(
String
aClearMsg
)
{
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
;
}
return
encryptedMsgRetValue
;
}
private
native
int
encryptMessageJni
(
String
aClearMsg
,
OlmMessage
aEncryptedMsg
);
private
native
int
encryptMessageJni
(
byte
[]
aClearMsg
,
OlmMessage
aEncryptedMsg
);
/**
* Decrypt a message using the session.<br>
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
View file @
765647cd
...
...
@@ -82,13 +82,17 @@ public class OlmUtility {
}
else
{
aError
.
setLength
(
0
);
if
(
TextUtils
.
isEmpty
(
aSignature
)
||
TextUtils
.
isEmpty
(
aFingerprintKey
)
||
TextUtils
.
isEmpty
(
aMessage
))
{
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): invalid input parameters"
);
aError
.
append
(
"JAVA sanity check failure - invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
verifyEd25519SignatureJni
(
aSignature
,
aFingerprintKey
,
aMessage
)))
{
retCode
=
true
;
}
else
{
aError
.
append
(
jniError
);
try
{
if
(
TextUtils
.
isEmpty
(
aSignature
)
||
TextUtils
.
isEmpty
(
aFingerprintKey
)
||
TextUtils
.
isEmpty
(
aMessage
))
{
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): invalid input parameters"
);
aError
.
append
(
"JAVA sanity check failure - invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
verifyEd25519SignatureJni
(
aSignature
.
getBytes
(
"UTF-8"
),
aFingerprintKey
.
getBytes
(
"UTF-8"
),
aMessage
.
getBytes
(
"UTF-8"
))))
{
retCode
=
true
;
}
else
{
aError
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): failed "
+
e
.
getMessage
());
}
}
...
...
@@ -103,7 +107,7 @@ public class OlmUtility {
* @param aMessage the signed message
* @return null if validation succeed, the error message string if operation failed
*/
private
native
String
verifyEd25519SignatureJni
(
String
aSignature
,
String
aFingerprintKey
,
String
aMessage
);
private
native
String
verifyEd25519SignatureJni
(
byte
[]
aSignature
,
byte
[]
aFingerprintKey
,
byte
[]
aMessage
);
/**
...
...
@@ -115,14 +119,18 @@ public class OlmUtility {
public
String
sha256
(
String
aMessageToHash
)
{
String
hashRetValue
=
null
;
if
(
null
!=
aMessageToHash
){
hashRetValue
=
sha256Jni
(
aMessageToHash
);
if
(
null
!=
aMessageToHash
)
{
try
{
hashRetValue
=
sha256Jni
(
aMessageToHash
.
getBytes
(
"UTF-8"
));
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sha256(): failed "
+
e
.
getMessage
());
}
}
return
hashRetValue
;
}
private
native
String
sha256Jni
(
String
aMessage
);
private
native
String
sha256Jni
(
byte
[]
aMessage
);
/**
...
...
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
View file @
765647cd
...
...
@@ -468,22 +468,22 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
/**
* Serialize and encrypt account instance into a base64 string.<br>
* @param aKey key used to encrypt the serialized account data
* @param aKey
Buffer
key used to encrypt the serialized account data
* @param[out] aErrorMsg error message set if operation failed
* @return a base64 string if operation succeed, null otherwise
**/
JNIEXPORT
jstring
OLM_ACCOUNT_FUNC_DEF
(
serializeDataWithKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
string
aKey
,
jobject
aErrorMsg
)
JNIEXPORT
jstring
OLM_ACCOUNT_FUNC_DEF
(
serializeDataWithKeyJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
byteArray
aKeyBuffer
,
jobject
aErrorMsg
)
{
jstring
pickledDataRetValue
=
0
;
jclass
errorMsgJClass
=
0
;
jmethodID
errorMsgMethodId
=
0
;
jstring
errorJstring
=
0
;
const
char
*
keyPtr
=
NULL
;
jbyte
*
keyPtr
=
NULL
;
OlmAccount
*
accountPtr
=
NULL
;
LOGD
(
"## serializeDataWithKeyJni(): IN"
);
if
(
!
aKey
)
if
(
!
aKey
Buffer
)
{
LOGE
(
" ## serializeDataWithKeyJni(): failure - invalid key"
);
}
...
...
@@ -503,14 +503,14 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
{
LOGE
(
" ## serializeDataWithKeyJni(): failure - unable to get error method ID"
);
}
else
if
(
!
(
keyPtr
=
env
->
Get
StringUTFChars
(
aKey
,
0
)))
else
if
(
!
(
keyPtr
=
env
->
Get
ByteArrayElements
(
aKeyBuffer
,
NULL
)))
{
LOGE
(
" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM"
);
}
else
{
size_t
pickledLength
=
olm_pickle_account_length
(
accountPtr
);
size_t
keyLength
=
(
size_t
)
env
->
Get
StringUTF
Length
(
aKey
);
size_t
keyLength
=
(
size_t
)
env
->
Get
Array
Length
(
aKey
Buffer
);
LOGD
(
" ## serializeDataWithKeyJni(): pickledLength=%lu keyLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
pickledLength
),
static_cast
<
long
unsigned
int
>
(
keyLength
));
LOGD
(
" ## serializeDataWithKeyJni(): key=%s"
,(
char
const
*
)
keyPtr
);
...
...
@@ -552,27 +552,27 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
// free alloc
if
(
keyPtr
)
{
env
->
Release
StringUTFChars
(
aKey
,
keyPtr
);
env
->
Release
ByteArrayElements
(
aKeyBuffer
,
keyPtr
,
JNI_ABORT
);
}
return
pickledDataRetValue
;
}
JNIEXPORT
jstring
OLM_ACCOUNT_FUNC_DEF
(
initWithSerializedDataJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
string
aSerializedData
,
jstring
aKey
)
JNIEXPORT
jstring
OLM_ACCOUNT_FUNC_DEF
(
initWithSerializedDataJni
)(
JNIEnv
*
env
,
jobject
thiz
,
j
byteArray
aSerializedData
Buffer
,
jbyteArray
aKeyBuffer
)
{
OlmAccount
*
accountPtr
=
NULL
;
jstring
errorMessageRetValue
=
0
;
const
char
*
keyPtr
=
NULL
;
const
char
*
pickledPtr
=
NULL
;
jbyte
*
keyPtr
=
NULL
;
jbyte
*
pickledPtr
=
NULL
;
LOGD
(
"## initWithSerializedDataJni(): IN"
);
if
(
!
aKey
)
if
(
!
aKey
Buffer
)
{
LOGE
(
" ## initWithSerializedDataJni(): failure - invalid key"
);
}
else
if
(
!
aSerializedData
)
else
if
(
!
aSerializedData
Buffer
)
{
LOGE
(
" ## initWithSerializedDataJni(): failure - serialized data"
);
}
...
...
@@ -580,18 +580,18 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
{
LOGE
(
" ## initWithSerializedDataJni(): failure - account failure OOM"
);
}
else
if
(
!
(
keyPtr
=
env
->
Get
StringUTFChars
(
aKey
,
0
)))
else
if
(
!
(
keyPtr
=
env
->
Get
ByteArrayElements
(
aKeyBuffer
,
0
)))
{
LOGE
(
" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM"
);
}
else
if
(
!
(
pickledPtr
=
env
->
Get
StringUTFChar
s
(
aSerializedData
,
0
)))
else
if
(
!
(
pickledPtr
=
env
->
Get
ByteArrayElement
s
(
aSerializedData
Buffer
,
0
)))
{
LOGE
(
" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM"
);
}
else
{
size_t
pickledLength
=
(
size_t
)
env
->
Get
StringUTF
Length
(
aSerializedData
);
size_t
keyLength
=
(
size_t
)
env
->
Get
StringUTF
Length
(
aKey
);