Skip to content

Commit

Permalink
fix: [litecoin-foundation#264] add null checking for BRKeyStore.remov…
Browse files Browse the repository at this point in the history
…eAliasAndFiles (litecoin-foundation#270)
  • Loading branch information
andhikayuana authored Nov 15, 2024
1 parent 1c1e19c commit 0382744
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/src/main/java/com/breadwallet/tools/security/BRKeyStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
import com.breadwallet.R;
import com.breadwallet.exceptions.BRKeystoreErrorException;
import com.breadwallet.presenter.customviews.BRDialogView;
import com.breadwallet.tools.animation.BRAnimator;
import com.breadwallet.tools.animation.BRDialog;
import com.breadwallet.tools.manager.BRSharedPrefs;
import com.breadwallet.tools.threads.BRExecutor;
import com.breadwallet.tools.util.BRConstants;
import com.breadwallet.tools.util.BytesUtil;
import com.breadwallet.tools.util.TypesConverter;
import com.breadwallet.tools.util.Utils;
Expand Down Expand Up @@ -333,7 +331,8 @@ private synchronized static byte[] _getData(final Context context, String alias,
Timber.e(e);
throw new RuntimeException(e.getMessage());
}
} catch (UnrecoverableKeyException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException e) {
} catch (UnrecoverableKeyException | NoSuchAlgorithmException | NoSuchPaddingException |
InvalidAlgorithmParameterException e) {
/** if for any other reason the keystore fails, crash! */
Timber.e(e, "timber:getData: error");
throw new RuntimeException(e.getMessage());
Expand Down Expand Up @@ -715,8 +714,15 @@ public synchronized static boolean resetWalletKeyStore(Context context) {
public synchronized static void removeAliasAndFiles(KeyStore keyStore, String alias, Context context) {
try {
keyStore.deleteEntry(alias);
boolean b1 = new File(getFilePath(aliasObjectMap.get(alias).datafileName, context)).delete();
boolean b2 = new File(getFilePath(aliasObjectMap.get(alias).ivFileName, context)).delete();

AliasObject aliasObject = aliasObjectMap.get(alias);
if (aliasObject == null) {
Timber.w("aliasObject for alias: %s is null, skipping deletion", alias);
return;
}

boolean b1 = new File(getFilePath(aliasObject.datafileName, context)).delete();
boolean b2 = new File(getFilePath(aliasObject.ivFileName, context)).delete();
} catch (KeyStoreException e) {
Timber.e(e);
}
Expand Down Expand Up @@ -930,7 +936,8 @@ public synchronized static byte[] _getOldData(final Context context, String alia
/** keyStore.load(null) threw the Exception, meaning the keystore is unavailable */
Timber.e(e, "timber:_getOldData: keyStore.load(null) threw the Exception, meaning the keystore is unavailable");
return null;
} catch (UnrecoverableKeyException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException e) {
} catch (UnrecoverableKeyException | NoSuchAlgorithmException | NoSuchPaddingException |
InvalidAlgorithmParameterException e) {
/** if for any other reason the keystore fails, crash! */
Timber.e(e, "timber:getData: error");
return null;
Expand Down

0 comments on commit 0382744

Please sign in to comment.