From f257580cb1adb798943b2b9bc54192320c2821e2 Mon Sep 17 00:00:00 2001 From: ylecollen Date: Mon, 9 Jan 2017 10:25:18 +0100 Subject: verifyEd25519Signature triggers an exception instead of filling an error buffer --- .../src/main/java/org/matrix/olm/OlmException.java | 50 +++++++++++----------- .../src/main/java/org/matrix/olm/OlmUtility.java | 39 ++++++++--------- 2 files changed, 43 insertions(+), 46 deletions(-) (limited to 'java/android/OlmLibSdk/olm-sdk/src/main') diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmException.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmException.java index a6f1805..d02b7fc 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmException.java +++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmException.java @@ -27,33 +27,35 @@ public class OlmException extends IOException { public static final int EXCEPTION_CODE_INIT_ACCOUNT_CREATION = 10; - public static final int EXCEPTION_CODE_ACCOUNT_SERIALIZATION = 20; - public static final int EXCEPTION_CODE_ACCOUNT_DESERIALIZATION = 21; - public static final int EXCEPTION_CODE_ACCOUNT_IDENTITY_KEYS = 22; - public static final int EXCEPTION_CODE_ACCOUNT_GENERATE_ONE_TIME_KEYS = 23; - public static final int EXCEPTION_CODE_ACCOUNT_ONE_TIME_KEYS = 24; - public static final int EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS = 25; - public static final int EXCEPTION_CODE_ACCOUNT_MARK_ONE_KEYS_AS_PUBLISHED = 26; - public static final int EXCEPTION_CODE_ACCOUNT_SIGN_MESSAGE = 27; + public static final int EXCEPTION_CODE_ACCOUNT_SERIALIZATION = 100; + public static final int EXCEPTION_CODE_ACCOUNT_DESERIALIZATION = 101; + public static final int EXCEPTION_CODE_ACCOUNT_IDENTITY_KEYS = 102; + public static final int EXCEPTION_CODE_ACCOUNT_GENERATE_ONE_TIME_KEYS = 103; + public static final int EXCEPTION_CODE_ACCOUNT_ONE_TIME_KEYS = 104; + public static final int EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS = 105; + public static final int EXCEPTION_CODE_ACCOUNT_MARK_ONE_KEYS_AS_PUBLISHED = 106; + public static final int EXCEPTION_CODE_ACCOUNT_SIGN_MESSAGE = 107; - public static final int EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION = 30; - public static final int EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION = 31; - public static final int EXCEPTION_CODE_INBOUND_GROUP_SESSION_IDENTIFIER = 32; - public static final int EXCEPTION_CODE_INBOUND_GROUP_SESSION_DECRYPT_SESSION = 33; + public static final int EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION = 200; + public static final int EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION = 201; + public static final int EXCEPTION_CODE_INBOUND_GROUP_SESSION_IDENTIFIER = 202; + public static final int EXCEPTION_CODE_INBOUND_GROUP_SESSION_DECRYPT_SESSION = 203; - public static final int EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION = 40; - public static final int EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION = 41; - public static final int EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_IDENTIFIER = 42; - public static final int EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_KEY = 43; - public static final int EXCEPTION_CODE_OUTBOUND_GROUP_ENCRYPT_MESSAGE = 44; + public static final int EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION = 300; + public static final int EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION = 301; + public static final int EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_IDENTIFIER = 302; + public static final int EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_KEY = 303; + public static final int EXCEPTION_CODE_OUTBOUND_GROUP_ENCRYPT_MESSAGE = 304; - public static final int EXCEPTION_CODE_INIT_SESSION_CREATION = 50; - public static final int EXCEPTION_CODE_SESSION_INIT_OUTBOUND_SESSION = 51; - public static final int EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION = 52; - public static final int EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION_FROM = 53; - public static final int EXCEPTION_CODE_SESSION_ENCRYPT_MESSAGE = 54; - public static final int EXCEPTION_CODE_SESSION_DECRYPT_MESSAGE = 55; - public static final int EXCEPTION_CODE_SESSION_SESSION_IDENTIFIER = 56; + public static final int EXCEPTION_CODE_INIT_SESSION_CREATION = 400; + public static final int EXCEPTION_CODE_SESSION_INIT_OUTBOUND_SESSION = 401; + public static final int EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION = 402; + public static final int EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION_FROM = 403; + public static final int EXCEPTION_CODE_SESSION_ENCRYPT_MESSAGE = 404; + public static final int EXCEPTION_CODE_SESSION_DECRYPT_MESSAGE = 405; + public static final int EXCEPTION_CODE_SESSION_SESSION_IDENTIFIER = 406; + + public static final int EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE = 500; // exception human readable messages public static final String EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION = "createNewSession() failed"; diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java index 28d8b58..3b1d9e1 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java +++ b/java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java @@ -70,33 +70,28 @@ public class OlmUtility { * @param aSignature the base64-encoded message signature to be checked. * @param aFingerprintKey the ed25519 key (fingerprint key) * @param aMessage the signed message - * @param aError error message description * @return true if the signature is verified, false otherwise + * @exception OlmException the failure reason */ - public boolean verifyEd25519Signature(String aSignature, String aFingerprintKey, String aMessage, StringBuffer aError) { - boolean retCode = false; - String jniError; - - if (null == aError) { - Log.e(LOG_TAG, "## verifyEd25519Signature(): invalid input error parameter"); - } else { - aError.setLength(0); - - try { - if (TextUtils.isEmpty(aSignature) || TextUtils.isEmpty(aFingerprintKey) || TextUtils.isEmpty(aMessage)) { - Log.e(LOG_TAG, "## verifyEd25519Signature(): invalid input parameters"); - aError.append("JAVA sanity check failure - invalid input parameters"); - } else if (null == (jniError = verifyEd25519SignatureJni(aSignature.getBytes("UTF-8"), aFingerprintKey.getBytes("UTF-8"), aMessage.getBytes("UTF-8")))) { - retCode = true; - } else { - aError.append(jniError); - } - } catch (Exception e) { - Log.e(LOG_TAG, "## verifyEd25519Signature(): failed " + e.getMessage()); + public boolean verifyEd25519Signature(String aSignature, String aFingerprintKey, String aMessage) throws OlmException { + String errorMessage = null; + + try { + if (TextUtils.isEmpty(aSignature) || TextUtils.isEmpty(aFingerprintKey) || TextUtils.isEmpty(aMessage)) { + Log.e(LOG_TAG, "## verifyEd25519Signature(): invalid input parameters"); + errorMessage = "JAVA sanity check failure - invalid input parameters"; + } else { + errorMessage = verifyEd25519SignatureJni(aSignature.getBytes("UTF-8"), aFingerprintKey.getBytes("UTF-8"), aMessage.getBytes("UTF-8")); } + } catch (Exception e) { + Log.e(LOG_TAG, "## verifyEd25519Signature(): failed " + e.getMessage()); } - return retCode; + if (!TextUtils.isEmpty(errorMessage)) { + throw new OlmException(OlmException.EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE, errorMessage); + } + + return true; } /** -- cgit v1.2.3