mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-25 08:16: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 android.widget.TextView;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.KeyStoreHandle;
|
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.FingerprintSlot;
|
||||||
import me.impy.aegis.crypto.slots.PasswordSlot;
|
import me.impy.aegis.crypto.slots.PasswordSlot;
|
||||||
import me.impy.aegis.crypto.slots.RawSlot;
|
import me.impy.aegis.crypto.slots.RawSlot;
|
||||||
import me.impy.aegis.crypto.slots.Slot;
|
import me.impy.aegis.crypto.slots.Slot;
|
||||||
|
import me.impy.aegis.helpers.FingerprintHelper;
|
||||||
|
|
||||||
public class SlotHolder extends RecyclerView.ViewHolder {
|
public class SlotHolder extends RecyclerView.ViewHolder {
|
||||||
private TextView _slotUsed;
|
private TextView _slotUsed;
|
||||||
|
@ -35,12 +37,14 @@ public class SlotHolder extends RecyclerView.ViewHolder {
|
||||||
} else if (slot instanceof FingerprintSlot) {
|
} else if (slot instanceof FingerprintSlot) {
|
||||||
_slotName.setText("Finger");
|
_slotName.setText("Finger");
|
||||||
_slotImg.setImageResource(R.drawable.ic_fingerprint_black_24dp);
|
_slotImg.setImageResource(R.drawable.ic_fingerprint_black_24dp);
|
||||||
try {
|
if (FingerprintHelper.isSupported()) {
|
||||||
KeyStoreHandle keyStore = new KeyStoreHandle();
|
try {
|
||||||
if (keyStore.containsKey(slot.getID())) {
|
KeyStoreHandle keyStore = new KeyStoreHandle();
|
||||||
_slotUsed.setVisibility(View.VISIBLE);
|
if (keyStore.containsKey(slot.getID())) {
|
||||||
}
|
_slotUsed.setVisibility(View.VISIBLE);
|
||||||
} catch (Exception e) { }
|
}
|
||||||
|
} catch (KeyStoreHandleException e) { }
|
||||||
|
}
|
||||||
} else if (slot instanceof RawSlot) {
|
} else if (slot instanceof RawSlot) {
|
||||||
_slotName.setText("Raw");
|
_slotName.setText("Raw");
|
||||||
_slotImg.setImageResource(R.drawable.ic_vpn_key_black_24dp);
|
_slotImg.setImageResource(R.drawable.ic_vpn_key_black_24dp);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.impy.aegis;
|
package me.impy.aegis;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
@ -9,12 +10,12 @@ import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.KeyStoreHandle;
|
import me.impy.aegis.crypto.KeyStoreHandle;
|
||||||
|
import me.impy.aegis.crypto.KeyStoreHandleException;
|
||||||
import me.impy.aegis.crypto.MasterKey;
|
import me.impy.aegis.crypto.MasterKey;
|
||||||
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
||||||
import me.impy.aegis.crypto.slots.PasswordSlot;
|
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
|
// 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
|
// and if none of the slots in the collection has a matching alias in the keystore
|
||||||
int visibility = View.VISIBLE;
|
int visibility = View.VISIBLE;
|
||||||
try {
|
if (FingerprintHelper.isSupported()) {
|
||||||
KeyStoreHandle keyStore = new KeyStoreHandle();
|
try {
|
||||||
for (FingerprintSlot slot : _slots.findAll(FingerprintSlot.class)) {
|
KeyStoreHandle keyStore = new KeyStoreHandle();
|
||||||
if (keyStore.containsKey(slot.getID()) && FingerprintHelper.getManager(this) != null) {
|
for (FingerprintSlot slot : _slots.findAll(FingerprintSlot.class)) {
|
||||||
visibility = View.GONE;
|
if (keyStore.containsKey(slot.getID()) && FingerprintHelper.getManager(this) != null) {
|
||||||
break;
|
visibility = View.GONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (KeyStoreHandleException e) {
|
||||||
|
visibility = View.GONE;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
visibility = View.GONE;
|
visibility = View.GONE;
|
||||||
}
|
}
|
||||||
findViewById(R.id.button_add_fingerprint).setVisibility(visibility);
|
findViewById(R.id.button_add_fingerprint).setVisibility(visibility);
|
||||||
|
|
|
@ -19,23 +19,29 @@ import javax.crypto.KeyGenerator;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
import javax.crypto.NoSuchPaddingException;
|
||||||
import javax.crypto.SecretKey;
|
import javax.crypto.SecretKey;
|
||||||
|
|
||||||
import me.impy.aegis.crypto.slots.FingerprintSlot;
|
|
||||||
|
|
||||||
public class KeyStoreHandle {
|
public class KeyStoreHandle {
|
||||||
private final KeyStore _keyStore;
|
private final KeyStore _keyStore;
|
||||||
private static final String STORE_NAME = "AndroidKeyStore";
|
private static final String STORE_NAME = "AndroidKeyStore";
|
||||||
|
|
||||||
public KeyStoreHandle() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
|
public KeyStoreHandle() throws KeyStoreHandleException {
|
||||||
_keyStore = KeyStore.getInstance(STORE_NAME);
|
try {
|
||||||
_keyStore.load(null);
|
_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 {
|
public boolean containsKey(String id) throws KeyStoreHandleException {
|
||||||
return _keyStore.containsAlias(id);
|
try {
|
||||||
|
return _keyStore.containsAlias(id);
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
throw new KeyStoreHandleException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecretKey generateKey(String id) throws Exception {
|
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);
|
KeyGenerator generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, STORE_NAME);
|
||||||
generator.init(new KeyGenParameterSpec.Builder(id,
|
generator.init(new KeyGenParameterSpec.Builder(id,
|
||||||
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
|
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
|
||||||
|
@ -58,7 +64,7 @@ public class KeyStoreHandle {
|
||||||
|
|
||||||
// try to initialize a dummy cipher
|
// try to initialize a dummy cipher
|
||||||
// and see if KeyPermanentlyInvalidatedException is thrown
|
// and see if KeyPermanentlyInvalidatedException is thrown
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (isSupported()) {
|
||||||
try {
|
try {
|
||||||
@SuppressLint("GetInstance")
|
@SuppressLint("GetInstance")
|
||||||
Cipher cipher = Cipher.getInstance(CryptoUtils.CRYPTO_CIPHER_RAW);
|
Cipher cipher = Cipher.getInstance(CryptoUtils.CRYPTO_CIPHER_RAW);
|
||||||
|
@ -76,4 +82,8 @@ public class KeyStoreHandle {
|
||||||
public void deleteKey(String id) throws KeyStoreException {
|
public void deleteKey(String id) throws KeyStoreException {
|
||||||
_keyStore.deleteEntry(id);
|
_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) {
|
public static FingerprintManager getManager(Context context) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (isSupported() && PermissionHelper.granted(context, Manifest.permission.USE_FINGERPRINT)) {
|
||||||
if (PermissionHelper.granted(context, Manifest.permission.USE_FINGERPRINT)) {
|
FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
||||||
FingerprintManager manager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
if (manager != null && manager.isHardwareDetected() && manager.hasEnrolledFingerprints()) {
|
||||||
if (manager != null && manager.isHardwareDetected() && manager.hasEnrolledFingerprints()) {
|
return manager;
|
||||||
return manager;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isSupported() {
|
||||||
|
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue