mirror of
https://github.com/wownero/wownerujo.git
synced 2026-11-22 00:03:58 +01:00
new wallet password fix (#184)
* revert to old (in-place) wallet creation method * recover with password
This commit is contained in:
@@ -778,13 +778,14 @@ public class LoginActivity extends SecureActivity
|
||||
static final String MNEMONIC_LANGUAGE = "English"; // see mnemonics/electrum-words.cpp for more
|
||||
|
||||
private class AsyncCreateWallet extends AsyncTask<Void, Void, Boolean> {
|
||||
String walletName;
|
||||
String walletPassword;
|
||||
WalletCreator walletCreator;
|
||||
final String walletName;
|
||||
final String walletPassword;
|
||||
final WalletCreator walletCreator;
|
||||
|
||||
File newWalletFile;
|
||||
|
||||
public AsyncCreateWallet(String name, String password, WalletCreator walletCreator) {
|
||||
public AsyncCreateWallet(final String name, final String password,
|
||||
final WalletCreator walletCreator) {
|
||||
super();
|
||||
this.walletName = name;
|
||||
this.walletPassword = password;
|
||||
@@ -814,12 +815,7 @@ public class LoginActivity extends SecureActivity
|
||||
return false;
|
||||
}
|
||||
|
||||
File newWalletFolder = Helper.getNewWalletDir(getApplicationContext());
|
||||
if (!newWalletFolder.isDirectory()) {
|
||||
Timber.e("New Wallet dir " + newWalletFolder.getAbsolutePath() + "is not a directory");
|
||||
return false;
|
||||
}
|
||||
newWalletFile = new File(newWalletFolder, walletName);
|
||||
newWalletFile = new File(walletFolder, walletName);
|
||||
boolean success = walletCreator.createWallet(newWalletFile, walletPassword);
|
||||
if (success) {
|
||||
return true;
|
||||
@@ -844,7 +840,8 @@ public class LoginActivity extends SecureActivity
|
||||
}
|
||||
}
|
||||
|
||||
public void createWallet(String name, String password, WalletCreator walletCreator) {
|
||||
public void createWallet(final String name, final String password,
|
||||
final WalletCreator walletCreator) {
|
||||
new AsyncCreateWallet(name, password, walletCreator)
|
||||
.executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
@@ -865,7 +862,7 @@ public class LoginActivity extends SecureActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGenerate(String name, String password) {
|
||||
public void onGenerate(final String name, final String password) {
|
||||
createWallet(name, password,
|
||||
new WalletCreator() {
|
||||
public boolean createWallet(File aFile, String password) {
|
||||
@@ -883,16 +880,15 @@ public class LoginActivity extends SecureActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGenerate(String name, String password, final String seed, final long restoreHeight) {
|
||||
public void onGenerate(final String name, final String password, final String seed,
|
||||
final long restoreHeight) {
|
||||
createWallet(name, password,
|
||||
new WalletCreator() {
|
||||
public boolean createWallet(File aFile, String password) {
|
||||
Wallet newWallet = WalletManager.getInstance().recoveryWallet(aFile, seed, restoreHeight);
|
||||
Wallet newWallet = WalletManager.getInstance().
|
||||
recoveryWallet(aFile, password, seed, restoreHeight);
|
||||
boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
|
||||
if (success) {
|
||||
newWallet.setPassword(password);
|
||||
success = success && newWallet.store();
|
||||
} else {
|
||||
if (!success) {
|
||||
Timber.e(newWallet.getErrorString());
|
||||
toast(newWallet.getErrorString());
|
||||
}
|
||||
@@ -903,19 +899,17 @@ public class LoginActivity extends SecureActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGenerate(String name, String password,
|
||||
final String address, final String viewKey, final String spendKey, final long restoreHeight) {
|
||||
public void onGenerate(final String name, final String password,
|
||||
final String address, final String viewKey, final String spendKey,
|
||||
final long restoreHeight) {
|
||||
createWallet(name, password,
|
||||
new WalletCreator() {
|
||||
public boolean createWallet(File aFile, String password) {
|
||||
Wallet newWallet = WalletManager.getInstance()
|
||||
.createWalletFromKeys(aFile, MNEMONIC_LANGUAGE, restoreHeight,
|
||||
.createWalletWithKeys(aFile, password, MNEMONIC_LANGUAGE, restoreHeight,
|
||||
address, viewKey, spendKey);
|
||||
boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
|
||||
if (success) {
|
||||
newWallet.setPassword(password);
|
||||
success = success && newWallet.store();
|
||||
} else {
|
||||
if (!success) {
|
||||
Timber.e(newWallet.getErrorString());
|
||||
toast(newWallet.getErrorString());
|
||||
}
|
||||
@@ -936,16 +930,10 @@ public class LoginActivity extends SecureActivity
|
||||
|
||||
@Override
|
||||
public void onAccept(final String name, final String password) {
|
||||
File newWalletFile = new File(Helper.getNewWalletDir(getApplicationContext()), name);
|
||||
Timber.d("New Wallet %s", newWalletFile.getAbsolutePath());
|
||||
newWalletFile.delete(); // when recovering wallets, the cache seems corrupt
|
||||
// TODO: figure out why this is so? Only for a private testnet?
|
||||
|
||||
// now copy the new wallet to the wallet folder
|
||||
File walletFile = new File(getStorageRoot(), name);
|
||||
Timber.d("Wallet %s", walletFile.getAbsolutePath());
|
||||
copyWallet(newWalletFile, walletFile, false, true);
|
||||
deleteWallet(newWalletFile); // delete it no matter what (can't recover from this anyway)
|
||||
File walletFolder = getStorageRoot();
|
||||
File walletFile = new File(walletFolder, name);
|
||||
Timber.d("New Wallet %s", walletFile.getAbsolutePath());
|
||||
walletFile.delete(); // when recovering wallets, the cache seems corrupt
|
||||
|
||||
boolean rc = testWallet(walletFile.getAbsolutePath(), password) == Wallet.Status.Status_Ok;
|
||||
|
||||
|
||||
@@ -86,31 +86,33 @@ public class WalletManager {
|
||||
|
||||
private native long openWalletJ(String path, String password, boolean isTestNet);
|
||||
|
||||
public Wallet recoveryWallet(File aFile, String mnemonic) {
|
||||
Wallet wallet = recoveryWallet(aFile, mnemonic, 0);
|
||||
manageWallet(wallet);
|
||||
return wallet;
|
||||
public Wallet recoveryWallet(File aFile, String password, String mnemonic) {
|
||||
return recoveryWallet(aFile, password, mnemonic, 0);
|
||||
}
|
||||
|
||||
public Wallet recoveryWallet(File aFile, String mnemonic, long restoreHeight) {
|
||||
long walletHandle = recoveryWalletJ(aFile.getAbsolutePath(), mnemonic, isTestNet(), restoreHeight);
|
||||
public Wallet recoveryWallet(File aFile, String password, String mnemonic, long restoreHeight) {
|
||||
long walletHandle = recoveryWalletJ(aFile.getAbsolutePath(), password, mnemonic,
|
||||
isTestNet(), restoreHeight);
|
||||
Wallet wallet = new Wallet(walletHandle);
|
||||
manageWallet(wallet);
|
||||
return wallet;
|
||||
}
|
||||
|
||||
private native long recoveryWalletJ(String path, String mnemonic, boolean isTestNet, long restoreHeight);
|
||||
private native long recoveryWalletJ(String path, String password, String mnemonic,
|
||||
boolean isTestNet, long restoreHeight);
|
||||
|
||||
public Wallet createWalletFromKeys(File aFile, String language, long restoreHeight,
|
||||
public Wallet createWalletWithKeys(File aFile, String password, String language, long restoreHeight,
|
||||
String addressString, String viewKeyString, String spendKeyString) {
|
||||
long walletHandle = createWalletFromKeysJ(aFile.getAbsolutePath(), language, isTestNet(), restoreHeight,
|
||||
long walletHandle = createWalletWithKeysJ(aFile.getAbsolutePath(), password,
|
||||
language, isTestNet(), restoreHeight,
|
||||
addressString, viewKeyString, spendKeyString);
|
||||
Wallet wallet = new Wallet(walletHandle);
|
||||
manageWallet(wallet);
|
||||
return wallet;
|
||||
}
|
||||
|
||||
private native long createWalletFromKeysJ(String path, String language,
|
||||
private native long createWalletWithKeysJ(String path, String password,
|
||||
String language,
|
||||
boolean isTestNet,
|
||||
long restoreHeight,
|
||||
String addressString,
|
||||
|
||||
@@ -58,17 +58,6 @@ public class Helper {
|
||||
|
||||
static public int DISPLAY_DIGITS_INFO = 5;
|
||||
|
||||
static public File getNewWalletDir(Context context) {
|
||||
File newWalletDir = context.getDir("new", Context.MODE_PRIVATE);
|
||||
Timber.d("new wallet directory is %s", newWalletDir.getAbsolutePath());
|
||||
if (!newWalletDir.exists() || !newWalletDir.isDirectory()) {
|
||||
String msg = newWalletDir.getAbsolutePath() + " is not a directory!";
|
||||
Timber.e(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
return newWalletDir;
|
||||
}
|
||||
|
||||
static public File getStorageRoot(Context context) {
|
||||
if (!isExternalStorageWritable()) {
|
||||
String msg = context.getString(R.string.message_strorage_not_writable);
|
||||
|
||||
Reference in New Issue
Block a user