From 04fd4c5a1301545419fb72533c57e4253085bdc0 Mon Sep 17 00:00:00 2001 From: pedroGitt Date: Mon, 14 Nov 2016 11:56:37 +0100 Subject: Fix the decrypt issue (crash on V5.1.1) when the message to decrypt contains emojis: - add an internal specific JNI function (javaCStringToUtf8()) to perform the UTF-8 conversion - the SDK is configured to enable/disable the use of javaCStringToUtf8() --- .../java/org/matrix/olm/OlmAccountTest.java | 7 +++-- .../java/org/matrix/olm/OlmGroupSessionTest.java | 34 +++++++++++++++++++++- .../java/org/matrix/olm/OlmSessionTest.java | 6 +++- .../java/org/matrix/olm/OlmUtilityTest.java | 6 +++- 4 files changed, 48 insertions(+), 5 deletions(-) (limited to 'java/android/OlmLibSdk/olm-sdk/src/androidTest') diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java index dc47d51..2c2711d 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java @@ -38,7 +38,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.util.Iterator; import static android.support.test.InstrumentationRegistry.getInstrumentation; import static org.junit.Assert.assertFalse; @@ -59,8 +58,12 @@ public class OlmAccountTest { @BeforeClass public static void setUpClass(){ + // enable UTF-8 specific conversion for pre Marshmallow(23) android versions, + // due to issue described here: https://github.com/eclipsesource/J2V8/issues/142 + boolean isSpecificUtf8ConversionEnabled = android.os.Build.VERSION.SDK_INT < 23; + // load native lib - mOlmManager = new OlmManager(); + mOlmManager = new OlmManager(isSpecificUtf8ConversionEnabled); String olmLibVersion = mOlmManager.getOlmLibVersion(); assertNotNull(olmLibVersion); diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java index 8fc0694..6e12463 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java @@ -60,8 +60,13 @@ public class OlmGroupSessionTest { @BeforeClass public static void setUpClass(){ + + // enable UTF-8 specific conversion for pre Marshmallow(23) android versions, + // due to issue described here: https://github.com/eclipsesource/J2V8/issues/142 + boolean isSpecificUtf8ConversionEnabled = android.os.Build.VERSION.SDK_INT < 23; + // load native lib - mOlmManager = new OlmManager(); + mOlmManager = new OlmManager(isSpecificUtf8ConversionEnabled); String version = mOlmManager.getOlmLibVersion(); assertNotNull(version); @@ -408,4 +413,31 @@ public class OlmGroupSessionTest { } } + /** + * Specific test for the following run time error: + * "JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xf0 in call to NewStringUTF".
+ * When the msg to decrypt contain emojis, depending on the android platform, the NewStringUTF() behaves differently and + * can even crash. + * This issue is described in details here: https://github.com/eclipsesource/J2V8/issues/142 + */ + @Test + public void test18TestBadCharacterCrashInDecrypt() { + OlmInboundGroupSession bobInboundGroupSession=null; + + // values taken from a "real life" crash case + String sessionKeyRef = "AgAAAAycZE6AekIctJWYxd2AWLOY15YmxZODm/WkgbpWkyycp6ytSp/R+wo84jRrzBNWmv6ySLTZ9R0EDOk9VI2eZyQ6Efdwyo1mAvrWvTkZl9yALPdkOIVHywyG65f1SNiLrnsln3hgsT1vUrISGyKtsljoUgQpr3JDPEhD0ilAi63QBjhnGCW252b+7nF+43rb6O6lwm93LaVwe2341Gdp6EkhTUvetALezEqDOtKN00wVqAbq0RQAnUJIowxHbMswg+FyoR1K1oCjnVEoF23O9xlAn5g1XtuBZP3moJlR2lwsBA"; + String msgToDecryptWithEmoji = "AwgNEpABpjs+tYF+0y8bWtzAgYAC3N55p5cPJEEiGPU1kxIHSY7f2aG5Fj4wmcsXUkhDv0UePj922kgf+Q4dFsPHKq2aVA93n8DJAQ/FRfcM98B9E6sKCZ/PsCF78uBvF12Aaq9D3pUHBopdd7llUfVq29d5y6ZwX5VDoqV2utsATkKjXYV9CbfZuvvBMQ30ZLjEtyUUBJDY9K4FxEFcULytA/IkVnATTG9ERuLF/yB6ukSFR+iUWRYAmtuOuU0k9BvaqezbGqNoK5Grlkes+dYX6/0yUObumcw9/iAI"; + + // bob creates INBOUND GROUP SESSION + try { + bobInboundGroupSession = new OlmInboundGroupSession(sessionKeyRef); + } catch (OlmException e) { + assertTrue("Exception in test18TestBadCharacterCrashInDecrypt, Exception code=" + e.getExceptionCode(), false); + } + + String decryptedMessage = bobInboundGroupSession.decryptMessage(msgToDecryptWithEmoji); + assertNotNull(decryptedMessage); + } + } + diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java index 2494c80..1aeb3fb 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java +++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java @@ -51,8 +51,12 @@ public class OlmSessionTest { @BeforeClass public static void setUpClass(){ + // enable UTF-8 specific conversion for pre Marshmallow(23) android versions, + // due to issue described here: https://github.com/eclipsesource/J2V8/issues/142 + boolean isSpecificUtf8ConversionEnabled = android.os.Build.VERSION.SDK_INT < 23; + // load native lib - mOlmManager = new OlmManager(); + mOlmManager = new OlmManager(isSpecificUtf8ConversionEnabled); String version = mOlmManager.getOlmLibVersion(); assertNotNull(version); 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 9e03453..3006344 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 @@ -41,8 +41,12 @@ public class OlmUtilityTest { @BeforeClass public static void setUpClass(){ + // enable UTF-8 specific conversion for pre Marshmallow(23) android versions, + // due to issue described here: https://github.com/eclipsesource/J2V8/issues/142 + boolean isSpecificUtf8ConversionEnabled = android.os.Build.VERSION.SDK_INT < 23; + // load native lib - mOlmManager = new OlmManager(); + mOlmManager = new OlmManager(isSpecificUtf8ConversionEnabled); String version = mOlmManager.getOlmLibVersion(); assertNotNull(version); -- cgit v1.2.3