mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Don't try to zero out sensitive memory
Perhaps revisit this later
This commit is contained in:
parent
317e42ed4c
commit
a778cd5661
10 changed files with 8 additions and 45 deletions
|
@ -93,7 +93,7 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
|
|||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
char[] password = AuthHelper.getPassword(_textPassword, true);
|
||||
char[] password = AuthHelper.getEditTextChars(_textPassword);
|
||||
trySlots(PasswordSlot.class, password);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -67,8 +67,7 @@ public class CustomAuthenticatedSlide extends Fragment implements FingerprintUiH
|
|||
}
|
||||
|
||||
public char[] getPassword() {
|
||||
AuthHelper.clearPassword(_textPasswordConfirm);
|
||||
return AuthHelper.getPassword(_textPassword, true);
|
||||
return AuthHelper.getEditTextChars(_textPassword);
|
||||
}
|
||||
|
||||
public Cipher getFingerCipher() {
|
||||
|
|
|
@ -24,7 +24,6 @@ public class DerivationTask extends ProgressDialogTask<DerivationTask.Params, Se
|
|||
try {
|
||||
byte[] salt = CryptoUtils.generateSalt();
|
||||
SecretKey key = params.Slot.deriveKey(params.Password, salt, CryptoUtils.CRYPTO_SCRYPT_N, CryptoUtils.CRYPTO_SCRYPT_r, CryptoUtils.CRYPTO_SCRYPT_p);
|
||||
CryptoUtils.zero(params.Password);
|
||||
return key;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
|
|
@ -219,7 +219,6 @@ public class EditProfileActivity extends AegisActivity {
|
|||
try {
|
||||
char[] secret = AuthHelper.getEditTextChars(_textSecret);
|
||||
info.setSecret(secret);
|
||||
CryptoUtils.zero(secret);
|
||||
info.setIssuer(_textIssuer.getText().toString());
|
||||
info.setPeriod(period);
|
||||
info.setDigits(digits);
|
||||
|
|
|
@ -43,9 +43,7 @@ public class PasswordDialogFragment extends SlotDialogFragment {
|
|||
return;
|
||||
}
|
||||
|
||||
AuthHelper.clearPassword(textPasswordConfirm);
|
||||
char[] password = AuthHelper.getPassword(textPassword, true);
|
||||
|
||||
char[] password = AuthHelper.getEditTextChars(textPassword);
|
||||
PasswordSlot slot = new PasswordSlot();
|
||||
DerivationTask task = new DerivationTask(getContext(), key -> {
|
||||
Cipher cipher;
|
||||
|
|
|
@ -62,10 +62,6 @@ public class SlotCollectionTask<T extends Slot> extends ProgressDialogTask<SlotC
|
|||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new UndeclaredThrowableException(e);
|
||||
} finally {
|
||||
if (params.Obj instanceof char[]) {
|
||||
CryptoUtils.zero((char[]) params.Obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,10 +44,7 @@ public class CryptoUtils {
|
|||
public static SecretKey deriveKey(char[] password, byte[] salt, int n, int r, int p) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
byte[] bytes = toBytes(password);
|
||||
byte[] keyBytes = SCrypt.generate(bytes, salt, n, r, p, CRYPTO_KEY_SIZE);
|
||||
zero(bytes);
|
||||
SecretKey key = new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");
|
||||
zero(keyBytes);
|
||||
return key;
|
||||
return new SecretKeySpec(keyBytes, 0, keyBytes.length, "AES");
|
||||
}
|
||||
|
||||
public static Cipher createCipher(SecretKey key, int opmode) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException {
|
||||
|
@ -102,7 +99,6 @@ public class CryptoUtils {
|
|||
|
||||
byte[] bytes = key.getEncoded();
|
||||
hash.update(bytes);
|
||||
CryptoUtils.zero(bytes);
|
||||
return hash.digest();
|
||||
}
|
||||
|
||||
|
@ -127,14 +123,6 @@ public class CryptoUtils {
|
|||
return data;
|
||||
}
|
||||
|
||||
public static void zero(char[] data) {
|
||||
Arrays.fill(data, '\0');
|
||||
}
|
||||
|
||||
public static void zero(byte[] data) {
|
||||
Arrays.fill(data, (byte) 0);
|
||||
}
|
||||
|
||||
private static byte[] toBytes(char[] chars) {
|
||||
CharBuffer charBuf = CharBuffer.wrap(chars);
|
||||
ByteBuffer byteBuf = Charset.forName("UTF-8").encode(charBuf);
|
||||
|
|
|
@ -33,16 +33,13 @@ public abstract class Slot implements Serializable {
|
|||
// getKey decrypts the encrypted master key in this slot with the given key and returns it.
|
||||
public SecretKey getKey(Cipher cipher) throws BadPaddingException, IllegalBlockSizeException {
|
||||
byte[] decryptedKeyBytes = cipher.doFinal(_encryptedMasterKey);
|
||||
SecretKey decryptedKey = new SecretKeySpec(decryptedKeyBytes, CryptoUtils.CRYPTO_CIPHER_AEAD);
|
||||
CryptoUtils.zero(decryptedKeyBytes);
|
||||
return decryptedKey;
|
||||
return new SecretKeySpec(decryptedKeyBytes, CryptoUtils.CRYPTO_CIPHER_AEAD);
|
||||
}
|
||||
|
||||
// setKey encrypts the given master key with the given key and stores the result in this slot.
|
||||
public void setKey(MasterKey masterKey, Cipher cipher) throws BadPaddingException, IllegalBlockSizeException {
|
||||
byte[] masterKeyBytes = masterKey.getBytes();
|
||||
_encryptedMasterKey = cipher.doFinal(masterKeyBytes);
|
||||
CryptoUtils.zero(masterKeyBytes);
|
||||
}
|
||||
|
||||
// suppress the AES ECB warning
|
||||
|
|
|
@ -87,9 +87,7 @@ public class Base32 {
|
|||
base32[j++] = base32Chars.charAt(digit);
|
||||
}
|
||||
|
||||
char[] res = Arrays.copyOf(base32, j);
|
||||
CryptoUtils.zero(base32);
|
||||
return res;
|
||||
return Arrays.copyOf(base32, j);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,15 +11,7 @@ public class AuthHelper {
|
|||
private AuthHelper() {
|
||||
}
|
||||
|
||||
public static char[] getPassword(EditText text, boolean clear) {
|
||||
char[] password = getEditTextChars(text);
|
||||
if (clear) {
|
||||
clearPassword(text);
|
||||
}
|
||||
return password;
|
||||
}
|
||||
|
||||
public static void clearPassword(EditText text) {
|
||||
public static void clearEditText(EditText text) {
|
||||
text.getText().clear();
|
||||
}
|
||||
|
||||
|
@ -33,9 +25,6 @@ public class AuthHelper {
|
|||
public static boolean arePasswordsEqual(EditText text1, EditText text2) {
|
||||
char[] password = getEditTextChars(text1);
|
||||
char[] passwordConfirm = getEditTextChars(text2);
|
||||
boolean equal = password.length != 0 && Arrays.equals(password, passwordConfirm);
|
||||
CryptoUtils.zero(password);
|
||||
CryptoUtils.zero(passwordConfirm);
|
||||
return equal;
|
||||
return password.length != 0 && Arrays.equals(password, passwordConfirm);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue