From 31f2f40bcf764254090e68d244c58923e04d408a Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Mon, 17 Jan 2022 11:18:35 +0100 Subject: [PATCH] refactor PushUtils Signed-off-by: Marcel Hibbe --- .../com/nextcloud/talk/utils/PushUtils.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java index 372155ded..ea44175a1 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java +++ b/app/src/main/java/com/nextcloud/talk/utils/PushUtils.java @@ -85,21 +85,17 @@ public class PushUtils { @Inject NcApi ncApi; - private File keysFile; - private File publicKeyFile; - private File privateKeyFile; + private final File publicKeyFile; + private final File privateKeyFile; - private String proxyServer; + private final String proxyServer; public PushUtils() { NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this); - keysFile = NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeyStore", Context.MODE_PRIVATE); - - publicKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", - Context.MODE_PRIVATE), "push_key.pub"); - privateKeyFile = new File(NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", - Context.MODE_PRIVATE), "push_key.priv"); + String keyPath = NextcloudTalkApplication.Companion.getSharedApplication().getDir("PushKeystore", Context.MODE_PRIVATE).getAbsolutePath(); + publicKeyFile = new File(keyPath, "push_key.pub"); + privateKeyFile = new File(keyPath, "push_key.priv"); proxyServer = NextcloudTalkApplication.Companion.getSharedApplication().getResources(). getString(R.string.nc_push_server_url); } @@ -190,9 +186,6 @@ public class PushUtils { public int generateRsa2048KeyPair() { if (!publicKeyFile.exists() && !privateKeyFile.exists()) { - if (!keysFile.exists()) { - keysFile.mkdirs(); - } KeyPairGenerator keyGen = null; try { @@ -226,7 +219,6 @@ public class PushUtils { String token = appPreferences.getPushToken(); if (!TextUtils.isEmpty(token)) { - String credentials; String pushTokenHash = generateSHA512Hash(token).toLowerCase(); PublicKey devicePublicKey = (PublicKey) readKeyFromFile(true); if (devicePublicKey != null) {