The olm objects are serialized as byte[] instead of strings.

This commit is contained in:
ylecollen 2017-01-04 18:30:35 +01:00
parent 7f6a63068b
commit 9df5dd9c42
12 changed files with 81 additions and 84 deletions

View file

@ -39,11 +39,11 @@ abstract class CommonSerializeUtils {
aOutStream.defaultWriteObject(); aOutStream.defaultWriteObject();
// generate serialization key // generate serialization key
String key = OlmUtility.getRandomKey(); byte[] key = OlmUtility.getRandomKey();
// compute pickle string // compute pickle string
StringBuffer errorMsg = new StringBuffer(); StringBuffer errorMsg = new StringBuffer();
String pickledData = serialize(key, errorMsg); byte[] pickledData = serialize(key, errorMsg);
if(null == pickledData) { if(null == pickledData) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_SERIALIZATION, String.valueOf(errorMsg)); 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 { protected void deserialize(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
aInStream.defaultReadObject(); aInStream.defaultReadObject();
String key = (String) aInStream.readObject(); byte[] key = (byte[]) aInStream.readObject();
String pickledData = (String) 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"); 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"); 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"); Log.d(LOG_TAG,"## deserializeObject(): success");
} }
protected abstract String serialize(String aKey, StringBuffer aErrorMsg); protected abstract byte[] serialize(byte[] aKey, StringBuffer aErrorMsg);
protected abstract void deserialize(String aSerializedData, String aKey) throws IOException; protected abstract void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException;
} }

View file

