From 30b3f419c1c0f9c5d74453e51d5300c8c108872b Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sun, 20 Oct 2019 17:49:58 +0200 Subject: fix endless setup loop on pre-P devices, differentiate security provider between P and pre-P devices --- .../main/java/se/leap/bitmaskclient/utils/ConfigHelper.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/se') diff --git a/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java index ca76a799..d4a640bb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/utils/ConfigHelper.java @@ -18,6 +18,7 @@ package se.leap.bitmaskclient.utils; import android.content.Context; import android.content.res.Resources; +import android.os.Build; import android.os.Looper; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -117,7 +118,12 @@ public class ConfigHelper { public static RSAPrivateKey parseRsaKeyFromString(String rsaKeyString) { RSAPrivateKey key; try { - KeyFactory kf = KeyFactory.getInstance("RSA"); + KeyFactory kf; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { + kf = KeyFactory.getInstance("RSA", "BC"); + } else { + kf = KeyFactory.getInstance("RSA"); + } rsaKeyString = rsaKeyString.replaceFirst("-----BEGIN RSA PRIVATE KEY-----", "").replaceFirst("-----END RSA PRIVATE KEY-----", ""); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(rsaKeyString)); key = (RSAPrivateKey) kf.generatePrivate(keySpec); @@ -132,6 +138,9 @@ public class ConfigHelper { } catch (NullPointerException e) { e.printStackTrace(); return null; + } catch (NoSuchProviderException e) { + e.printStackTrace(); + return null; } return key; -- cgit v1.2.3