aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorylecollen <ylecollen@amdocs.com>2017-01-04 18:30:35 +0100
committerylecollen <ylecollen@amdocs.com>2017-01-04 18:30:35 +0100
commit9df5dd9c4257982d22955d6b9ee55fc1e9dcb25f (patch)
treedb28b1848d8458df9ffc5ea8fc02529f810f59e9
parent7f6a63068bd29309e4e75d8af8fce24b6636dffe (diff)
The olm objects are serialized as byte[] instead of strings.
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java16
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java24
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java33
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java25
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java22
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java6
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp6
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp2
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp12
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h2
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp15
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h2
12 files changed, 81 insertions, 84 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java
index 72437e4..b8c7215 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/CommonSerializeUtils.java
@@ -39,11 +39,11 @@ abstract class CommonSerializeUtils {
aOutStream.defaultWriteObject();
// generate serialization key
- String key = OlmUtility.getRandomKey();
+ byte[] key = OlmUtility.getRandomKey();
// compute pickle string
StringBuffer errorMsg = new StringBuffer();
- String pickledData = serialize(key, errorMsg);
+ byte[] pickledData = serialize(key, errorMsg);
if(null == pickledData) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_SERIALIZATION, String.valueOf(errorMsg));
@@ -62,12 +62,12 @@ abstract class CommonSerializeUtils {
protected void deserialize(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
aInStream.defaultReadObject();
- String key = (String) aInStream.readObject();
- String pickledData = (String) aInStream.readObject();
+ byte[] key = (byte[]) aInStream.readObject();
+ byte[] pickledData = (byte[]) aInStream.readObject();
- if (TextUtils.isEmpty(key)) {
+ if (null == key) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" key");
- } else if (TextUtils.isEmpty(pickledData)) {
+ } else if (null == pickledData) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" pickle");
}
@@ -75,6 +75,6 @@ abstract class CommonSerializeUtils {
Log.d(LOG_TAG,"## deserializeObject(): success");
}
- protected abstract String serialize(String aKey, StringBuffer aErrorMsg);
- protected abstract void deserialize(String aSerializedData, String aKey) throws IOException;
+ protected abstract byte[] serialize(byte[] aKey, StringBuffer aErrorMsg);
+ protected abstract void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException;
}
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
index 9d8e6d6..3a78365 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmAccount.java
@@ -418,27 +418,27 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
}
/**
- * Return an account as a base64 string.<br>
+ * Return an account as a bytes buffer.<br>
* The account is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
- * @return pickled base64 string if operation succeed, null otherwise
+ * @return the account as bytes buffer
*/
@Override
- protected String serialize(String aKey, StringBuffer aErrorMsg) {
- String pickleRetValue = null;
+ protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
+ byte[] pickleRetValue = null;
// sanity check
if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
- } else if(TextUtils.isEmpty(aKey)) {
+ } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
} else {
aErrorMsg.setLength(0);
try {
- pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8")), "UTF-8");
+ pickleRetValue = serializeJni(aKey);
} catch (Exception e) {
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
aErrorMsg.append(e.getMessage());
@@ -451,13 +451,13 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native byte[] serializeJni(byte[] aKey);
/**
- * Loads an account from a pickled base64 string.<br>
- * See {@link #serialize(String, StringBuffer)}
- * @param aSerializedData pickled account in a base64 string format
+ * Loads an account from a pickled bytes buffer.<br>
+ * See {@link #serialize(byte[], StringBuffer)}
+ * @param aSerializedData bytes buffer
* @param aKey key used to encrypted
*/
@Override
- protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewAccount()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
}
@@ -466,10 +466,10 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
try {
String jniError;
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters");
- } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError);
}
} catch (Exception e) {
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
index 41eeba1..dc1b80d 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmInboundGroupSession.java
@@ -44,7 +44,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/**
* Result in {@link #decryptMessage(String)}
*/
- static class DecryptMessageResult {
+ public static class DecryptMessageResult {
/** decrypt message **/
public String mDecryptedMessage;
@@ -135,6 +135,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/**
* Retrieve the base64-encoded identifier for this inbound group session.
* @return the session ID
+ * @throws OlmException the failure reason
*/
public String sessionIdentifier() throws OlmException {
try {
@@ -197,28 +198,28 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
}
/**
- * Return the current inbound group session as a base64 serialized string.<br>
+ * Return the current inbound group session as a bytes buffer.<br>
* The session is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
- * @return pickled base64 string if operation succeed, null otherwise
+ * @return pickled bytes buffer if operation succeed, null otherwise
*/
@Override
- protected String serialize(String aKey, StringBuffer aErrorMsg) {
- String pickleRetValue = null;
+ protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
+ byte[] pickleRetValue = null;
// sanity check
if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
aErrorMsg.append("aErrorMsg=null");
- } else if(TextUtils.isEmpty(aKey)) {
+ } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serialize()");
} else {
aErrorMsg.setLength(0);
try {
- pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8")), "UTF-8");
+ pickleRetValue = serializeJni(aKey);
} catch (Exception e) {
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
aErrorMsg.append(e.getMessage());
@@ -228,7 +229,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
return pickleRetValue;
}
/**
- * JNI counter part of {@link #serialize(String, StringBuffer)}.
+ * JNI counter part of {@link #serialize(byte[], StringBuffer)}.
* @param aKey encryption key
* @return pickled base64 string if operation succeed, null otherwise
*/
@@ -236,12 +237,12 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/**
* Loads an account from a pickled base64 string.<br>
- * See {@link #serialize(String, StringBuffer)}
- * @param aSerializedData pickled account in a base64 string format
+ * See {@link #serialize(byte[], StringBuffer)}
+ * @param aSerializedData pickled account in a bytes buffer
* @param aKey key used to encrypted
*/
@Override
- protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
}
@@ -250,10 +251,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
try {
String jniError;
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters");
- } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError);
}
} catch (Exception e) {
@@ -268,9 +269,9 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
}
/**
- * JNI counter part of {@link #deserialize(String, String)}.
- * @param aSerializedData pickled session in a base64 string format
- * @param aKey key used to encrypted in {@link #serialize(String, StringBuffer)}
+ * JNI counter part of {@link #deserialize(byte[], byte[])}.
+ * @param aSerializedData pickled session in a base64 sbytes buffer
+ * @param aKey key used to encrypted in {@link #serialize(byte[], StringBuffer)}
* @return null if operation succeed, an error message if operation failed
*/
private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
index c27addb..534636c 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmOutboundGroupSession.java
@@ -117,6 +117,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
/**
* Get a base64-encoded identifier for this session.
* @return session identifier
+ * @throws OlmException the failure reason
*/
public String sessionIdentifier() throws OlmException {
try {
@@ -210,26 +211,26 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
}
/**
- * Return the current outbound group session as a base64 serialized string.<br>
+ * Return the current outbound group session as a base64 byte buffers.<br>
* The session is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
- * @return pickled base64 string if operation succeed, null otherwise
+ * @return pickled base64 bytes buffer if operation succeed, null otherwise
*/
@Override
- protected String serialize(String aKey, StringBuffer aErrorMsg) {
- String pickleRetValue = null;
+ protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
+ byte[] pickleRetValue = null;
// sanity check
if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
- } else if(TextUtils.isEmpty(aKey)) {
+ } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serialize()");
} else {
try {
- pickleRetValue = serializeJni(aKey.getBytes("UTF-8"));
+ pickleRetValue = serializeJni(aKey);
} catch (Exception e) {
Log.e(LOG_TAG,"## serialize(): failed " + e.getMessage());
aErrorMsg.append(e.getMessage());
@@ -238,17 +239,17 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return pickleRetValue;
}
- private native String serializeJni(byte[] aKey);
+ private native byte[] serializeJni(byte[] aKey);
/**
* Loads an account from a pickled base64 string.<br>
- * See {@link #serialize(String, StringBuffer)}
- * @param aSerializedData pickled account in a base64 string format
+ * See {@link #serialize(byte[], StringBuffer)}
+ * @param aSerializedData pickled account in a base64 bytes buffer
* @param aKey key used to encrypted
*/
@Override
- protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
}
@@ -257,10 +258,10 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
try {
String jniError;
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters");
- } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError);
}
} catch (Exception e) {
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
index 9138309..bc190ed 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmSession.java
@@ -336,27 +336,27 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
}
/**
- * Return a session as a base64 string.<br>
+ * Return a session as a bytes buffer.<br>
* The account is serialized and encrypted with aKey.
* In case of failure, an error human readable
* description is provide in aErrorMsg.
* @param aKey encryption key
* @param aErrorMsg error message description
- * @return pickled base64 string if operation succeed, null otherwise
+ * @return session as a bytes buffer
*/
@Override
- protected String serialize(String aKey, StringBuffer aErrorMsg) {
- String pickleRetValue = null;
+ protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
+ byte[] pickleRetValue = null;
// sanity check
if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
- } else if(TextUtils.isEmpty(aKey)) {
+ } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
} else {
aErrorMsg.setLength(0);
try {
- pickleRetValue = serializeJni(aKey.getBytes("UTF-8"));
+ pickleRetValue = serializeJni(aKey);
} catch (Exception e) {
Log.e(LOG_TAG,"## serializeDataWithKey(): failed " + e.getMessage());
aErrorMsg.append(e.getMessage());
@@ -365,16 +365,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
return pickleRetValue;
}
- private native String serializeJni(byte[] aKey);
+ private native byte[] serializeJni(byte[] aKey);
/**
* Loads an account from a pickled base64 string.<br>
- * See {@link #serialize(String, StringBuffer)}
+ * See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData pickled account in a base64 string format
* @param aKey key used to encrypted
*/
@Override
- protected void deserialize(String aSerializedData, String aKey) throws IOException {
+ protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
}
@@ -383,10 +383,10 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
try {
String jniError;
- if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) {
+ if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("invalid input parameters");
- } else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
+ } else if (null != (jniError = deserializeJni(aSerializedData, aKey))) {
errorMsg.append(jniError);
}
} catch (Exception e) {
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
index d3c185f..28d8b58 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
@@ -135,13 +135,13 @@ public class OlmUtility {
/**
* Helper method to compute a string based on random integers.
- * @return string containing randoms integer values
+ * @return bytes buffer containing randoms integer values
*/
- public static String getRandomKey() {
+ public static byte[] getRandomKey() {
SecureRandom secureRandom = new SecureRandom();
byte[] buffer = new byte[RANDOM_KEY_SIZE];
secureRandom.nextBytes(buffer);
- return new String(buffer);
+ return buffer;
}
/**
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
index bac8b34..53eace7 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
@@ -558,7 +558,6 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi
size_t pickledLength = olm_pickle_account_length(accountPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
@@ -586,8 +585,8 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi
LOGD(" ## serializeJni(): 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);
+ pickledDataRetValue = env->NewByteArray(pickledLength);
+ env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength, (jbyte*)pickledPtr);
}
free(pickledPtr);
@@ -643,7 +642,6 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_account(accountPtr,
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
index 223b3d8..315f607 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_inbound_group_session.cpp
@@ -361,7 +361,6 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *en
size_t pickledLength = olm_pickle_inbound_group_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu", static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
@@ -444,7 +443,6 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_inbound_group_session(sessionPtr,
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
index 982840c..e8fd38b 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.cpp
@@ -381,11 +381,11 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIE
* @param aKey key used to encrypt the serialized session data
* @return a base64 string if operation succeed, null otherwise
**/
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer)
+JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer)
{
const char* errorMessage = NULL;
+ jbyteArray returnValue = 0;
- jstring pickledDataRetValue = 0;
jbyte* keyPtr = NULL;
OlmOutboundGroupSession* sessionPtr = NULL;
@@ -411,7 +411,6 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env,
size_t pickledLength = olm_pickle_outbound_group_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
@@ -436,8 +435,10 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env,
{
// build success output
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
- pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
+
+ returnValue = env->NewByteArray(pickledLength);
+ env->SetByteArrayRegion(returnValue, 0 , pickledLength, (jbyte*)pickledPtr);
}
}
@@ -455,7 +456,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env,
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
- return pickledDataRetValue;
+ return returnValue;
}
@@ -493,7 +494,6 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *en
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_outbound_group_session(sessionPtr,
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
index 1156b77..fb3bf87 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_outbound_group_session.h
@@ -40,7 +40,7 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer);
// serialization
-JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);
+JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
#ifdef __cplusplus
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
index f09ace6..7cde2cd 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.cpp
@@ -754,7 +754,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobjec
*/
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz)
{
- const char* errorMessage = NULL;
+ const char* errorMessage = NULL;
jbyteArray returnValue = 0;
LOGD("## getSessionIdentifierJni(): IN ");
@@ -817,11 +817,11 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env,
* @param aKey key used to encrypt the serialized session data
* @return a base64 string if operation succeed, null otherwise
**/
-JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer)
+JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer)
{
const char* errorMessage = NULL;
+ jbyteArray returnValue = 0;
- jstring pickledDataRetValue = 0;
jbyte* keyPtr = NULL;
OlmSession* sessionPtr = NULL;
@@ -847,7 +847,6 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz,
size_t pickledLength = olm_pickle_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
@@ -872,8 +871,10 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz,
{
// build success output
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
- pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
+
+ returnValue = env->NewByteArray(pickledLength);
+ env->SetByteArrayRegion(returnValue, 0 , pickledLength, (jbyte*)pickledPtr);
}
free(pickledPtr);
@@ -891,10 +892,9 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz,
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
}
- return pickledDataRetValue;
+ return returnValue;
}
-
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
{
OlmSession* sessionPtr = NULL;
@@ -929,7 +929,6 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
- LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_session(sessionPtr,
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
index 004031e..ef92395 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
+++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_session.h
@@ -50,7 +50,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobjec
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz);
// serialization
-JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);
+JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
#ifdef __cplusplus