From 076750c0a84498766d39fa3caf241dc380d21017 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 20 Oct 2018 21:44:42 +0200 Subject: use bouncycastle provider up to api 27 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apparently using conscrypt on Android below version 7? throws an exception when using 16 byte IVs. so we now use BC when ever possible (excluding api 28) we don’t know why Conscrypt behaves differently on various android versions --- .../java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java | 4 ++-- .../java/de/pixart/messenger/services/AbstractConnectionManager.java | 4 ++-- src/main/java/de/pixart/messenger/utils/Compatibility.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java index 4b4395e60..71fbd40db 100644 --- a/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java +++ b/src/main/java/de/pixart/messenger/crypto/axolotl/XmppAxolotlMessage.java @@ -178,7 +178,7 @@ public class XmppAxolotlMessage { try { SecretKey secretKey = new SecretKeySpec(innerKey, KEYTYPE); IvParameterSpec ivSpec = new IvParameterSpec(iv); - Cipher cipher = Compatibility.twentyTwo() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); + Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivSpec); this.ciphertext = cipher.doFinal(Config.OMEMO_PADDING ? getPaddedBytes(plaintext) : plaintext.getBytes()); if (Config.PUT_AUTH_TAG_INTO_KEY && this.ciphertext != null) { @@ -294,7 +294,7 @@ public class XmppAxolotlMessage { key = newKey; } - Cipher cipher = Compatibility.twentyTwo() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); + Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); SecretKeySpec keySpec = new SecretKeySpec(key, KEYTYPE); IvParameterSpec ivSpec = new IvParameterSpec(iv); diff --git a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java index 7cf2b7a93..4b2239895 100644 --- a/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java +++ b/src/main/java/de/pixart/messenger/services/AbstractConnectionManager.java @@ -42,7 +42,7 @@ public class AbstractConnectionManager { public static InputStream upgrade(DownloadableFile file, InputStream is, boolean gcm) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, NoSuchProviderException { if (file.getKey() != null && file.getIv() != null) { if (gcm) { - final Cipher cipher = Compatibility.twentyTwo() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); + final Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); SecretKeySpec keySpec = new SecretKeySpec(file.getKey(), KEYTYPE); IvParameterSpec ivSpec = new IvParameterSpec(file.getIv()); cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); @@ -80,7 +80,7 @@ public class AbstractConnectionManager { } try { if (gcm) { - final Cipher cipher = Compatibility.twentyTwo() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); + final Cipher cipher = Compatibility.twentyEight() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); SecretKeySpec keySpec = new SecretKeySpec(file.getKey(), KEYTYPE); IvParameterSpec ivSpec = new IvParameterSpec(file.getIv()); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec); diff --git a/src/main/java/de/pixart/messenger/utils/Compatibility.java b/src/main/java/de/pixart/messenger/utils/Compatibility.java index 6d5f35bc4..f178f17c7 100644 --- a/src/main/java/de/pixart/messenger/utils/Compatibility.java +++ b/src/main/java/de/pixart/messenger/utils/Compatibility.java @@ -37,8 +37,8 @@ public class Compatibility { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; } - public static boolean twentyTwo() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1; + public static boolean twentyEight() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.P; } private static boolean getBooleanPreference(Context context, String name, @BoolRes int res) { -- cgit v1.2.3