Fixes "Invalid Password" although password correct (#289)

* don't log warning

* fix cn_slow_hash variant&prehash
cn_slow_hash signature was changed in monero-core but the linker didn't
notice - also added code to support wallets created with variant &
prehash enabled
This commit is contained in:
m2049r
2018-05-25 18:20:48 +02:00
committed by GitHub
parent e109df34f0
commit 0cf5981eae
5 changed files with 57 additions and 12 deletions
@@ -24,7 +24,6 @@ public class FingerprintHelper {
KeyStoreHelper.loadWalletUserPass(context, wallet);
return true;
} catch (KeyStoreHelper.BrokenPasswordStoreException ex) {
Timber.w(ex);
return false;
}
}
@@ -302,6 +302,16 @@ public class Helper {
else return "";
}
public static byte[] hexToBytes(String hex) {
final int len = hex.length();
final byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
+ Character.digit(hex.charAt(i + 1), 16));
}
return data;
}
static public void setMoneroHome(Context context) {
try {
String home = getStorage(context, HOME_DIR).getAbsolutePath();
@@ -351,6 +361,12 @@ public class Helper {
return crazyPass;
}
// or maybe it is a broken CrAzYpass?
String brokenCrazyPass = KeyStoreHelper.getBrokenCrazyPass(context, password);
if (WalletManager.getInstance().verifyWalletPassword(walletPath, brokenCrazyPass, true)) {
return brokenCrazyPass;
}
return null;
}
@@ -26,6 +26,7 @@ import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.support.annotation.NonNull;
import android.util.Base64;
import android.util.Log;
import java.io.IOException;
import java.math.BigInteger;
@@ -61,17 +62,21 @@ public class KeyStoreHelper {
System.loadLibrary("monerujo");
}
public static native byte[] cnSlowHash(byte[] data);
public static native byte[] slowHash(byte[] data, boolean broken);
static final private String RSA_ALIAS = "MonerujoRSA";
public static String getCrazyPass(Context context, String password) {
private static String getCrazyPass(Context context, String password, boolean broken) {
byte[] data = password.getBytes(StandardCharsets.UTF_8);
byte[] sig = null;
try {
KeyStoreHelper.createKeys(context, RSA_ALIAS);
sig = KeyStoreHelper.signData(RSA_ALIAS, data);
return CrazyPassEncoder.encode(cnSlowHash(sig));
byte[] hash = slowHash(sig, broken);
if (hash == null) {
throw new IllegalStateException("Slow Hash is null!");
}
return CrazyPassEncoder.encode(hash);
} catch (NoSuchProviderException | NoSuchAlgorithmException |
InvalidAlgorithmParameterException | KeyStoreException |
InvalidKeyException | SignatureException ex) {
@@ -79,6 +84,18 @@ public class KeyStoreHelper {
}
}
public static String getCrazyPass(Context context, String password) {
return getCrazyPass(context, password, false);
}
public static String getBrokenCrazyPass(Context context, String password) {
// due to a link bug in the initial implementation, some crazypasses were built with
// prehash & variant == 1
// since there are wallets out there, we need to keep this here
return getCrazyPass(context, password, true);
}
public static boolean saveWalletUserPass(@NonNull Context context, String wallet, String password) {
String walletKeyAlias = SecurityConstants.WALLET_PASS_KEY_PREFIX + wallet;
byte[] data = password.getBytes(StandardCharsets.UTF_8);