@ -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. * The account is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise * @return the account as bytes buffer
*/ */
@Override @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null"); 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()"); aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
} else { } else {
aErrorMsg.setLength(0); aErrorMsg.setLength(0);
try { try {
pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8")), "UTF-8"); pickleRetValue = serializeJni(aKey);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage()); Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
aErrorMsg.append(e.getMessage()); aErrorMsg.append(e.getMessage());
@ -451,13 +451,13 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
private native byte[] serializeJni(byte[] aKey); private native byte[] serializeJni(byte[] aKey);
/** /**
* Loads an account from a pickled base64 string.<br> * Loads an account from a pickled bytes buffer.<br>
* See {@link #serialize(String, StringBuffer)} * See {@link #serialize(byte[], StringBuffer)}
* @param aSerializedData pickled account in a base64 string format * @param aSerializedData bytes buffer
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewAccount()) { if (!createNewAccount()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); 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 { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("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); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {

View file

@ -44,7 +44,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/** /**
* Result in {@link #decryptMessage(String)} * Result in {@link #decryptMessage(String)}
*/ */
static class DecryptMessageResult { public static class DecryptMessageResult {
/** decrypt message **/ /** decrypt message **/
public String mDecryptedMessage; public String mDecryptedMessage;
@ -135,6 +135,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
/** /**
* Retrieve the base64-encoded identifier for this inbound group session. * Retrieve the base64-encoded identifier for this inbound group session.
* @return the session ID * @return the session ID
* @throws OlmException the failure reason
*/ */
public String sessionIdentifier() throws OlmException { public String sessionIdentifier() throws OlmException {
try { 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. * The session is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise * @return pickled bytes buffer if operation succeed, null otherwise
*/ */
@Override @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null"); Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
aErrorMsg.append("aErrorMsg=null"); aErrorMsg.append("aErrorMsg=null");
} else if(TextUtils.isEmpty(aKey)) { } else if (null == aKey) {
aErrorMsg.append("Invalid input parameters in serialize()"); aErrorMsg.append("Invalid input parameters in serialize()");
} else { } else {
aErrorMsg.setLength(0); aErrorMsg.setLength(0);
try { try {
pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8")), "UTF-8"); pickleRetValue = serializeJni(aKey);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage()); Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
aErrorMsg.append(e.getMessage()); aErrorMsg.append(e.getMessage());
@ -228,7 +229,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
return pickleRetValue; return pickleRetValue;
} }
/** /**
* JNI counter part of {@link #serialize(String, StringBuffer)}. * JNI counter part of {@link #serialize(byte[], StringBuffer)}.
* @param aKey encryption key * @param aKey encryption key
* @return pickled base64 string if operation succeed, null otherwise * @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> * 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 aSerializedData pickled account in a bytes buffer
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) { if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); 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 { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("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); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {
@ -268,9 +269,9 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
} }
/** /**
* JNI counter part of {@link #deserialize(String, String)}. * JNI counter part of {@link #deserialize(byte[], byte[])}.
* @param aSerializedData pickled session in a base64 string format * @param aSerializedData pickled session in a base64 sbytes buffer
* @param aKey key used to encrypted in {@link #serialize(String, StringBuffer)} * @param aKey key used to encrypted in {@link #serialize(byte[], 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 deserializeJni(byte[] aSerializedData, byte[] aKey); private native String deserializeJni(byte[] aSerializedData, byte[] aKey);

View file

@ -117,6 +117,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
/** /**
* Get a base64-encoded identifier for this session. * Get a base64-encoded identifier for this session.
* @return session identifier * @return session identifier
* @throws OlmException the failure reason
*/ */
public String sessionIdentifier() throws OlmException { public String sessionIdentifier() throws OlmException {
try { 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. * The session is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @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 @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null"); 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()"); aErrorMsg.append("Invalid input parameters in serialize()");
} else { } else {
try { try {
pickleRetValue = serializeJni(aKey.getBytes("UTF-8")); pickleRetValue = serializeJni(aKey);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG,"## serialize(): failed " + e.getMessage()); Log.e(LOG_TAG,"## serialize(): failed " + e.getMessage());
aErrorMsg.append(e.getMessage()); aErrorMsg.append(e.getMessage());
@ -238,17 +239,17 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
return pickleRetValue; return pickleRetValue;
} }
private native String serializeJni(byte[] aKey); private native byte[] serializeJni(byte[] aKey);
/** /**
* Loads an account from a pickled base64 string.<br> * 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 aSerializedData pickled account in a base64 bytes buffer
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) { if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); 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 { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("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); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {

View file

@ -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. * The account is serialized and encrypted with aKey.
* In case of failure, an error human readable * In case of failure, an error human readable
* description is provide in aErrorMsg. * description is provide in aErrorMsg.
* @param aKey encryption key * @param aKey encryption key
* @param aErrorMsg error message description * @param aErrorMsg error message description
* @return pickled base64 string if operation succeed, null otherwise * @return session as a bytes buffer
*/ */
@Override @Override
protected String serialize(String aKey, StringBuffer aErrorMsg) { protected byte[] serialize(byte[] aKey, StringBuffer aErrorMsg) {
String pickleRetValue = null; byte[] pickleRetValue = null;
// sanity check // sanity check
if(null == aErrorMsg) { if(null == aErrorMsg) {
Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null"); 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()"); aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
} else { } else {
aErrorMsg.setLength(0); aErrorMsg.setLength(0);
try { try {
pickleRetValue = serializeJni(aKey.getBytes("UTF-8")); pickleRetValue = serializeJni(aKey);
} 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());
@ -365,16 +365,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
return pickleRetValue; return pickleRetValue;
} }
private native String serializeJni(byte[] aKey); private native byte[] serializeJni(byte[] aKey);
/** /**
* Loads an account from a pickled base64 string.<br> * 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 aSerializedData pickled account in a base64 string format
* @param aKey key used to encrypted * @param aKey key used to encrypted
*/ */
@Override @Override
protected void deserialize(String aSerializedData, String aKey) throws IOException { protected void deserialize(byte[] aSerializedData, byte[] aKey) throws IOException {
if (!createNewSession()) { if (!createNewSession()) {
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION); 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 { try {
String jniError; String jniError;
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(aKey)) { if ((null == aSerializedData) || (null == aKey)) {
Log.e(LOG_TAG, "## deserialize(): invalid input parameters"); Log.e(LOG_TAG, "## deserialize(): invalid input parameters");
errorMsg.append("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); errorMsg.append(jniError);
} }
} catch (Exception e) { } catch (Exception e) {

View file

@ -135,13 +135,13 @@ public class OlmUtility {
/** /**
* Helper method to compute a string based on random integers. * 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(); SecureRandom secureRandom = new SecureRandom();
byte[] buffer = new byte[RANDOM_KEY_SIZE]; byte[] buffer = new byte[RANDOM_KEY_SIZE];
secureRandom.nextBytes(buffer); secureRandom.nextBytes(buffer);
return new String(buffer); return buffer;
} }
/** /**

View file

@ -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 pickledLength = olm_pickle_account_length(accountPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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)); 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)); LOGD(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
pickledDataRetValue = env->NewByteArray(pickledLength+1); pickledDataRetValue = env->NewByteArray(pickledLength);
env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength+1, (jbyte*)pickledPtr); env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength, (jbyte*)pickledPtr);
} }
free(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 pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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); LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_account(accountPtr, size_t result = olm_unpickle_account(accountPtr,

View file

@ -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 pickledLength = olm_pickle_inbound_group_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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)); 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 pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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); LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_inbound_group_session(sessionPtr, size_t result = olm_unpickle_inbound_group_session(sessionPtr,

View file

@ -381,11 +381,11 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIE
* @param aKey key used to encrypt the serialized session data * @param aKey key used to encrypt the serialized session data
* @return a base64 string if operation succeed, null otherwise * @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; const char* errorMessage = NULL;
jbyteArray returnValue = 0;
jstring pickledDataRetValue = 0;
jbyte* keyPtr = NULL; jbyte* keyPtr = NULL;
OlmOutboundGroupSession* sessionPtr = 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 pickledLength = olm_pickle_outbound_group_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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)); 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 // 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(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<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); 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 pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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); LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_outbound_group_session(sessionPtr, size_t result = olm_unpickle_outbound_group_session(sessionPtr,

View file

@ -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); JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer);
// serialization // 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); JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -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) JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz)
{ {
const char* errorMessage = NULL; const char* errorMessage = NULL;
jbyteArray returnValue = 0; jbyteArray returnValue = 0;
LOGD("## getSessionIdentifierJni(): IN "); 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 * @param aKey key used to encrypt the serialized session data
* @return a base64 string if operation succeed, null otherwise * @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; const char* errorMessage = NULL;
jbyteArray returnValue = 0;
jstring pickledDataRetValue = 0;
jbyte* keyPtr = NULL; jbyte* keyPtr = NULL;
OlmSession* sessionPtr = 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 pickledLength = olm_pickle_session_length(sessionPtr);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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)); 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 // 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(" ## serializeJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<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); 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); 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) JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
{ {
OlmSession* sessionPtr = NULL; 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 pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); 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(): 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); LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr);
size_t result = olm_unpickle_session(sessionPtr, size_t result = olm_unpickle_session(sessionPtr,

View file

@ -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); JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz);
// serialization // 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); JNIEXPORT jstring OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
#ifdef __cplusplus #ifdef __cplusplus