From 67e7d2cf9eedb8ffbd755fbe4ff01f1ea8474e38 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 17 Sep 2018 17:47:36 +0200 Subject: [PATCH] do not use BC provider on android 22+ --- .../conversations/crypto/axolotl/XmppAxolotlMessage.java | 5 +++-- .../java/eu/siacs/conversations/utils/Compatibility.java | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java index 587944ff8..9b7d10008 100644 --- a/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java +++ b/src/main/java/eu/siacs/conversations/crypto/axolotl/XmppAxolotlMessage.java @@ -24,6 +24,7 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import eu.siacs.conversations.Config; +import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.xml.Element; import rocks.xmpp.addr.Jid; @@ -180,7 +181,7 @@ public class XmppAxolotlMessage { try { SecretKey secretKey = new SecretKeySpec(innerKey, KEYTYPE); IvParameterSpec ivSpec = new IvParameterSpec(iv); - Cipher cipher = Cipher.getInstance(CIPHERMODE, PROVIDER); + Cipher cipher = Compatibility.twentyTwo() ? 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) { @@ -296,7 +297,7 @@ public class XmppAxolotlMessage { key = newKey; } - Cipher cipher = Cipher.getInstance(CIPHERMODE, PROVIDER); + Cipher cipher = Compatibility.twentyTwo() ? Cipher.getInstance(CIPHERMODE) : Cipher.getInstance(CIPHERMODE, PROVIDER); SecretKeySpec keySpec = new SecretKeySpec(key, KEYTYPE); IvParameterSpec ivSpec = new IvParameterSpec(iv); diff --git a/src/main/java/eu/siacs/conversations/utils/Compatibility.java b/src/main/java/eu/siacs/conversations/utils/Compatibility.java index f72bc1446..caa592ceb 100644 --- a/src/main/java/eu/siacs/conversations/utils/Compatibility.java +++ b/src/main/java/eu/siacs/conversations/utils/Compatibility.java @@ -32,6 +32,10 @@ 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; + } + private static boolean getBooleanPreference(Context context, String name, @BoolRes int res) { return getPreferences(context).getBoolean(name, context.getResources().getBoolean(res)); }