StrictMode fix: close cached keystore file

This commit is contained in:
Daniel Martí 2015-09-05 23:45:45 -04:00
parent cb9290fb89
commit 9e85911b5d

View File

@ -23,6 +23,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.Socket; import java.net.Socket;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
@ -95,9 +96,11 @@ public class LocalRepoKeyStore {
this.keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); this.keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
if (keyStoreFile.exists()) { if (keyStoreFile.exists()) {
InputStream in = null;
try { try {
Utils.DebugLog(TAG, "Keystore already exists, loading..."); Utils.DebugLog(TAG, "Keystore already exists, loading...");
keyStore.load(new FileInputStream(keyStoreFile), "".toCharArray()); in = new FileInputStream(keyStoreFile);
keyStore.load(in, "".toCharArray());
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Error while loading existing keystore. Will delete and create a new one."); Log.e(TAG, "Error while loading existing keystore. Will delete and create a new one.");
@ -106,6 +109,8 @@ public class LocalRepoKeyStore {
// that you have swapped apps with in the past, then you would really want the // that you have swapped apps with in the past, then you would really want the
// signature to be the same as last time. // signature to be the same as last time.
throw new InitException("Could not initialize local repo keystore: " + e); throw new InitException("Could not initialize local repo keystore: " + e);
} finally {
Utils.closeQuietly(in);
} }
} }