From b0fc867bfe22a1253c0d28919b817d247122a06c Mon Sep 17 00:00:00 2001 From: pedroGitt Date: Wed, 26 Oct 2016 15:08:39 +0200 Subject: Update verifyEd25519Signature() unit test: add a test to detect a key length too small - add logs in verifyEd25519SignatureJni() to print the key used --- .../src/androidTest/java/org/matrix/olm/OlmUtilityTest.java | 8 +++++++- java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'java') diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java index e483d71..d4c3382 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java @@ -86,12 +86,18 @@ public class OlmUtilityTest { assertTrue(isVerified); assertTrue(String.valueOf(errorMsg).isEmpty()); - // check a bad signature is detected and the error message is not empty + // check a bad signature is detected => errorMsg = BAD_MESSAGE_MAC String badSignature = "Bad signature Bad signature Bad signature.."; isVerified = utility.verifyEd25519Signature(badSignature, fingerPrintKey, message, errorMsg); assertFalse(isVerified); assertFalse(String.valueOf(errorMsg).isEmpty()); + // check bad fingerprint size => errorMsg = INVALID_BASE64 + String badSizeFingerPrintKey = fingerPrintKey.substring(fingerPrintKey.length()/2); + isVerified = utility.verifyEd25519Signature(messageSignature, badSizeFingerPrintKey, message, errorMsg); + assertFalse(isVerified); + assertFalse(String.valueOf(errorMsg).isEmpty()); + utility.releaseUtility(); account.releaseAccount(); } diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp index bd93de1..19a045b 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp +++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_utility.cpp @@ -121,6 +121,7 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, j size_t keyLength = (size_t)env->GetStringUTFLength(aKey); size_t messageLength = (size_t)env->GetStringUTFLength(aMessage); LOGD(" ## verifyEd25519SignatureJni(): signatureLength=%lu keyLength=%lu messageLength=%lu",static_cast(signatureLength),static_cast(keyLength),static_cast(messageLength)); + LOGD(" ## verifyEd25519SignatureJni(): key=%s",keyPtr); size_t result = olm_ed25519_verify(utilityPtr, (void const *)keyPtr, @@ -132,7 +133,7 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, j if(result == olm_error()) { const char *errorMsgPtr = olm_utility_last_error(utilityPtr); errorMessageRetValue = env->NewStringUTF(errorMsgPtr); - LOGE("## verifyEd25519SignatureJni(): failure - session creation Msg=%s",errorMsgPtr); + LOGE("## verifyEd25519SignatureJni(): failure - olm_ed25519_verify Msg=%s",errorMsgPtr); } else { -- cgit v1.2.3