Commit 03ae28e0 authored by ylecollen's avatar ylecollen
Browse files

Update after a new review

parent eeb210f7
...@@ -389,17 +389,12 @@ public class OlmAccountTest { ...@@ -389,17 +389,12 @@ public class OlmAccountTest {
assertTrue(e.getMessage(),false); assertTrue(e.getMessage(),false);
} }
boolean sessionRetCode = true;
try { try {
sessionRetCode = olmAccount.removeOneTimeKeys(null); olmAccount.removeOneTimeKeys(null);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); assertTrue(e.getMessage(), false);
} }
// test against no matching keys
assertFalse(sessionRetCode);
olmAccount.releaseAccount(); olmAccount.releaseAccount();
} }
......
...@@ -174,13 +174,11 @@ public class OlmSessionTest { ...@@ -174,13 +174,11 @@ public class OlmSessionTest {
assertTrue(clearMsg.equals(decryptedMsg)); assertTrue(clearMsg.equals(decryptedMsg));
// clean objects.. // clean objects..
boolean res = false;
try { try {
res = bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); assertTrue(e.getMessage(), false);
} }
assertTrue(res);
// release accounts // release accounts
bobAccount.releaseAccount(); bobAccount.releaseAccount();
...@@ -402,13 +400,11 @@ public class OlmSessionTest { ...@@ -402,13 +400,11 @@ public class OlmSessionTest {
assertTrue(clearMsg1.equals(decryptedMsg1)); assertTrue(clearMsg1.equals(decryptedMsg1));
// clean objects.. // clean objects..
boolean res = false;
try { try {
res = bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); assertTrue(e.getMessage(), false);
} }
assertTrue(res);
bobAccount.releaseAccount(); bobAccount.releaseAccount();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
...@@ -585,13 +581,11 @@ public class OlmSessionTest { ...@@ -585,13 +581,11 @@ public class OlmSessionTest {
//assertTrue(false==bobSession.matchesInboundSessionFrom(bobIdentityKey, encryptedAliceToBobMsg1.mCipherText)); //assertTrue(false==bobSession.matchesInboundSessionFrom(bobIdentityKey, encryptedAliceToBobMsg1.mCipherText));
// release objects // release objects
boolean res = false;
try { try {
res = bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); assertTrue(e.getMessage(), false);
} }
assertTrue(res);
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
...@@ -782,13 +776,11 @@ public class OlmSessionTest { ...@@ -782,13 +776,11 @@ public class OlmSessionTest {
assertTrue(clearMsg3.equals(decryptedMsg3)); assertTrue(clearMsg3.equals(decryptedMsg3));
// clean objects.. // clean objects..
boolean res = false;
try { try {
res = bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); assertTrue(e.getMessage(), false);
} }
assertTrue(res);
bobAccount.releaseAccount(); bobAccount.releaseAccount();
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
...@@ -1002,13 +994,11 @@ public class OlmSessionTest { ...@@ -1002,13 +994,11 @@ public class OlmSessionTest {
assertTrue(!aliceSession.matchesInboundSessionFrom(null,null)); assertTrue(!aliceSession.matchesInboundSessionFrom(null,null));
// release objects // release objects
boolean res = false;
try { try {
res = bobAccount.removeOneTimeKeys(bobSession); bobAccount.removeOneTimeKeys(bobSession);
} catch (Exception e) { } catch (Exception e) {
assertTrue(e.getMessage(), false); assertTrue(e.getMessage(), false);
} }
assertTrue(res);
aliceAccount.releaseAccount(); aliceAccount.releaseAccount();
bobAccount.releaseAccount(); bobAccount.releaseAccount();
......
...@@ -104,42 +104,34 @@ public class OlmUtilityTest { ...@@ -104,42 +104,34 @@ public class OlmUtilityTest {
} }
// verify signature // verify signature
boolean isVerified;
isVerified = false;
errorMsg = null; errorMsg = null;
try { try {
isVerified = utility.verifyEd25519Signature(messageSignature, fingerPrintKey, message); utility.verifyEd25519Signature(messageSignature, fingerPrintKey, message);
} catch (Exception e) { } catch (Exception e) {
errorMsg = e.getMessage(); errorMsg = e.getMessage();
} }
assertTrue(isVerified);
assertTrue(TextUtils.isEmpty(errorMsg)); assertTrue(TextUtils.isEmpty(errorMsg));
// check a bad signature is detected => errorMsg = BAD_MESSAGE_MAC // check a bad signature is detected => errorMsg = BAD_MESSAGE_MAC
String badSignature = "Bad signature Bad signature Bad signature.."; String badSignature = "Bad signature Bad signature Bad signature..";
isVerified = false;
errorMsg = null; errorMsg = null;
try { try {
isVerified = utility.verifyEd25519Signature(badSignature, fingerPrintKey, message); utility.verifyEd25519Signature(badSignature, fingerPrintKey, message);
} catch (Exception e) { } catch (Exception e) {
errorMsg = e.getMessage(); errorMsg = e.getMessage();
} }
assertFalse(isVerified);
assertTrue(!TextUtils.isEmpty(errorMsg)); assertTrue(!TextUtils.isEmpty(errorMsg));
// check bad fingerprint size => errorMsg = INVALID_BASE64 // check bad fingerprint size => errorMsg = INVALID_BASE64
String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length()/2); String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length()/2);
isVerified = false;
errorMsg = null; errorMsg = null;
try { try {
isVerified = utility.verifyEd25519Signature(messageSignature, badSizeFingerPrintKey, message); utility.verifyEd25519Signature(messageSignature, badSizeFingerPrintKey, message);
} catch (Exception e) { } catch (Exception e) {
errorMsg = e.getMessage(); errorMsg = e.getMessage();
} }
assertFalse(isVerified);
assertTrue(!TextUtils.isEmpty(errorMsg)); assertTrue(!TextUtils.isEmpty(errorMsg));
utility.releaseUtility(); utility.releaseUtility();
......
...@@ -70,17 +70,11 @@ abstract class CommonSerializeUtils { ...@@ -70,17 +70,11 @@ abstract class CommonSerializeUtils {
key = keyAsString.getBytes("UTF-8"); key = keyAsString.getBytes("UTF-8");
pickledData = pickledDataAsString.getBytes("UTF-8"); pickledData = pickledDataAsString.getBytes("UTF-8");
deserialize(pickledData, key);
} catch (Exception e) { } catch (Exception e) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, e.getMessage()); throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, e.getMessage());
} }
if (null == key) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" key");
} else if (null == pickledData) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_DESERIALIZATION, OlmException.EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION+" pickle");
}
deserialize(pickledData, key);
Log.d(LOG_TAG,"## deserializeObject(): success"); Log.d(LOG_TAG,"## deserializeObject(): success");
} }
......
...@@ -242,23 +242,16 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable { ...@@ -242,23 +242,16 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
/** /**
* Remove the "one time keys" that the session used from the account. * Remove the "one time keys" that the session used from the account.
* @param aSession session instance * @param aSession session instance
* @return true if the operation succeeded.
* @throws OlmException the failure reason * @throws OlmException the failure reason
*/ */
public boolean removeOneTimeKeys(OlmSession aSession) throws OlmException { public void removeOneTimeKeys(OlmSession aSession) throws OlmException {
boolean res = false;
if (null != aSession) { if (null != aSession) {
try { try {
removeOneTimeKeysJni(aSession.getOlmSessionId()); removeOneTimeKeysJni(aSession.getOlmSessionId());
res = true;
Log.d(LOG_TAG,"## removeOneTimeKeysForSession(): result=" + res);
} catch (Exception e) { } catch (Exception e) {
throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS, e.getMessage()); throw new OlmException(OlmException.EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS, e.getMessage());
} }
} }
return res;
} }
/** /**
......
...@@ -73,17 +73,14 @@ public class OlmUtility { ...@@ -73,17 +73,14 @@ public class OlmUtility {
/** /**
* Verify an ed25519 signature.<br> * Verify an ed25519 signature.<br>
* If the signature is verified, the method returns true. If false is returned, an error description is provided in aError. * An exception is thrown if the operation fails.
* If the key was too small, aError is set to "OLM.INVALID_BASE64".
* If the signature was invalid, aError is set to "OLM.BAD_MESSAGE_MAC".<br>
* @param aSignature the base64-encoded message signature to be checked. * @param aSignature the base64-encoded message signature to be checked.
* @param aFingerprintKey the ed25519 key (fingerprint key) * @param aFingerprintKey the ed25519 key (fingerprint key)
* @param aMessage the signed message * @param aMessage the signed message
* @return true if the signature is verified, false otherwise
* @exception OlmException the failure reason * @exception OlmException the failure reason
*/ */
public boolean verifyEd25519Signature(String aSignature, String aFingerprintKey, String aMessage) throws OlmException { public void verifyEd25519Signature(String aSignature, String aFingerprintKey, String aMessage) throws OlmException {
String errorMessage = null; String errorMessage;
try { try {
if (TextUtils.isEmpty(aSignature) || TextUtils.isEmpty(aFingerprintKey) || TextUtils.isEmpty(aMessage)) { if (TextUtils.isEmpty(aSignature) || TextUtils.isEmpty(aFingerprintKey) || TextUtils.isEmpty(aMessage)) {
...@@ -94,13 +91,12 @@ public class OlmUtility { ...@@ -94,13 +91,12 @@ public class OlmUtility {
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "## verifyEd25519Signature(): failed " + e.getMessage()); Log.e(LOG_TAG, "## verifyEd25519Signature(): failed " + e.getMessage());
errorMessage = e.getMessage();
} }
if (!TextUtils.isEmpty(errorMessage)) { if (!TextUtils.isEmpty(errorMessage)) {
throw new OlmException(OlmException.EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE, errorMessage); throw new OlmException(OlmException.EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE, errorMessage);
} }
return true;
} }
/** /**
......
...@@ -92,6 +92,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject t ...@@ -92,6 +92,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(createNewAccountJni)(JNIEnv *env, jobject t
if (randomBuffPtr) if (randomBuffPtr)
{ {
memset(randomBuffPtr, 0, randomSize);
free(randomBuffPtr); free(randomBuffPtr);
} }
} }
...@@ -286,6 +287,7 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject ...@@ -286,6 +287,7 @@ JNIEXPORT void OLM_ACCOUNT_FUNC_DEF(generateOneTimeKeysJni)(JNIEnv *env, jobject
if (randomBufferPtr) if (randomBufferPtr)
{ {
memset(randomBufferPtr, 0, randomLength);
free(randomBufferPtr); free(randomBufferPtr);
} }
} }
...@@ -642,7 +644,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, ...@@ -642,7 +644,7 @@ JNIEXPORT jlong OLM_ACCOUNT_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz,
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer); size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength)); LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr); LOGD(" ## deserializeJni(): pickled=%.*s", static_cast<int> (pickledLength), (char const *)pickledPtr);
size_t result = olm_unpickle_account(accountPtr, size_t result = olm_unpickle_account(accountPtr,
(void const *)keyPtr, (void const *)keyPtr,
......
...@@ -254,7 +254,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEn ...@@ -254,7 +254,7 @@ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEn
else else
{ {
memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength); memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength);
LOGD(" ## decryptMessageJni(): encryptedMsgLength=%lu encryptedMsg=%s",static_cast<long unsigned int>(encryptedMsgLength),encryptedMsgPtr); LOGD(" ## decryptMessageJni(): encryptedMsgLength=%lu encryptedMsg=%.*s",static_cast<long unsigned int>(encryptedMsgLength), static_cast<int>(encryptedMsgLength), encryptedMsgPtr);
// get max plaintext length // get max plaintext length
size_t maxPlainTextLength = olm_group_decrypt_max_plaintext_length(sessionPtr, size_t maxPlainTextLength = olm_group_decrypt_max_plaintext_length(sessionPtr,
...@@ -464,7 +464,7 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, ...@@ -464,7 +464,7 @@ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env,
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer); size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength)); LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr); LOGD(" ## deserializeJni(): pickled=%.*s", static_cast<int>(pickledLength), (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,
......
...@@ -506,7 +506,7 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, ...@@ -506,7 +506,7 @@ JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env,
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer); size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength)); LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr); LOGD(" ## deserializeJni(): pickled=%.*s", static_cast<int>(pickledLength), (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,
......
...@@ -143,7 +143,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject ...@@ -143,7 +143,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
{ {
size_t theirIdentityKeyLength = (size_t)env->GetArrayLength(aTheirIdentityKeyBuffer); size_t theirIdentityKeyLength = (size_t)env->GetArrayLength(aTheirIdentityKeyBuffer);
size_t theirOneTimeKeyLength = (size_t)env->GetArrayLength(aTheirOneTimeKeyBuffer); size_t theirOneTimeKeyLength = (size_t)env->GetArrayLength(aTheirOneTimeKeyBuffer);
LOGD("## initOutboundSessionJni(): identityKey=%s oneTimeKey=%s",theirIdentityKeyPtr,theirOneTimeKeyPtr); LOGD("## initOutboundSessionJni(): identityKey=%.*s oneTimeKey=%.*s", static_cast<int>(theirIdentityKeyLength), theirIdentityKeyPtr, static_cast<int>(theirOneTimeKeyLength), theirOneTimeKeyPtr);
size_t sessionResult = olm_create_outbound_session(sessionPtr, size_t sessionResult = olm_create_outbound_session(sessionPtr,
accountPtr, accountPtr,
...@@ -175,6 +175,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject ...@@ -175,6 +175,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject
if (randomBuffPtr) if (randomBuffPtr)
{ {
memset(randomBuffPtr, 0, randomSize);
free(randomBuffPtr); free(randomBuffPtr);
} }
} }
...@@ -231,7 +232,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject ...@@ -231,7 +232,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject
else else
{ {
size_t messageLength = (size_t)env->GetArrayLength(aOneTimeKeyMsgBuffer); size_t messageLength = (size_t)env->GetArrayLength(aOneTimeKeyMsgBuffer);
LOGD("## initInboundSessionJni(): messageLength=%lu message=%s", static_cast<long unsigned int>(messageLength), messagePtr); LOGD("## initInboundSessionJni(): messageLength=%lu message=%.*s", static_cast<long unsigned int>(messageLength), static_cast<int>(messageLength), messagePtr);
sessionResult = olm_create_inbound_session(sessionPtr, accountPtr, (void*)messagePtr , messageLength); sessionResult = olm_create_inbound_session(sessionPtr, accountPtr, (void*)messagePtr , messageLength);
...@@ -309,7 +310,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env, ...@@ -309,7 +310,7 @@ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env,
size_t messageLength = (size_t)env->GetArrayLength(aOneTimeKeyMsgBuffer); size_t messageLength = (size_t)env->GetArrayLength(aOneTimeKeyMsgBuffer);
size_t theirIdentityKeyLength = (size_t)env->GetArrayLength(aTheirIdentityKeyBuffer); size_t theirIdentityKeyLength = (size_t)env->GetArrayLength(aTheirIdentityKeyBuffer);
LOGD("## initInboundSessionFromIdKeyJni(): message=%s messageLength=%lu",messagePtr,static_cast<long unsigned int>(messageLength)); LOGD("## initInboundSessionFromIdKeyJni(): message=%.*s messageLength=%lu", static_cast<int>(messageLength), messagePtr, static_cast<long unsigned int>(messageLength));
sessionResult = olm_create_inbound_session_from(sessionPtr, accountPtr, theirIdentityKeyPtr, theirIdentityKeyLength, (void*)messagePtr , messageLength); sessionResult = olm_create_inbound_session_from(sessionPtr, accountPtr, theirIdentityKeyPtr, theirIdentityKeyLength, (void*)messagePtr , messageLength);
if (sessionResult == olm_error()) if (sessionResult == olm_error())
...@@ -571,6 +572,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobjec ...@@ -571,6 +572,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobjec
free(encryptedMsgPtr); free(encryptedMsgPtr);
} }
memset(randomBuffPtr, 0, randomLength);
free(randomBuffPtr); free(randomBuffPtr);
} }
} }
...@@ -659,7 +661,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobjec ...@@ -659,7 +661,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobjec
// create a dedicated temp buffer to be used in next Olm API calls // create a dedicated temp buffer to be used in next Olm API calls
tempEncryptedPtr = static_cast<char*>(malloc(encryptedMsgLength*sizeof(uint8_t))); tempEncryptedPtr = static_cast<char*>(malloc(encryptedMsgLength*sizeof(uint8_t)));
memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength); memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength);
LOGD("## decryptMessageJni(): MsgType=%lu encryptedMsgLength=%lu encryptedMsg=%s",static_cast<long unsigned int>(encryptedMsgType),static_cast<long unsigned int>(encryptedMsgLength),encryptedMsgPtr); LOGD("## decryptMessageJni(): MsgType=%lu encryptedMsgLength=%lu encryptedMsg=%.*s",static_cast<long unsigned int>(encryptedMsgType),static_cast<long unsigned int>(encryptedMsgLength), static_cast<int>(encryptedMsgLength), encryptedMsgPtr);
// get max plaintext length // get max plaintext length
size_t maxPlainTextLength = olm_decrypt_max_plaintext_length(sessionPtr, size_t maxPlainTextLength = olm_decrypt_max_plaintext_length(sessionPtr,
...@@ -846,7 +848,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi ...@@ -846,7 +848,7 @@ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thi
} }
else else
{ {
LOGD(" ## serializeJni(): success - result=%lu pickled starts with %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<int>(pickledLength), static_cast<char*>(pickledPtr));
returnValue = env->NewByteArray(pickledLength); returnValue = env->NewByteArray(pickledLength);
env->SetByteArrayRegion(returnValue, 0 , pickledLength, (jbyte*)pickledPtr); env->SetByteArrayRegion(returnValue, 0 , pickledLength, (jbyte*)pickledPtr);
...@@ -916,7 +918,7 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, ...@@ -916,7 +918,7 @@ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz,
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer); size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength)); LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
LOGD(" ## deserializeJni(): pickled=%s",(char const *)pickledPtr); LOGD(" ## deserializeJni(): pickled=%.*s",static_cast<int>(pickledLength), (char const *)pickledPtr);
size_t result = olm_unpickle_session(sessionPtr, size_t result = olm_unpickle_session(sessionPtr,
(void const *)keyPtr, (void const *)keyPtr,
......
...@@ -78,9 +78,6 @@ JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz ...@@ -78,9 +78,6 @@ JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz
/** /**
* Verify an ed25519 signature. * Verify an ed25519 signature.
* If the key was too small then the message will be "OLM.INVALID_BASE64".
* If the signature was invalid then the message will be "OLM.BAD_MESSAGE_MAC".
*
* @param aSignature the base64-encoded message signature to be checked. * @param aSignature the base64-encoded message signature to be checked.
* @param aKey the ed25519 key (fingerprint key) * @param aKey the ed25519 key (fingerprint key)
* @param aMessage the message which was signed * @param aMessage the message which was signed
...@@ -122,7 +119,7 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, j ...@@ -122,7 +119,7 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, j
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer); size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
size_t messageLength = (size_t)env->GetArrayLength(aMessageBuffer); size_t messageLength = (size_t)env->GetArrayLength(aMessageBuffer);
LOGD(" ## verifyEd25519SignatureJni(): signatureLength=%lu keyLength=%lu messageLength=%lu",static_cast<long unsigned int>(signatureLength),static_cast<long unsigned int>(keyLength),static_cast<long unsigned int>(messageLength)); LOGD(" ## verifyEd25519SignatureJni(): signatureLength=%lu keyLength=%lu messageLength=%lu",static_cast<long unsigned int>(signatureLength),static_cast<long unsigned int>(keyLength),static_cast<long unsigned int>(messageLength));
LOGD(" ## verifyEd25519SignatureJni(): key=%s",keyPtr); LOGD(" ## verifyEd25519SignatureJni(): key=%.*s", static_cast<int>(keyLength), keyPtr);
size_t result = olm_ed25519_verify(utilityPtr, size_t result = olm_ed25519_verify(utilityPtr,
(void const *)keyPtr, (void const *)keyPtr,
...@@ -194,7 +191,7 @@ JNIEXPORT jbyteArray OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, ...@@ -194,7 +191,7 @@ JNIEXPORT jbyteArray OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz,
// get lengths // get lengths
size_t messageLength = (size_t)env->GetArrayLength(aMessageToHashBuffer); size_t messageLength = (size_t)env->GetArrayLength(aMessageToHashBuffer);
size_t hashLength = olm_sha256_length(utilityPtr); size_t hashLength = olm_sha256_length(utilityPtr);
void* hashValuePtr = malloc((hashLength+1)*sizeof(uint8_t)); void* hashValuePtr = malloc((hashLength)*sizeof(uint8_t));
if (!hashValuePtr)