From 521bb7846c4eb622110fe6777b6b2e322f9753cd Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 6 Oct 2018 19:33:38 +0200 Subject: [PATCH] catch exception if Conscrypt could not be initialized and use tls 1.2 --- .../conversations/services/XmppConnectionService.java | 7 +++++-- .../java/eu/siacs/conversations/utils/SSLSocketHelper.java | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 09045703b..86319acec 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -116,7 +116,6 @@ import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.MimeUtils; import eu.siacs.conversations.utils.OnPhoneContactsLoadedListener; -import eu.siacs.conversations.utils.PRNGFixes; import eu.siacs.conversations.utils.PhoneHelper; import eu.siacs.conversations.utils.QuickLoader; import eu.siacs.conversations.utils.ReplacingSerialSingleThreadExecutor; @@ -947,7 +946,11 @@ public class XmppConnectionService extends Service { public void onCreate() { OmemoSetting.load(this); ExceptionHelper.init(getApplicationContext()); - Security.insertProviderAt(Conscrypt.newProvider(), 1); + try { + Security.insertProviderAt(Conscrypt.newProvider(), 1); + } catch (Throwable throwable) { + Log.e(Config.LOGTAG,"unable to initialize security provider", throwable); + } Resolver.init(this); this.mRandom = new SecureRandom(); updateMemorizingTrustmanager(); diff --git a/src/main/java/eu/siacs/conversations/utils/SSLSocketHelper.java b/src/main/java/eu/siacs/conversations/utils/SSLSocketHelper.java index 575de9540..00f42bcea 100644 --- a/src/main/java/eu/siacs/conversations/utils/SSLSocketHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/SSLSocketHelper.java @@ -89,7 +89,11 @@ public class SSLSocketHelper { } public static SSLContext getSSLContext() throws NoSuchAlgorithmException { - return SSLContext.getInstance("TLSv1.3"); + try { + return SSLContext.getInstance("TLSv1.3"); + } catch (NoSuchAlgorithmException e) { + return SSLContext.getInstance("TLSv1.2"); + } } public static void log(Account account, SSLSocket socket) {