Simplify the serialization / deserializtion methods (CommonSerializeUtils)
This commit is contained in:
parent
2070de4fc5
commit
ce9f67d5be
14 changed files with 503 additions and 545 deletions
|
@ -112,7 +112,7 @@ public class OlmSessionTest {
|
||||||
assertTrue(0!=aliceSession.getOlmSessionId());
|
assertTrue(0!=aliceSession.getOlmSessionId());
|
||||||
|
|
||||||
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
|
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
|
||||||
assertNotNull(aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
assertNotNull(aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
||||||
String clearMsg = "Heloo bob , this is alice!";
|
String clearMsg = "Heloo bob , this is alice!";
|
||||||
OlmMessage encryptedMsgToBob = aliceSession.encryptMessage(clearMsg);
|
OlmMessage encryptedMsgToBob = aliceSession.encryptMessage(clearMsg);
|
||||||
assertNotNull(encryptedMsgToBob);
|
assertNotNull(encryptedMsgToBob);
|
||||||
|
@ -129,7 +129,7 @@ public class OlmSessionTest {
|
||||||
assertTrue(0!=bobSession.getOlmSessionId());
|
assertTrue(0!=bobSession.getOlmSessionId());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(bobAccount, encryptedMsgToBob.mCipherText);
|
bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ public class OlmSessionTest {
|
||||||
assertTrue(0!=aliceSession.getOlmSessionId());
|
assertTrue(0!=aliceSession.getOlmSessionId());
|
||||||
|
|
||||||
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
|
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
|
||||||
assertNotNull(aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
assertNotNull(aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
||||||
String helloClearMsg = "Hello I'm Alice!";
|
String helloClearMsg = "Hello I'm Alice!";
|
||||||
|
|
||||||
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
|
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
|
||||||
|
@ -229,7 +229,7 @@ public class OlmSessionTest {
|
||||||
assertTrue(0!=bobSession.getOlmSessionId());
|
assertTrue(0!=bobSession.getOlmSessionId());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(bobAccount, encryptedAliceToBobMsg1.mCipherText);
|
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ public class OlmSessionTest {
|
||||||
String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
|
String bobOneTimeKey1 = TestHelper.getOneTimeKey(bobOneTimeKeys, 1);
|
||||||
|
|
||||||
// create alice inbound session for bob
|
// create alice inbound session for bob
|
||||||
assertTrue(0==aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey1));
|
assertTrue(0==aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey1));
|
||||||
|
|
||||||
String aliceClearMsg = "hello helooo to bob!";
|
String aliceClearMsg = "hello helooo to bob!";
|
||||||
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(aliceClearMsg);
|
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(aliceClearMsg);
|
||||||
|
@ -389,7 +389,7 @@ public class OlmSessionTest {
|
||||||
|
|
||||||
// init bob session with alice PRE KEY
|
// init bob session with alice PRE KEY
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(bobAccount, encryptedAliceToBobMsg1.mCipherText);
|
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
||||||
}
|
}
|
||||||
|
@ -463,7 +463,7 @@ public class OlmSessionTest {
|
||||||
assertTrue(0!=aliceSession.getOlmSessionId());
|
assertTrue(0!=aliceSession.getOlmSessionId());
|
||||||
|
|
||||||
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
|
// CREATE ALICE OUTBOUND SESSION and encrypt message to bob
|
||||||
assertNotNull(aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
assertNotNull(aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
||||||
String helloClearMsg = "Hello I'm Alice!";
|
String helloClearMsg = "Hello I'm Alice!";
|
||||||
|
|
||||||
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
|
OlmMessage encryptedAliceToBobMsg1 = aliceSession.encryptMessage(helloClearMsg);
|
||||||
|
@ -481,7 +481,7 @@ public class OlmSessionTest {
|
||||||
|
|
||||||
// init bob session with alice PRE KEY
|
// init bob session with alice PRE KEY
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(bobAccount, encryptedAliceToBobMsg1.mCipherText);
|
bobSession.initInboundSession(bobAccount, encryptedAliceToBobMsg1.mCipherText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
assertTrue("initInboundSessionWithAccount failed " + e.getMessage(), false);
|
||||||
}
|
}
|
||||||
|
@ -608,13 +608,13 @@ public class OlmSessionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SANITY CHECK TESTS FOR: initOutboundSessionWithAccount()
|
// SANITY CHECK TESTS FOR: initOutboundSessionWithAccount()
|
||||||
assertTrue(-1==aliceSession.initOutboundSessionWithAccount(null, bobIdentityKey, bobOneTimeKey));
|
assertTrue(-1==aliceSession.initOutboundSession(null, bobIdentityKey, bobOneTimeKey));
|
||||||
assertTrue(-1==aliceSession.initOutboundSessionWithAccount(aliceAccount, null, bobOneTimeKey));
|
assertTrue(-1==aliceSession.initOutboundSession(aliceAccount, null, bobOneTimeKey));
|
||||||
assertTrue(-1==aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, null));
|
assertTrue(-1==aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, null));
|
||||||
assertTrue(-1==aliceSession.initOutboundSessionWithAccount(null, null, null));
|
assertTrue(-1==aliceSession.initOutboundSession(null, null, null));
|
||||||
|
|
||||||
// init properly
|
// init properly
|
||||||
assertTrue(0==aliceSession.initOutboundSessionWithAccount(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
assertTrue(0==aliceSession.initOutboundSession(aliceAccount, bobIdentityKey, bobOneTimeKey));
|
||||||
|
|
||||||
// SANITY CHECK TESTS FOR: encryptMessage()
|
// SANITY CHECK TESTS FOR: encryptMessage()
|
||||||
assertTrue(null==aliceSession.encryptMessage(null));
|
assertTrue(null==aliceSession.encryptMessage(null));
|
||||||
|
@ -629,7 +629,7 @@ public class OlmSessionTest {
|
||||||
bobSession = new OlmSession();
|
bobSession = new OlmSession();
|
||||||
String errorMessage = null;
|
String errorMessage = null;
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(null, encryptedMsgToBob.mCipherText);
|
bobSession.initInboundSession(null, encryptedMsgToBob.mCipherText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorMessage = e.getMessage();
|
errorMessage = e.getMessage();
|
||||||
}
|
}
|
||||||
|
@ -638,7 +638,7 @@ public class OlmSessionTest {
|
||||||
|
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(bobAccount, null);
|
bobSession.initInboundSession(bobAccount, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorMessage = e.getMessage();
|
errorMessage = e.getMessage();
|
||||||
}
|
}
|
||||||
|
@ -647,7 +647,7 @@ public class OlmSessionTest {
|
||||||
|
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(bobAccount, INVALID_PRE_KEY);
|
bobSession.initInboundSession(bobAccount, INVALID_PRE_KEY);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorMessage = e.getMessage();
|
errorMessage = e.getMessage();
|
||||||
}
|
}
|
||||||
|
@ -657,7 +657,7 @@ public class OlmSessionTest {
|
||||||
// init properly
|
// init properly
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
try {
|
try {
|
||||||
bobSession.initInboundSessionWithAccount(bobAccount, encryptedMsgToBob.mCipherText);
|
bobSession.initInboundSession(bobAccount, encryptedMsgToBob.mCipherText);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorMessage = e.getMessage();
|
errorMessage = e.getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ abstract class CommonSerializeUtils {
|
||||||
* @param aOutStream output stream for serializing
|
* @param aOutStream output stream for serializing
|
||||||
* @throws IOException exception
|
* @throws IOException exception
|
||||||
*/
|
*/
|
||||||
protected void serializeObject(ObjectOutputStream aOutStream) throws IOException {
|
protected void serialize(ObjectOutputStream aOutStream) throws IOException {
|
||||||
aOutStream.defaultWriteObject();
|
aOutStream.defaultWriteObject();
|
||||||
|
|
||||||
// generate serialization key
|
// generate serialization key
|
||||||
|
@ -43,7 +43,7 @@ abstract class CommonSerializeUtils {
|
||||||
|
|
||||||
// compute pickle string
|
// compute pickle string
|
||||||
StringBuffer errorMsg = new StringBuffer();
|
StringBuffer errorMsg = new StringBuffer();
|
||||||
String pickledData = serializeDataWithKey(key, errorMsg);
|
String 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));
|
||||||
|
@ -59,33 +59,22 @@ abstract class CommonSerializeUtils {
|
||||||
* @throws IOException exception
|
* @throws IOException exception
|
||||||
* @throws ClassNotFoundException exception
|
* @throws ClassNotFoundException exception
|
||||||
*/
|
*/
|
||||||
protected void deserializeObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
protected void deserialize(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||||
aInStream.defaultReadObject();
|
aInStream.defaultReadObject();
|
||||||
StringBuffer errorMsg = new StringBuffer();
|
|
||||||
|
|
||||||
String key = (String) aInStream.readObject();
|
String key = (String) aInStream.readObject();
|
||||||
String pickledData = (String) aInStream.readObject();
|
String pickledData = (String) aInStream.readObject();
|
||||||
|
|
||||||
if(TextUtils.isEmpty(key)) {
|
if (TextUtils.isEmpty(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(TextUtils.isEmpty(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");
|
||||||
|
|
||||||
} else if(!createNewObjectFromSerialization()) {
|
|
||||||
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INIT_NEW_ACCOUNT_DESERIALIZATION);
|
|
||||||
|
|
||||||
} else if(!initWithSerializedData(pickledData, key, errorMsg)) {
|
|
||||||
releaseObjectFromSerialization(); // prevent memory leak
|
|
||||||
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Log.d(LOG_TAG,"## readObject(): success");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String serializeDataWithKey(String aKey, StringBuffer aErrorMsg);
|
deserialize(pickledData, key);
|
||||||
protected abstract boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg);
|
Log.d(LOG_TAG,"## deserializeObject(): success");
|
||||||
protected abstract boolean createNewObjectFromSerialization();
|
}
|
||||||
protected abstract void releaseObjectFromSerialization();
|
|
||||||
|
protected abstract String serialize(String aKey, StringBuffer aErrorMsg);
|
||||||
|
protected abstract void deserialize(String aSerializedData, String aKey) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,105 +68,6 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Kick off the serialization mechanism.
|
|
||||||
* @param aOutStream output stream for serializing
|
|
||||||
* @throws IOException exception
|
|
||||||
*/
|
|
||||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
|
||||||
serializeObject(aOutStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kick off the deserialization mechanism.
|
|
||||||
* @param aInStream input stream
|
|
||||||
* @throws IOException exception
|
|
||||||
* @throws ClassNotFoundException exception
|
|
||||||
*/
|
|
||||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
|
||||||
deserializeObject(aInStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean createNewObjectFromSerialization() {
|
|
||||||
return createNewAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void releaseObjectFromSerialization() {
|
|
||||||
releaseAccount();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an account as a base64 string.<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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
|
|
||||||
String pickleRetValue = null;
|
|
||||||
|
|
||||||
// sanity check
|
|
||||||
if(null == aErrorMsg) {
|
|
||||||
Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
|
|
||||||
} else if(TextUtils.isEmpty(aKey)) {
|
|
||||||
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
|
|
||||||
} else {
|
|
||||||
aErrorMsg.setLength(0);
|
|
||||||
try {
|
|
||||||
pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
|
|
||||||
aErrorMsg.append(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pickleRetValue;
|
|
||||||
}
|
|
||||||
private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads an account from a pickled base64 string.<br>
|
|
||||||
* See {@link #serializeDataWithKey(String, StringBuffer)}
|
|
||||||
* @param aSerializedData pickled account in a base64 string format
|
|
||||||
* @param aKey key used to encrypted
|
|
||||||
* @param aErrorMsg error message description
|
|
||||||
* @return true if operation succeed, false otherwise
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
|
|
||||||
boolean retCode = false;
|
|
||||||
String jniError;
|
|
||||||
|
|
||||||
if (null == aErrorMsg) {
|
|
||||||
Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
|
|
||||||
} else {
|
|
||||||
aErrorMsg.setLength(0);
|
|
||||||
|
|
||||||
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(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter on the account ID.
|
* Getter on the account ID.
|
||||||
* @return native account ID
|
* @return native account ID
|
||||||
|
@ -229,6 +130,14 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
*/
|
*/
|
||||||
private native long createNewAccountJni();
|
private native long createNewAccountJni();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true the object resources have been released.<br>
|
||||||
|
* @return true the object resources have been released
|
||||||
|
*/
|
||||||
|
public boolean isReleased() {
|
||||||
|
return (0 == mNativeId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the identity keys (identity and fingerprint keys) in a dictionary.<br>
|
* Return the identity keys (identity and fingerprint keys) in a dictionary.<br>
|
||||||
* Public API for {@link #identityKeysJni()}.<br>
|
* Public API for {@link #identityKeysJni()}.<br>
|
||||||
|
@ -393,14 +302,6 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
|
|
||||||
private native byte[] signMessageJni(byte[] aMessage);
|
private native byte[] signMessageJni(byte[] aMessage);
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true the object resources have been released.<br>
|
|
||||||
* @return true the object resources have been released
|
|
||||||
*/
|
|
||||||
public boolean isReleased() {
|
|
||||||
return (0 == mNativeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build a string-string dictionary from a jsonObject.<br>
|
* Build a string-string dictionary from a jsonObject.<br>
|
||||||
* @param jsonObject the object to parse
|
* @param jsonObject the object to parse
|
||||||
|
@ -461,4 +362,95 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==============================================================================================================
|
||||||
|
// Serialization management
|
||||||
|
//==============================================================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kick off the serialization mechanism.
|
||||||
|
* @param aOutStream output stream for serializing
|
||||||
|
* @throws IOException exception
|
||||||
|
*/
|
||||||
|
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||||
|
serialize(aOutStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kick off the deserialization mechanism.
|
||||||
|
* @param aInStream input stream
|
||||||
|
* @throws IOException exception
|
||||||
|
* @throws ClassNotFoundException exception
|
||||||
|
*/
|
||||||
|
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||||
|
deserialize(aInStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an account as a base64 string.<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
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected String serialize(String aKey, StringBuffer aErrorMsg) {
|
||||||
|
String pickleRetValue = null;
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
if(null == aErrorMsg) {
|
||||||
|
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
|
||||||
|
} else if(TextUtils.isEmpty(aKey)) {
|
||||||
|
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
|
||||||
|
} else {
|
||||||
|
aErrorMsg.setLength(0);
|
||||||
|
try {
|
||||||
|
pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
|
||||||
|
aErrorMsg.append(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pickleRetValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private native byte[] serializeJni(byte[] aKey, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an account from a pickled base64 string.<br>
|
||||||
|
* See {@link #serialize(String, 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 {
|
||||||
|
if (!createNewAccount()) {
|
||||||
|
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer errorMsg = new StringBuffer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String jniError;
|
||||||
|
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(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")))) {
|
||||||
|
errorMsg.append(jniError);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
|
||||||
|
errorMsg.append(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg.length() > 0) {
|
||||||
|
releaseAccount();
|
||||||
|
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private native String deserializeJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,13 +65,13 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
* Constructor.<br>
|
* Constructor.<br>
|
||||||
* Create and save a new native session instance ID and start a new inbound group session.
|
* Create and save a new native session instance ID and start a new inbound group session.
|
||||||
* The session key parameter is retrieved from an outbound group session
|
* The session key parameter is retrieved from an outbound group session
|
||||||
* See {@link #createNewSession()} and {@link #initInboundGroupSessionWithSessionKey(String)}
|
* See {@link #createNewSession()} and {@link #initInboundGroupSession(String)}
|
||||||
* @param aSessionKey session key
|
* @param aSessionKey session key
|
||||||
* @throws OlmException constructor failure
|
* @throws OlmException constructor failure
|
||||||
*/
|
*/
|
||||||
public OlmInboundGroupSession(String aSessionKey) throws OlmException {
|
public OlmInboundGroupSession(String aSessionKey) throws OlmException {
|
||||||
if(createNewSession()) {
|
if(createNewSession()) {
|
||||||
if (0 != initInboundGroupSessionWithSessionKey(aSessionKey)) {
|
if (0 != initInboundGroupSession(aSessionKey)) {
|
||||||
releaseSession();// prevent memory leak before throwing
|
releaseSession();// prevent memory leak before throwing
|
||||||
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION,OlmException.EXCEPTION_MSG_INIT_INBOUND_GROUP_SESSION);
|
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION,OlmException.EXCEPTION_MSG_INIT_INBOUND_GROUP_SESSION);
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,14 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
*/
|
*/
|
||||||
private native long createNewSessionJni();
|
private native long createNewSessionJni();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true the object resources have been released.<br>
|
||||||
|
* @return true the object resources have been released
|
||||||
|
*/
|
||||||
|
public boolean isReleased() {
|
||||||
|
return (0 == mNativeId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a new inbound group session.<br>
|
* Start a new inbound group session.<br>
|
||||||
* The session key parameter is retrieved from an outbound group session
|
* The session key parameter is retrieved from an outbound group session
|
||||||
|
@ -121,23 +129,23 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
* @param aSessionKey session key
|
* @param aSessionKey session key
|
||||||
* @return 0 if operation succeed, -1 otherwise
|
* @return 0 if operation succeed, -1 otherwise
|
||||||
*/
|
*/
|
||||||
private int initInboundGroupSessionWithSessionKey(String aSessionKey) {
|
private int initInboundGroupSession(String aSessionKey) {
|
||||||
int retCode = -1;
|
int retCode = -1;
|
||||||
|
|
||||||
if(TextUtils.isEmpty(aSessionKey)){
|
if(TextUtils.isEmpty(aSessionKey)){
|
||||||
Log.e(LOG_TAG, "## initInboundGroupSessionWithSessionKey(): invalid session key");
|
Log.e(LOG_TAG, "## initInboundGroupSession(): invalid session key");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
retCode = initInboundGroupSessionWithSessionKeyJni(aSessionKey.getBytes("UTF-8"));
|
retCode = initInboundGroupSessionJni(aSessionKey.getBytes("UTF-8"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## initInboundGroupSessionWithSessionKey() failed " + e.getMessage());
|
Log.e(LOG_TAG, "## initInboundGroupSession() failed " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retCode;
|
return retCode;
|
||||||
}
|
}
|
||||||
private native int initInboundGroupSessionWithSessionKeyJni(byte[] aSessionKeyBuffer);
|
|
||||||
|
|
||||||
|
private native int initInboundGroupSessionJni(byte[] aSessionKeyBuffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the base64-encoded identifier for this inbound group session.
|
* Retrieve the base64-encoded identifier for this inbound group session.
|
||||||
|
@ -187,13 +195,17 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
|
|
||||||
private native byte[] decryptMessageJni(byte[] aEncryptedMsg, DecryptMessageResult aDecryptMessageResult, StringBuffer aErrorMsg);
|
private native byte[] decryptMessageJni(byte[] aEncryptedMsg, DecryptMessageResult aDecryptMessageResult, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
//==============================================================================================================
|
||||||
|
// Serialization management
|
||||||
|
//==============================================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick off the serialization mechanism.
|
* Kick off the serialization mechanism.
|
||||||
* @param aOutStream output stream for serializing
|
* @param aOutStream output stream for serializing
|
||||||
* @throws IOException exception
|
* @throws IOException exception
|
||||||
*/
|
*/
|
||||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||||
serializeObject(aOutStream);
|
serialize(aOutStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,17 +215,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
* @throws ClassNotFoundException exception
|
* @throws ClassNotFoundException exception
|
||||||
*/
|
*/
|
||||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||||
deserializeObject(aInStream);
|
deserialize(aInStream);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean createNewObjectFromSerialization() {
|
|
||||||
return createNewSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void releaseObjectFromSerialization() {
|
|
||||||
releaseSession();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,20 +228,20 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
* @return pickled base64 string if operation succeed, null otherwise
|
* @return pickled base64 string if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
|
protected String serialize(String aKey, StringBuffer aErrorMsg) {
|
||||||
String pickleRetValue = null;
|
String 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,"## serialize(): invalid parameter - aErrorMsg=null");
|
||||||
} else if(TextUtils.isEmpty(aKey)) {
|
} else if(TextUtils.isEmpty(aKey)) {
|
||||||
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
|
aErrorMsg.append("Invalid input parameters in serialize()");
|
||||||
} else {
|
} else {
|
||||||
aErrorMsg.setLength(0);
|
aErrorMsg.setLength(0);
|
||||||
try {
|
try {
|
||||||
pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
|
pickleRetValue = new String(serializeJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
|
Log.e(LOG_TAG, "## serialize() failed " + e.getMessage());
|
||||||
aErrorMsg.append(e.getMessage());
|
aErrorMsg.append(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,60 +249,51 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
return pickleRetValue;
|
return pickleRetValue;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* JNI counter part of {@link #serializeDataWithKey(String, StringBuffer)}.
|
* JNI counter part of {@link #serialize(String, StringBuffer)}.
|
||||||
* @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 string if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
|
private native byte[] serializeJni(byte[] aKey, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an inbound group session from a pickled base64 string.<br>
|
* Loads an account from a pickled base64 string.<br>
|
||||||
* See {@link #serializeDataWithKey(String, StringBuffer)}
|
* See {@link #serialize(String, StringBuffer)}
|
||||||
* @param aSerializedData pickled inbound group session in a base64 string format
|
* @param aSerializedData pickled account in a base64 string format
|
||||||
* @param aKey encrypting key used in {@link #serializeDataWithKey(String, StringBuffer)}
|
* @param aKey key used to encrypted
|
||||||
* @param aErrorMsg error message description
|
|
||||||
* @return true if operation succeed, false otherwise
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
|
protected void deserialize(String aSerializedData, String aKey) throws IOException {
|
||||||
boolean retCode = false;
|
if (!createNewSession()) {
|
||||||
String jniError;
|
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer errorMsg = new StringBuffer();
|
||||||
|
|
||||||
if(null == aErrorMsg) {
|
|
||||||
Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
|
|
||||||
} else {
|
|
||||||
aErrorMsg.setLength(0);
|
|
||||||
try {
|
try {
|
||||||
|
String jniError;
|
||||||
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, "## deserialize(): invalid input parameters");
|
||||||
} else if (null == (jniError = initWithSerializedDataJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
|
errorMsg.append("invalid input parameters");
|
||||||
retCode = true;
|
} else if (null != (jniError = deserializeJni(aSerializedData.getBytes("UTF-8"), aKey.getBytes("UTF-8")))) {
|
||||||
} else {
|
errorMsg.append(jniError);
|
||||||
aErrorMsg.append(jniError);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## initWithSerializedData() failed " + e.getMessage());
|
Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
|
||||||
aErrorMsg.append(e.getMessage());
|
errorMsg.append(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg.length() > 0) {
|
||||||
|
releaseSession();
|
||||||
|
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return retCode;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* JNI counter part of {@link #initWithSerializedData(String, String, StringBuffer)}.
|
* JNI counter part of {@link #deserialize(String, String)}.
|
||||||
* @param aSerializedData pickled session in a base64 string format
|
* @param aSerializedData pickled session in a base64 string format
|
||||||
* @param aKey key used to encrypted in {@link #serializeDataWithKey(String, StringBuffer)}
|
* @param aKey key used to encrypted in {@link #serialize(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(byte[] aSerializedData, byte[] aKey);
|
private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true the object resources have been released.<br>
|
|
||||||
* @return true the object resources have been released
|
|
||||||
*/
|
|
||||||
public boolean isReleased() {
|
|
||||||
return (0 == mNativeId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,105 +69,6 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Kick off the serialization mechanism.
|
|
||||||
* @param aOutStream output stream for serializing
|
|
||||||
* @throws IOException exception
|
|
||||||
*/
|
|
||||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
|
||||||
serializeObject(aOutStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kick off the deserialization mechanism.
|
|
||||||
* @param aInStream input stream
|
|
||||||
* @throws IOException exception
|
|
||||||
* @throws ClassNotFoundException exception
|
|
||||||
*/
|
|
||||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
|
||||||
deserializeObject(aInStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean createNewObjectFromSerialization() {
|
|
||||||
return createNewSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void releaseObjectFromSerialization() {
|
|
||||||
releaseSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the current outbound group session as a base64 serialized string.<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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
|
|
||||||
String pickleRetValue = null;
|
|
||||||
|
|
||||||
// sanity check
|
|
||||||
if(null == aErrorMsg) {
|
|
||||||
Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
|
|
||||||
} else if(TextUtils.isEmpty(aKey)) {
|
|
||||||
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
|
|
||||||
} else {
|
|
||||||
aErrorMsg.setLength(0);
|
|
||||||
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(byte[] aKey, StringBuffer aErrorMsg);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load an outbound group session from a pickled base64 string.<br>
|
|
||||||
* See {@link #serializeDataWithKey(String, StringBuffer)}
|
|
||||||
* @param aSerializedData pickled outbound group session in a base64 string format
|
|
||||||
* @param aKey encrypting key used in {@link #serializeDataWithKey(String, StringBuffer)}
|
|
||||||
* @param aErrorMsg error message description
|
|
||||||
* @return true if operation succeed, false otherwise
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
|
|
||||||
boolean retCode = false;
|
|
||||||
String jniError;
|
|
||||||
|
|
||||||
if(null == aErrorMsg) {
|
|
||||||
Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
|
|
||||||
} else {
|
|
||||||
aErrorMsg.setLength(0);
|
|
||||||
|
|
||||||
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(byte[] aSerializedData, byte[] aKey);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release native session and invalid its JAVA reference counter part.<br>
|
* Release native session and invalid its JAVA reference counter part.<br>
|
||||||
* Public API for {@link #releaseSessionJni()}.
|
* Public API for {@link #releaseSessionJni()}.
|
||||||
|
@ -203,6 +104,14 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
|
||||||
*/
|
*/
|
||||||
private native long createNewSessionJni();
|
private native long createNewSessionJni();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true the object resources have been released.<br>
|
||||||
|
* @return true the object resources have been released
|
||||||
|
*/
|
||||||
|
public boolean isReleased() {
|
||||||
|
return (0 == mNativeId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a new outbound group session.<br>
|
* Start a new outbound group session.<br>
|
||||||
* @return 0 if operation succeed, -1 otherwise
|
* @return 0 if operation succeed, -1 otherwise
|
||||||
|
@ -290,11 +199,96 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
|
||||||
}
|
}
|
||||||
private native byte[] encryptMessageJni(byte[] aClearMsgBuffer, StringBuffer aErrorMsg);
|
private native byte[] encryptMessageJni(byte[] aClearMsgBuffer, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
|
||||||
|
//==============================================================================================================
|
||||||
|
// Serialization management
|
||||||
|
//==============================================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true the object resources have been released.<br>
|
* Kick off the serialization mechanism.
|
||||||
* @return true the object resources have been released
|
* @param aOutStream output stream for serializing
|
||||||
|
* @throws IOException exception
|
||||||
*/
|
*/
|
||||||
public boolean isReleased() {
|
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||||
return (0 == mNativeId);
|
serialize(aOutStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kick off the deserialization mechanism.
|
||||||
|
* @param aInStream input stream
|
||||||
|
* @throws IOException exception
|
||||||
|
* @throws ClassNotFoundException exception
|
||||||
|
*/
|
||||||
|
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||||
|
deserialize(aInStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current outbound group session as a base64 serialized string.<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
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected String serialize(String aKey, StringBuffer aErrorMsg) {
|
||||||
|
String pickleRetValue = null;
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
if(null == aErrorMsg) {
|
||||||
|
Log.e(LOG_TAG,"## serialize(): invalid parameter - aErrorMsg=null");
|
||||||
|
} else if(TextUtils.isEmpty(aKey)) {
|
||||||
|
aErrorMsg.append("Invalid input parameters in serialize()");
|
||||||
|
} else {
|
||||||
|
aErrorMsg.setLength(0);
|
||||||
|
try {
|
||||||
|
pickleRetValue = serializeJni(aKey.getBytes("UTF-8"), aErrorMsg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG,"## serialize(): failed " + e.getMessage());
|
||||||
|
aErrorMsg.append(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pickleRetValue;
|
||||||
|
}
|
||||||
|
private native String serializeJni(byte[] aKey, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an account from a pickled base64 string.<br>
|
||||||
|
* See {@link #serialize(String, 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 {
|
||||||
|
if (!createNewSession()) {
|
||||||
|
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer errorMsg = new StringBuffer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String jniError;
|
||||||
|
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(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")))) {
|
||||||
|
errorMsg.append(jniError);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
|
||||||
|
errorMsg.append(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg.length() > 0) {
|
||||||
|
releaseSession();
|
||||||
|
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,8 @@ import java.io.Serializable;
|
||||||
/**
|
/**
|
||||||
* Session class used to create Olm sessions in conjunction with {@link OlmAccount} class.<br>
|
* Session class used to create Olm sessions in conjunction with {@link OlmAccount} class.<br>
|
||||||
* Olm session is used to encrypt data between devices, especially to create Olm group sessions (see {@link OlmOutboundGroupSession} and {@link OlmInboundGroupSession}).<br>
|
* Olm session is used to encrypt data between devices, especially to create Olm group sessions (see {@link OlmOutboundGroupSession} and {@link OlmInboundGroupSession}).<br>
|
||||||
* To establish an Olm session with Bob, Alice calls {@link #initOutboundSessionWithAccount(OlmAccount, String, String)} with Bob's identity and onetime keys. Then Alice generates an encrypted PRE_KEY message ({@link #encryptMessage(String)})
|
* To establish an Olm session with Bob, Alice calls {@link #initOutboundSession(OlmAccount, String, String)} with Bob's identity and onetime keys. Then Alice generates an encrypted PRE_KEY message ({@link #encryptMessage(String)})
|
||||||
* used by Bob to open the Olm session in his side with {@link #initOutboundSessionWithAccount(OlmAccount, String, String)}.
|
* used by Bob to open the Olm session in his side with {@link #initOutboundSession(OlmAccount, String, String)}.
|
||||||
* From this step on, messages can be exchanged by using {@link #encryptMessage(String)} and {@link #decryptMessage(OlmMessage)}.
|
* From this step on, messages can be exchanged by using {@link #encryptMessage(String)} and {@link #decryptMessage(OlmMessage)}.
|
||||||
* <br><br>Detailed implementation guide is available at <a href="http://matrix.org/docs/guides/e2e_implementation.html">Implementing End-to-End Encryption in Matrix clients</a>.
|
* <br><br>Detailed implementation guide is available at <a href="http://matrix.org/docs/guides/e2e_implementation.html">Implementing End-to-End Encryption in Matrix clients</a>.
|
||||||
*/
|
*/
|
||||||
|
@ -48,104 +48,6 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Kick off the serialization mechanism.
|
|
||||||
* @param aOutStream output stream for serializing
|
|
||||||
* @throws IOException exception
|
|
||||||
*/
|
|
||||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
|
||||||
serializeObject(aOutStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Kick off the deserialization mechanism.
|
|
||||||
* @param aInStream input stream
|
|
||||||
* @throws IOException exception
|
|
||||||
* @throws ClassNotFoundException exception
|
|
||||||
*/
|
|
||||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
|
||||||
deserializeObject(aInStream);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean createNewObjectFromSerialization() {
|
|
||||||
return createNewSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void releaseObjectFromSerialization() {
|
|
||||||
releaseSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a session as a base64 string.<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
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected String serializeDataWithKey(String aKey, StringBuffer aErrorMsg) {
|
|
||||||
String pickleRetValue = null;
|
|
||||||
|
|
||||||
// sanity check
|
|
||||||
if(null == aErrorMsg) {
|
|
||||||
Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
|
|
||||||
} else if(TextUtils.isEmpty(aKey)) {
|
|
||||||
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
|
|
||||||
} else {
|
|
||||||
aErrorMsg.setLength(0);
|
|
||||||
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(byte[] aKey, StringBuffer aErrorMsg);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads a session from a pickled base64 string.<br>
|
|
||||||
* See {@link #serializeDataWithKey(String, StringBuffer)}
|
|
||||||
* @param aSerializedData pickled account in a base64 string format
|
|
||||||
* @param aKey key used to encrypted
|
|
||||||
* @param aErrorMsg error message description
|
|
||||||
* @return true if operation succeed, false otherwise
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected boolean initWithSerializedData(String aSerializedData, String aKey, StringBuffer aErrorMsg) {
|
|
||||||
boolean retCode = false;
|
|
||||||
String jniError;
|
|
||||||
|
|
||||||
if(null == aErrorMsg) {
|
|
||||||
Log.e(LOG_TAG, "## initWithSerializedData(): invalid input error parameter");
|
|
||||||
} else {
|
|
||||||
aErrorMsg.setLength(0);
|
|
||||||
|
|
||||||
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(byte[] aSerializedData, byte[] aKey);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter on the session ID.
|
* Getter on the session ID.
|
||||||
* @return native session ID
|
* @return native session ID
|
||||||
|
@ -189,7 +91,6 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
*/
|
*/
|
||||||
private native long initNewSessionJni();
|
private native long initNewSessionJni();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a native account instance without any initialization.<br>
|
* Create a native account instance without any initialization.<br>
|
||||||
* Since the account is left uninitialized, this
|
* Since the account is left uninitialized, this
|
||||||
|
@ -209,6 +110,14 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
*/
|
*/
|
||||||
private native long createNewSessionJni();
|
private native long createNewSessionJni();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true the object resources have been released.<br>
|
||||||
|
* @return true the object resources have been released
|
||||||
|
*/
|
||||||
|
public boolean isReleased() {
|
||||||
|
return (0 == mNativeId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new out-bound session for sending messages to a recipient
|
* Creates a new out-bound session for sending messages to a recipient
|
||||||
* identified by an identity key and a one time key.<br>
|
* identified by an identity key and a one time key.<br>
|
||||||
|
@ -217,7 +126,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
* @param aTheirOneTimeKey the one time key of the recipient
|
* @param aTheirOneTimeKey the one time key of the recipient
|
||||||
* @return 0 if operation succeed, -1 otherwise
|
* @return 0 if operation succeed, -1 otherwise
|
||||||
*/
|
*/
|
||||||
public int initOutboundSessionWithAccount(OlmAccount aAccount, String aTheirIdentityKey, String aTheirOneTimeKey) {
|
public int initOutboundSession(OlmAccount aAccount, String aTheirIdentityKey, String aTheirOneTimeKey) {
|
||||||
int retCode=-1;
|
int retCode=-1;
|
||||||
|
|
||||||
if ((null == aAccount) || TextUtils.isEmpty(aTheirIdentityKey) || TextUtils.isEmpty(aTheirOneTimeKey)) {
|
if ((null == aAccount) || TextUtils.isEmpty(aTheirIdentityKey) || TextUtils.isEmpty(aTheirOneTimeKey)) {
|
||||||
|
@ -226,7 +135,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
try {
|
try {
|
||||||
retCode = initOutboundSessionJni(aAccount.getOlmAccountId(), aTheirIdentityKey.getBytes("UTF-8"), aTheirOneTimeKey.getBytes("UTF-8"));
|
retCode = initOutboundSessionJni(aAccount.getOlmAccountId(), aTheirIdentityKey.getBytes("UTF-8"), aTheirOneTimeKey.getBytes("UTF-8"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## initOutboundSessionWithAccount(): " + e.getMessage());
|
Log.e(LOG_TAG, "## initOutboundSession(): " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,9 +152,9 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
* @param aPreKeyMsg PRE KEY message
|
* @param aPreKeyMsg PRE KEY message
|
||||||
* @exception Exception the failure reason
|
* @exception Exception the failure reason
|
||||||
*/
|
*/
|
||||||
public void initInboundSessionWithAccount(OlmAccount aAccount, String aPreKeyMsg) throws Exception {
|
public void initInboundSession(OlmAccount aAccount, String aPreKeyMsg) throws Exception {
|
||||||
if ((null == aAccount) || TextUtils.isEmpty(aPreKeyMsg)){
|
if ((null == aAccount) || TextUtils.isEmpty(aPreKeyMsg)){
|
||||||
Log.e(LOG_TAG, "## initInboundSessionWithAccount(): invalid input parameters");
|
Log.e(LOG_TAG, "## initInboundSession(): invalid input parameters");
|
||||||
throw new Exception("invalid input parameters");
|
throw new Exception("invalid input parameters");
|
||||||
} else {
|
} else {
|
||||||
StringBuffer errorMsg = new StringBuffer();
|
StringBuffer errorMsg = new StringBuffer();
|
||||||
|
@ -253,7 +162,7 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
try {
|
try {
|
||||||
initInboundSessionJni(aAccount.getOlmAccountId(), aPreKeyMsg.getBytes("UTF-8"), errorMsg);
|
initInboundSessionJni(aAccount.getOlmAccountId(), aPreKeyMsg.getBytes("UTF-8"), errorMsg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## initInboundSessionWithAccount(): " + e.getMessage());
|
Log.e(LOG_TAG, "## initInboundSession(): " + e.getMessage());
|
||||||
errorMsg.append(errorMsg);
|
errorMsg.append(errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,16 +185,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
* @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 initInboundSessionWithAccountFrom(OlmAccount aAccount, String aTheirIdentityKey, String aPreKeyMsg) {
|
public int initInboundSessionFrom(OlmAccount aAccount, String aTheirIdentityKey, 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, "## initInboundSessionFrom(): invalid input parameters");
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
retCode = initInboundSessionFromIdKeyJni(aAccount.getOlmAccountId(), aTheirIdentityKey.getBytes("UTF-8"), aPreKeyMsg.getBytes("UTF-8"));
|
retCode = initInboundSessionFromIdKeyJni(aAccount.getOlmAccountId(), aTheirIdentityKey.getBytes("UTF-8"), aPreKeyMsg.getBytes("UTF-8"));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## initInboundSessionWithAccountFrom(): " + e.getMessage());
|
Log.e(LOG_TAG, "## initInboundSessionFrom(): " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,12 +309,94 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
|
|
||||||
private native byte[] decryptMessageJni(OlmMessage aEncryptedMsg);
|
private native byte[] decryptMessageJni(OlmMessage aEncryptedMsg);
|
||||||
|
|
||||||
|
//==============================================================================================================
|
||||||
|
// Serialization management
|
||||||
|
//==============================================================================================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true the object resources have been released.<br>
|
* Kick off the serialization mechanism.
|
||||||
* @return true the object resources have been released
|
* @param aOutStream output stream for serializing
|
||||||
|
* @throws IOException exception
|
||||||
*/
|
*/
|
||||||
public boolean isReleased() {
|
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||||
return (0 == mNativeId);
|
serialize(aOutStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kick off the deserialization mechanism.
|
||||||
|
* @param aInStream input stream
|
||||||
|
* @throws IOException exception
|
||||||
|
* @throws ClassNotFoundException exception
|
||||||
|
*/
|
||||||
|
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||||
|
deserialize(aInStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a session as a base64 string.<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
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected String serialize(String aKey, StringBuffer aErrorMsg) {
|
||||||
|
String pickleRetValue = null;
|
||||||
|
|
||||||
|
// sanity check
|
||||||
|
if(null == aErrorMsg) {
|
||||||
|
Log.e(LOG_TAG,"## serializeDataWithKey(): invalid parameter - aErrorMsg=null");
|
||||||
|
} else if(TextUtils.isEmpty(aKey)) {
|
||||||
|
aErrorMsg.append("Invalid input parameters in serializeDataWithKey()");
|
||||||
|
} else {
|
||||||
|
aErrorMsg.setLength(0);
|
||||||
|
try {
|
||||||
|
pickleRetValue = serializeJni(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 serializeJni(byte[] aKey, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads an account from a pickled base64 string.<br>
|
||||||
|
* See {@link #serialize(String, 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 {
|
||||||
|
if (!createNewSession()) {
|
||||||
|
throw new OlmException(OlmException.EXCEPTION_CODE_INIT_ACCOUNT_CREATION,OlmException.EXCEPTION_MSG_INIT_ACCOUNT_CREATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer errorMsg = new StringBuffer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String jniError;
|
||||||
|
if (TextUtils.isEmpty(aSerializedData) || TextUtils.isEmpty(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")))) {
|
||||||
|
errorMsg.append(jniError);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## deserialize() failed " + e.getMessage());
|
||||||
|
errorMsg.append(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMsg.length() > 0) {
|
||||||
|
releaseSession();
|
||||||
|
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, String.valueOf(errorMsg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private native String deserializeJni(byte[] aSerializedData, byte[] aKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -476,7 +476,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject t
|
||||||
* @param[out] aErrorMsg error message set if operation failed
|
* @param[out] aErrorMsg error message set if operation failed
|
||||||
* @return a base64 string if operation succeed, null otherwise
|
* @return a base64 string if operation succeed, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
||||||
{
|
{
|
||||||
jbyteArray pickledDataRetValue = 0;
|
jbyteArray pickledDataRetValue = 0;
|
||||||
jclass errorMsgJClass = 0;
|
jclass errorMsgJClass = 0;
|
||||||
|
@ -485,44 +485,44 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env,
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
OlmAccount* accountPtr = NULL;
|
OlmAccount* accountPtr = NULL;
|
||||||
|
|
||||||
LOGD("## serializeDataWithKeyJni(): IN");
|
LOGD("## serializeJni(): IN");
|
||||||
|
|
||||||
if (!aKeyBuffer)
|
if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
|
LOGE(" ## serializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aErrorMsg)
|
else if (!aErrorMsg)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
|
LOGE(" ## serializeJni(): failure - invalid error object");
|
||||||
}
|
}
|
||||||
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
|
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid account ptr");
|
LOGE(" ## serializeJni(): failure - invalid account ptr");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
|
LOGE(" ## serializeJni(): failure - unable to get error class");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
|
LOGE(" ## serializeJni(): failure - unable to get error method ID");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, NULL)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, NULL)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## serializeDataWithKeyJni(): 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(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
|
||||||
|
|
||||||
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
||||||
|
|
||||||
if (!pickledPtr)
|
if (!pickledPtr)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
|
LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -534,7 +534,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env,
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_account_last_error(accountPtr);
|
const char *errorMsgPtr = olm_account_last_error(accountPtr);
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_account() Msg=%s",errorMsgPtr);
|
LOGE(" ## serializeJni(): failure - olm_pickle_account() Msg=%s",errorMsgPtr);
|
||||||
|
|
||||||
if(0 != (errorJstring = env->NewStringUTF(errorMsgPtr)))
|
if(0 != (errorJstring = env->NewStringUTF(errorMsgPtr)))
|
||||||
{
|
{
|
||||||
|
@ -546,7 +546,7 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(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');
|
||||||
|
|
||||||
LOGD(" ## serializeDataWithKeyJni(): 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+1);
|
||||||
env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength+1, (jbyte*)pickledPtr);
|
env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength+1, (jbyte*)pickledPtr);
|
||||||
|
@ -566,42 +566,42 @@ JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
|
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
|
||||||
{
|
{
|
||||||
OlmAccount* accountPtr = NULL;
|
OlmAccount* accountPtr = NULL;
|
||||||
jstring errorMessageRetValue = 0;
|
jstring errorMessageRetValue = 0;
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
jbyte* pickledPtr = NULL;
|
jbyte* pickledPtr = NULL;
|
||||||
|
|
||||||
LOGD("## initWithSerializedDataJni(): IN");
|
LOGD("## deserializeJni(): IN");
|
||||||
|
|
||||||
if (!aKeyBuffer)
|
if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
|
LOGE(" ## deserializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aSerializedDataBuffer)
|
else if (!aSerializedDataBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
|
LOGE(" ## deserializeJni(): failure - serialized data");
|
||||||
}
|
}
|
||||||
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
|
else if (!(accountPtr = (OlmAccount*)getAccountInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - account failure OOM");
|
LOGE(" ## deserializeJni(): failure - account failure OOM");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## initWithSerializedDataJni(): 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(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
|
||||||
LOGD(" ## initWithSerializedDataJni(): 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,
|
||||||
(void const *)keyPtr,
|
(void const *)keyPtr,
|
||||||
|
@ -611,12 +611,12 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_account_last_error(accountPtr);
|
const char *errorMsgPtr = olm_account_last_error(accountPtr);
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
|
LOGE(" ## deserializeJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
|
||||||
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
|
||||||
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);
|
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
|
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
|
||||||
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer);
|
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,41 +86,41 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *
|
||||||
* @param aSessionKey session key from an outbound session
|
* @param aSessionKey session key from an outbound session
|
||||||
* @return ERROR_CODE_OK if operation succeed, ERROR_CODE_KO otherwise
|
* @return ERROR_CODE_OK if operation succeed, ERROR_CODE_KO otherwise
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer)
|
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer)
|
||||||
{
|
{
|
||||||
jint retCode = ERROR_CODE_KO;
|
jint retCode = ERROR_CODE_KO;
|
||||||
OlmInboundGroupSession *sessionPtr = NULL;
|
OlmInboundGroupSession *sessionPtr = NULL;
|
||||||
jbyte* sessionKeyPtr = NULL;
|
jbyte* sessionKeyPtr = NULL;
|
||||||
size_t sessionResult;
|
size_t sessionResult;
|
||||||
|
|
||||||
LOGD("## initInboundGroupSessionWithSessionKeyJni(): inbound group session IN");
|
LOGD("## initInboundGroupSessionJni(): inbound group session IN");
|
||||||
|
|
||||||
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid inbound group session instance");
|
LOGE(" ## initInboundGroupSessionJni(): failure - invalid inbound group session instance");
|
||||||
}
|
}
|
||||||
else if (!aSessionKeyBuffer)
|
else if (!aSessionKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initInboundGroupSessionWithSessionKeyJni(): failure - invalid aSessionKey");
|
LOGE(" ## initInboundGroupSessionJni(): failure - invalid aSessionKey");
|
||||||
}
|
}
|
||||||
else if (!(sessionKeyPtr = env->GetByteArrayElements(aSessionKeyBuffer, 0)))
|
else if (!(sessionKeyPtr = env->GetByteArrayElements(aSessionKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initInboundSessionFromIdKeyJni(): failure - session key JNI allocation OOM");
|
LOGE(" ## initInboundGroupSessionJni(): failure - session key JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
size_t sessionKeyLength = (size_t)env->GetArrayLength(aSessionKeyBuffer);
|
size_t sessionKeyLength = (size_t)env->GetArrayLength(aSessionKeyBuffer);
|
||||||
LOGD(" ## initInboundSessionFromIdKeyJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
|
LOGD(" ## initInboundGroupSessionJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
|
||||||
|
|
||||||
sessionResult = olm_init_inbound_group_session(sessionPtr, (const uint8_t*)sessionKeyPtr, sessionKeyLength);
|
sessionResult = olm_init_inbound_group_session(sessionPtr, (const uint8_t*)sessionKeyPtr, sessionKeyLength);
|
||||||
if (sessionResult == olm_error()) {
|
if (sessionResult == olm_error()) {
|
||||||
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
|
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
|
||||||
LOGE(" ## initInboundSessionFromIdKeyJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
|
LOGE(" ## initInboundGroupSessionJni(): failure - init inbound session creation Msg=%s",errorMsgPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retCode = ERROR_CODE_OK;
|
retCode = ERROR_CODE_OK;
|
||||||
LOGD(" ## initInboundSessionFromIdKeyJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
|
LOGD(" ## initInboundGroupSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEn
|
||||||
* @param[out] aErrorMsg error message set if operation failed
|
* @param[out] aErrorMsg error message set if operation failed
|
||||||
* @return a base64 string if operation succeed, null otherwise
|
* @return a base64 string if operation succeed, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
||||||
{
|
{
|
||||||
jbyteArray pickledDataRet = 0;
|
jbyteArray pickledDataRet = 0;
|
||||||
|
|
||||||
|
@ -346,44 +346,44 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
OlmInboundGroupSession* sessionPtr = NULL;
|
OlmInboundGroupSession* sessionPtr = NULL;
|
||||||
|
|
||||||
LOGD("## inbound group session serializeDataWithKeyJni(): IN");
|
LOGD("## inbound group session serializeJni(): IN");
|
||||||
|
|
||||||
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
|
LOGE(" ## serializeJni(): failure - invalid session ptr");
|
||||||
}
|
}
|
||||||
else if (!aKeyBuffer)
|
else if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
|
LOGE(" ## serializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aErrorMsg)
|
else if (!aErrorMsg)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
|
LOGE(" ## serializeJni(): failure - invalid error object");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
|
LOGE(" ## serializeJni(): failure - unable to get error class");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
|
LOGE(" ## serializeJni(): failure - unable to get error method ID");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## serializeDataWithKeyJni(): 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(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
|
||||||
|
|
||||||
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
||||||
|
|
||||||
if (!pickledPtr)
|
if (!pickledPtr)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
|
LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -395,7 +395,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
|
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
|
LOGE(" ## serializeJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
|
||||||
|
|
||||||
jstring errorJstring = env->NewStringUTF(errorMsgPtr);
|
jstring errorJstring = env->NewStringUTF(errorMsgPtr);
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
||||||
LOGD(" ## serializeDataWithKeyJni(): 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));
|
||||||
|
|
||||||
pickledDataRet = env->NewByteArray(pickledLength);
|
pickledDataRet = env->NewByteArray(pickledLength);
|
||||||
env->SetByteArrayRegion(pickledDataRet, 0 , pickledLength, (jbyte*)pickledPtr);
|
env->SetByteArrayRegion(pickledDataRet, 0 , pickledLength, (jbyte*)pickledPtr);
|
||||||
|
@ -427,42 +427,42 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
|
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
|
||||||
{
|
{
|
||||||
OlmInboundGroupSession* sessionPtr = NULL;
|
OlmInboundGroupSession* sessionPtr = NULL;
|
||||||
jstring errorMessageRetValue = 0;
|
jstring errorMessageRetValue = 0;
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
jbyte* pickledPtr = NULL;
|
jbyte* pickledPtr = NULL;
|
||||||
|
|
||||||
LOGD("## initWithSerializedDataJni(): IN");
|
LOGD("## deserializeJni(): IN");
|
||||||
|
|
||||||
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
if (!(sessionPtr = (OlmInboundGroupSession*)getInboundGroupSessionInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
|
LOGE(" ## deserializeJni(): failure - session failure OOM");
|
||||||
}
|
}
|
||||||
else if (!aKeyBuffer)
|
else if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
|
LOGE(" ## deserializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aSerializedDataBuffer)
|
else if (!aSerializedDataBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
|
LOGE(" ## deserializeJni(): failure - serialized data");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## initWithSerializedDataJni(): 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(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
|
||||||
LOGD(" ## initWithSerializedDataJni(): 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,
|
||||||
(void const *)keyPtr,
|
(void const *)keyPtr,
|
||||||
|
@ -472,12 +472,12 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
|
const char *errorMsgPtr = olm_inbound_group_session_last_error(sessionPtr);
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_inbound_group_session() Msg=%s",errorMsgPtr);
|
LOGE(" ## deserializeJni(): failure - olm_unpickle_inbound_group_session() Msg=%s",errorMsgPtr);
|
||||||
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,13 @@ extern "C" {
|
||||||
JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
|
||||||
|
|
||||||
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer);
|
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer);
|
||||||
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex, jobject aErrorMsg);
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex, jobject aErrorMsg);
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
|
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -372,7 +372,7 @@ JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIE
|
||||||
* @param[out] aErrorMsg error message set if operation failed
|
* @param[out] aErrorMsg error message set if operation failed
|
||||||
* @return a base64 string if operation succeed, null otherwise
|
* @return a base64 string if operation succeed, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
||||||
{
|
{
|
||||||
jstring pickledDataRetValue = 0;
|
jstring pickledDataRetValue = 0;
|
||||||
jclass errorMsgJClass = 0;
|
jclass errorMsgJClass = 0;
|
||||||
|
@ -381,44 +381,44 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
OlmOutboundGroupSession* sessionPtr = NULL;
|
OlmOutboundGroupSession* sessionPtr = NULL;
|
||||||
|
|
||||||
LOGD("## outbound group session serializeDataWithKeyJni(): IN");
|
LOGD("## outbound group session serializeJni(): IN");
|
||||||
|
|
||||||
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
|
LOGE(" ## serializeJni(): failure - invalid session ptr");
|
||||||
}
|
}
|
||||||
else if (!aKeyBuffer)
|
else if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
|
LOGE(" ## serializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aErrorMsg)
|
else if (!aErrorMsg)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
|
LOGE(" ## serializeJni(): failure - invalid error object");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
|
LOGE(" ## serializeJni(): failure - unable to get error class");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
|
LOGE(" ## serializeJni(): failure - unable to get error method ID");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## serializeDataWithKeyJni(): 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(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
|
||||||
|
|
||||||
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
||||||
|
|
||||||
if(!pickledPtr)
|
if(!pickledPtr)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
|
LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -430,7 +430,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
|
const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
|
LOGE(" ## serializeJni(): failure - olm_pickle_outbound_group_session() Msg=%s",errorMsgPtr);
|
||||||
|
|
||||||
if (!(errorJstring = env->NewStringUTF(errorMsgPtr)))
|
if (!(errorJstring = env->NewStringUTF(errorMsgPtr)))
|
||||||
{
|
{
|
||||||
|
@ -442,7 +442,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
||||||
// 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);
|
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
|
||||||
LOGD(" ## serializeDataWithKeyJni(): 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,42 +459,42 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(J
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
|
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
|
||||||
{
|
{
|
||||||
OlmOutboundGroupSession* sessionPtr = NULL;
|
OlmOutboundGroupSession* sessionPtr = NULL;
|
||||||
jstring errorMessageRetValue = 0;
|
jstring errorMessageRetValue = 0;
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
jbyte* pickledPtr = NULL;
|
jbyte* pickledPtr = NULL;
|
||||||
|
|
||||||
LOGD("## initWithSerializedDataJni(): IN");
|
LOGD("## deserializeJni(): IN");
|
||||||
|
|
||||||
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
|
LOGE(" ## deserializeJni(): failure - session failure OOM");
|
||||||
}
|
}
|
||||||
else if (!aKeyBuffer)
|
else if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
|
LOGE(" ## deserializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aSerializedDataBuffer)
|
else if (!aSerializedDataBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
|
LOGE(" ## deserializeJni(): failure - serialized data");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## initWithSerializedDataJni(): 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(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
|
||||||
LOGD(" ## initWithSerializedDataJni(): 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,
|
||||||
(void const *)keyPtr,
|
(void const *)keyPtr,
|
||||||
|
@ -504,12 +504,12 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
|
const char *errorMsgPtr = olm_outbound_group_session_last_error(sessionPtr);
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_outbound_group_session() Msg=%s",errorMsgPtr);
|
LOGE(" ## deserializeJni(): failure - olm_unpickle_outbound_group_session() Msg=%s",errorMsgPtr);
|
||||||
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,8 @@ 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, jobject aErrorMsg);
|
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer, jobject aErrorMsg);
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(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
|
||||||
}
|
}
|
||||||
|
|
|
@ -780,7 +780,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env,
|
||||||
* @param[out] aErrorMsg error message set if operation failed
|
* @param[out] aErrorMsg error message set if operation failed
|
||||||
* @return a base64 string if operation succeed, null otherwise
|
* @return a base64 string if operation succeed, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
||||||
{
|
{
|
||||||
jstring pickledDataRetValue = 0;
|
jstring pickledDataRetValue = 0;
|
||||||
jclass errorMsgJClass = 0;
|
jclass errorMsgJClass = 0;
|
||||||
|
@ -789,44 +789,44 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
OlmSession* sessionPtr = NULL;
|
OlmSession* sessionPtr = NULL;
|
||||||
|
|
||||||
LOGD("## serializeDataWithKeyJni(): IN");
|
LOGD("## serializeJni(): IN");
|
||||||
|
|
||||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid session ptr");
|
LOGE(" ## serializeJni(): failure - invalid session ptr");
|
||||||
}
|
}
|
||||||
else if (!aKeyBuffer)
|
else if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid key");
|
LOGE(" ## serializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aErrorMsg)
|
else if (!aErrorMsg)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - invalid error object");
|
LOGE(" ## serializeJni(): failure - invalid error object");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
else if (!(errorMsgJClass = env->GetObjectClass(aErrorMsg)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error class");
|
LOGE(" ## serializeJni(): failure - unable to get error class");
|
||||||
}
|
}
|
||||||
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
else if (!(errorMsgMethodId = env->GetMethodID(errorMsgJClass, "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;")))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - unable to get error method ID");
|
LOGE(" ## serializeJni(): failure - unable to get error method ID");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## serializeDataWithKeyJni(): 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(" ## serializeDataWithKeyJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## serializeJni(): key=%s",(char const *)keyPtr);
|
||||||
|
|
||||||
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
void *pickledPtr = malloc((pickledLength+1)*sizeof(uint8_t));
|
||||||
|
|
||||||
if (!pickledPtr)
|
if (!pickledPtr)
|
||||||
{
|
{
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - pickledPtr buffer OOM");
|
LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -838,7 +838,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_session_last_error(sessionPtr);
|
const char *errorMsgPtr = olm_session_last_error(sessionPtr);
|
||||||
LOGE(" ## serializeDataWithKeyJni(): failure - olm_pickle_session() Msg=%s",errorMsgPtr);
|
LOGE(" ## serializeJni(): failure - olm_pickle_session() Msg=%s",errorMsgPtr);
|
||||||
|
|
||||||
if ((errorJstring = env->NewStringUTF(errorMsgPtr)))
|
if ((errorJstring = env->NewStringUTF(errorMsgPtr)))
|
||||||
{
|
{
|
||||||
|
@ -850,7 +850,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
||||||
// build success output
|
// build success output
|
||||||
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
||||||
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
|
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
|
||||||
LOGD(" ## serializeDataWithKeyJni(): 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pickledPtr);
|
free(pickledPtr);
|
||||||
|
@ -867,42 +867,42 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(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;
|
||||||
jstring errorMessageRetValue = 0;
|
jstring errorMessageRetValue = 0;
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
jbyte* pickledPtr = NULL;
|
jbyte* pickledPtr = NULL;
|
||||||
|
|
||||||
LOGD("## initWithSerializedDataJni(): IN");
|
LOGD("## deserializeJni(): IN");
|
||||||
|
|
||||||
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
if (!(sessionPtr = (OlmSession*)getSessionInstanceId(env,thiz)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - session failure OOM");
|
LOGE(" ## deserializeJni(): failure - session failure OOM");
|
||||||
}
|
}
|
||||||
else if (!aKeyBuffer)
|
else if (!aKeyBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - invalid key");
|
LOGE(" ## deserializeJni(): failure - invalid key");
|
||||||
}
|
}
|
||||||
else if (!aSerializedDataBuffer)
|
else if (!aSerializedDataBuffer)
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - serialized data");
|
LOGE(" ## deserializeJni(): failure - serialized data");
|
||||||
}
|
}
|
||||||
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - keyPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
||||||
{
|
{
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - pickledPtr JNI allocation OOM");
|
LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
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(" ## initWithSerializedDataJni(): 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(" ## initWithSerializedDataJni(): key=%s",(char const *)keyPtr);
|
LOGD(" ## deserializeJni(): key=%s",(char const *)keyPtr);
|
||||||
LOGD(" ## initWithSerializedDataJni(): 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,
|
||||||
(void const *)keyPtr,
|
(void const *)keyPtr,
|
||||||
|
@ -912,14 +912,13 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, j
|
||||||
if (result == olm_error())
|
if (result == olm_error())
|
||||||
{
|
{
|
||||||
const char *errorMsgPtr = olm_session_last_error(sessionPtr);
|
const char *errorMsgPtr = olm_session_last_error(sessionPtr);
|
||||||
LOGE(" ## initWithSerializedDataJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
|
LOGE(" ## deserializeJni(): failure - olm_unpickle_account() Msg=%s",errorMsgPtr);
|
||||||
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGD(" ## initWithSerializedDataJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
LOGD(" ## initJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// free alloc
|
// free alloc
|
||||||
|
|
|
@ -50,8 +50,8 @@ 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(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(initWithSerializedDataJni)(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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue