mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-24 07:46:07 +00:00
Fix a crash on Kitkat. It doesn't like the KeyStoreHandle class for some reason
This commit is contained in:
parent
3a3e4cc584
commit
6e68d79816
5 changed files with 57 additions and 29 deletions
|
@ -7,10 +7,12 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import me.impy.aegis.crypto.KeyStoreHandle;
|
||||
import me.impy.aegis.crypto.KeyStoreHandleException;
|
||||
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
||||
import me.impy.aegis.crypto.slots.PasswordSlot;
|
||||
import me.impy.aegis.crypto.slots.RawSlot;
|
||||
import me.impy.aegis.crypto.slots.Slot;
|
||||
import me.impy.aegis.helpers.FingerprintHelper;
|
||||
|
||||
public class SlotHolder extends RecyclerView.ViewHolder {
|
||||
private TextView _slotUsed;
|
||||
|
@ -35,12 +37,14 @@ public class SlotHolder extends RecyclerView.ViewHolder {
|
|||
} else if (slot instanceof FingerprintSlot) {
|
||||
_slotName.setText("Finger");
|
||||
_slotImg.setImageResource(R.drawable.ic_fingerprint_black_24dp);
|
||||
try {
|
||||
KeyStoreHandle keyStore = new KeyStoreHandle();
|
||||
if (keyStore.containsKey(slot.getID())) {
|
||||
_slotUsed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} catch (Exception e) { }
|
||||
if (FingerprintHelper.isSupported()) {
|
||||
try {
|
||||
KeyStoreHandle keyStore = new KeyStoreHandle();
|
||||
if (keyStore.containsKey(slot.getID())) {
|
||||
_slotUsed.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} catch (KeyStoreHandleException e) { }
|
||||
}
|
||||
} else if (slot instanceof RawSlot) {
|
||||
_slotName.setText("Raw");
|
||||
_slotImg.setImageResource(R.drawable.ic_vpn_key_black_24dp);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package me.impy.aegis;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
@ -9,12 +10,12 @@ import android.support.v7.widget.RecyclerView;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
|
||||
import me.impy.aegis.crypto.KeyStoreHandle;
|
||||
import me.impy.aegis.crypto.KeyStoreHandleException;
|
||||
import me.impy.aegis.crypto.MasterKey;
|
||||
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
||||
import me.impy.aegis.crypto.slots.PasswordSlot;
|
||||
|
@ -70,15 +71,19 @@ public class SlotManagerActivity extends AegisActivity implements SlotAdapter.Li
|
|||
// only show the fingerprint option if we can get an instance of the fingerprint manager
|
||||
// and if none of the slots in the collection has a matching alias in the keystore
|
||||
int visibility = View.VISIBLE;
|
||||
try {
|
||||
KeyStoreHandle keyStore = new KeyStoreHandle();
|
||||
for (FingerprintSlot slot : _slots.findAll(FingerprintSlot.class)) {
|
||||
if (keyStore.containsKey(slot.getID()) && FingerprintHelper.getManager(this) != null) {
|
||||
visibility = View.GONE;
|
||||
break;
|
||||
if (FingerprintHelper.isSupported()) {
|
||||
try {
|
||||
KeyStoreHandle keyStore = new KeyStoreHandle();
|
||||
for (FingerprintSlot slot : _slots.findAll(FingerprintSlot.class)) {
|
||||
if (keyStore.containsKey(slot.getID()) && FingerprintHelper.getManager(this) != null) {
|
||||
visibility = View.GONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (KeyStoreHandleException e) {
|
||||
visibility = View.GONE;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} else {
|
||||
visibility = View.GONE;
|
||||
}
|
||||
findViewById(R.id.button_add_fingerprint).setVisibility(visibility);
|
||||
|
|
|
@ -19,23 +19,29 @@ import javax.crypto.KeyGenerator;
|
|||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
||||
|
||||
public class KeyStoreHandle {
|
||||
private final KeyStore _keyStore;
|
||||
private static final String STORE_NAME = "AndroidKeyStore";
|
||||
|
||||
public KeyStoreHandle() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
|
||||
_keyStore = KeyStore.getInstance(STORE_NAME);
|
||||
_keyStore.load(null);
|
||||
public KeyStoreHandle() throws KeyStoreHandleException {
|
||||
try {
|
||||
_keyStore = KeyStore.getInstance(STORE_NAME);
|
||||
_keyStore.load(null);
|
||||
} catch (KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e) {
|
||||
throw new KeyStoreHandleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsKey(String id) throws KeyStoreException {
|
||||
return _keyStore.containsAlias(id);
|
||||
public boolean containsKey(String id) throws KeyStoreHandleException {
|
||||
try {
|
||||
return _keyStore.containsAlias(id);
|
||||
} catch (KeyStoreException e) {
|
||||
throw new KeyStoreHandleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public SecretKey generateKey(String id) throws Exception {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (isSupported()) {
|
||||
KeyGenerator generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, STORE_NAME);
|
||||
generator.init(new KeyGenParameterSpec.Builder(id,
|
||||
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
|
||||
|
@ -58,7 +64,7 @@ public class KeyStoreHandle {
|
|||
|
||||
// try to initialize a dummy cipher
|
||||
// and see if KeyPermanentlyInvalidatedException is thrown
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (isSupported()) {
|
||||
try {
|
||||
@SuppressLint("GetInstance")
|
||||
Cipher cipher = Cipher.getInstance(CryptoUtils.CRYPTO_CIPHER_RAW);
|
||||
|
@ -76,4 +82,8 @@ public class KeyStoreHandle {
|
|||
public void deleteKey(String id) throws KeyStoreException {
|
||||
_keyStore.deleteEntry(id);
|
||||
}
|
||||
|
||||
public static boolean isSupported() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package me.impy.aegis.crypto;
|
||||
|
||||
public class KeyStoreHandleException extends Exception {
|
||||
public KeyStoreHandleException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -11,14 +11,16 @@ public class FingerprintHelper {
|
|||
}
|
||||
|
||||
public static FingerprintManager getManager(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (PermissionHelper.granted(context, Manifest.permission.USE_FINGERPRINT)) {
|
||||
FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
||||
if (manager != null && manager.isHardwareDetected() && manager.hasEnrolledFingerprints()) {
|
||||
return manager;
|
||||
}
|
||||
if (isSupported() && PermissionHelper.granted(context, Manifest.permission.USE_FINGERPRINT)) {
|
||||
FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
||||
if (manager != null && manager.isHardwareDetected() && manager.hasEnrolledFingerprints()) {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isSupported() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue