From ae6b7156c06629652c76b662797b801b5c526393 Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Fri, 16 Dec 2022 14:51:40 +0100 Subject: [PATCH 1/2] Implement hasCode based on equals() elements to fullfil hasCode/equals contract Signed-off-by: Andy Scherzinger --- .../talk/adapters/items/GenericTextHeaderItem.java | 6 ++++++ .../talk/adapters/items/MentionAutocompleteItem.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/items/GenericTextHeaderItem.java b/app/src/main/java/com/nextcloud/talk/adapters/items/GenericTextHeaderItem.java index 943e90f17..92de855f5 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/items/GenericTextHeaderItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/items/GenericTextHeaderItem.java @@ -30,6 +30,7 @@ import com.nextcloud.talk.databinding.RvItemTitleHeaderBinding; import com.nextcloud.talk.ui.theme.ViewThemeUtils; import java.util.List; +import java.util.Objects; import eu.davidea.flexibleadapter.FlexibleAdapter; import eu.davidea.flexibleadapter.items.AbstractHeaderItem; @@ -63,6 +64,11 @@ public class GenericTextHeaderItem extends AbstractHeaderItem Date: Fri, 16 Dec 2022 14:57:45 +0100 Subject: [PATCH 2/2] Implement closing for file input/output streams Signed-off-by: Andy Scherzinger --- .../talk/utils/ssl/MagicTrustManager.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java b/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java index 74484d0df..d33d1c2da 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java +++ b/app/src/main/java/com/nextcloud/talk/utils/ssl/MagicTrustManager.java @@ -24,11 +24,12 @@ package com.nextcloud.talk.utils.ssl; import android.content.Context; import android.util.Log; + import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.events.CertificateEvent; + import org.greenrobot.eventbus.EventBus; -import javax.net.ssl.*; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -37,6 +38,13 @@ import java.security.KeyStoreException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; + public class MagicTrustManager implements X509TrustManager { private static final String TAG = "MagicTrustManager"; @@ -49,9 +57,8 @@ public class MagicTrustManager implements X509TrustManager { keystoreFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("CertsKeystore", Context.MODE_PRIVATE), "keystore.bks"); - try { + try (FileInputStream fileInputStream = new FileInputStream(keystoreFile)) { trustedKeyStore = KeyStore.getInstance(KeyStore.getDefaultType()); - FileInputStream fileInputStream = new FileInputStream(keystoreFile); trustedKeyStore.load(fileInputStream, null); } catch (Exception exception) { try { @@ -126,9 +133,8 @@ public class MagicTrustManager implements X509TrustManager { public void addCertInTrustStore(X509Certificate x509Certificate) { if (trustedKeyStore != null) { - try { + try (FileOutputStream fileOutputStream = new FileOutputStream(keystoreFile)) { trustedKeyStore.setCertificateEntry(x509Certificate.getSubjectDN().getName(), x509Certificate); - FileOutputStream fileOutputStream = new FileOutputStream(keystoreFile); trustedKeyStore.store(fileOutputStream, null); } catch (Exception exception) { Log.d(TAG, "Failed to set certificate entry " + exception.getLocalizedMessage());