new wallet password fix (#184)
* revert to old (in-place) wallet creation method * recover with password
This commit is contained in:
parent
7f47307307
commit
d6eb82c457
|
@ -291,41 +291,48 @@ Java_com_m2049r_xmrwallet_model_WalletManager_openWalletJ(JNIEnv *env, jobject i
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL
|
JNIEXPORT jlong JNICALL
|
||||||
Java_com_m2049r_xmrwallet_model_WalletManager_recoveryWalletJ(JNIEnv *env, jobject instance,
|
Java_com_m2049r_xmrwallet_model_WalletManager_recoveryWalletJ(JNIEnv *env, jobject instance,
|
||||||
jstring path, jstring mnemonic,
|
jstring path, jstring password,
|
||||||
|
jstring mnemonic,
|
||||||
jboolean isTestNet,
|
jboolean isTestNet,
|
||||||
jlong restoreHeight) {
|
jlong restoreHeight) {
|
||||||
const char *_path = env->GetStringUTFChars(path, NULL);
|
const char *_path = env->GetStringUTFChars(path, NULL);
|
||||||
|
const char *_password = env->GetStringUTFChars(password, NULL);
|
||||||
const char *_mnemonic = env->GetStringUTFChars(mnemonic, NULL);
|
const char *_mnemonic = env->GetStringUTFChars(mnemonic, NULL);
|
||||||
|
|
||||||
Bitmonero::Wallet *wallet =
|
Bitmonero::Wallet *wallet =
|
||||||
Bitmonero::WalletManagerFactory::getWalletManager()->recoveryWallet(
|
Bitmonero::WalletManagerFactory::getWalletManager()->recoveryWallet(
|
||||||
std::string(_path),
|
std::string(_path),
|
||||||
|
std::string(_password),
|
||||||
std::string(_mnemonic),
|
std::string(_mnemonic),
|
||||||
isTestNet,
|
isTestNet,
|
||||||
restoreHeight);
|
restoreHeight);
|
||||||
|
|
||||||
env->ReleaseStringUTFChars(path, _path);
|
env->ReleaseStringUTFChars(path, _path);
|
||||||
|
env->ReleaseStringUTFChars(password, _password);
|
||||||
env->ReleaseStringUTFChars(mnemonic, _mnemonic);
|
env->ReleaseStringUTFChars(mnemonic, _mnemonic);
|
||||||
return reinterpret_cast<jlong>(wallet);
|
return reinterpret_cast<jlong>(wallet);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jlong JNICALL
|
JNIEXPORT jlong JNICALL
|
||||||
Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromKeysJ(JNIEnv *env, jobject instance,
|
Java_com_m2049r_xmrwallet_model_WalletManager_createWalletWithKeysJ(JNIEnv *env, jobject instance,
|
||||||
jstring path, jstring language,
|
jstring path, jstring password,
|
||||||
|
jstring language,
|
||||||
jboolean isTestNet,
|
jboolean isTestNet,
|
||||||
jlong restoreHeight,
|
jlong restoreHeight,
|
||||||
jstring addressString,
|
jstring addressString,
|
||||||
jstring viewKeyString,
|
jstring viewKeyString,
|
||||||
jstring spendKeyString) {
|
jstring spendKeyString) {
|
||||||
const char *_path = env->GetStringUTFChars(path, NULL);
|
const char *_path = env->GetStringUTFChars(path, NULL);
|
||||||
|
const char *_password = env->GetStringUTFChars(password, NULL);
|
||||||
const char *_language = env->GetStringUTFChars(language, NULL);
|
const char *_language = env->GetStringUTFChars(language, NULL);
|
||||||
const char *_addressString = env->GetStringUTFChars(addressString, NULL);
|
const char *_addressString = env->GetStringUTFChars(addressString, NULL);
|
||||||
const char *_viewKeyString = env->GetStringUTFChars(viewKeyString, NULL);
|
const char *_viewKeyString = env->GetStringUTFChars(viewKeyString, NULL);
|
||||||
const char *_spendKeyString = env->GetStringUTFChars(spendKeyString, NULL);
|
const char *_spendKeyString = env->GetStringUTFChars(spendKeyString, NULL);
|
||||||
|
|
||||||
Bitmonero::Wallet *wallet =
|
Bitmonero::Wallet *wallet =
|
||||||
Bitmonero::WalletManagerFactory::getWalletManager()->createWalletFromKeys(
|
Bitmonero::WalletManagerFactory::getWalletManager()->createWalletWithKeys(
|
||||||
std::string(_path),
|
std::string(_path),
|
||||||
|
std::string(_password),
|
||||||
std::string(_language),
|
std::string(_language),
|
||||||
isTestNet,
|
isTestNet,
|
||||||
restoreHeight,
|
restoreHeight,
|
||||||
|
@ -334,6 +341,7 @@ Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromKeysJ(JNIEnv *env,
|
||||||
std::string(_spendKeyString));
|
std::string(_spendKeyString));
|
||||||
|
|
||||||
env->ReleaseStringUTFChars(path, _path);
|
env->ReleaseStringUTFChars(path, _path);
|
||||||
|
env->ReleaseStringUTFChars(password, _password);
|
||||||
env->ReleaseStringUTFChars(language, _language);
|
env->ReleaseStringUTFChars(language, _language);
|
||||||
env->ReleaseStringUTFChars(addressString, _addressString);
|
env->ReleaseStringUTFChars(addressString, _addressString);
|
||||||
env->ReleaseStringUTFChars(viewKeyString, _viewKeyString);
|
env->ReleaseStringUTFChars(viewKeyString, _viewKeyString);
|
||||||
|
|
|
@ -778,13 +778,14 @@ public class LoginActivity extends SecureActivity
|
||||||
static final String MNEMONIC_LANGUAGE = "English"; // see mnemonics/electrum-words.cpp for more
|
static final String MNEMONIC_LANGUAGE = "English"; // see mnemonics/electrum-words.cpp for more
|
||||||
|
|
||||||
private class AsyncCreateWallet extends AsyncTask<Void, Void, Boolean> {
|
private class AsyncCreateWallet extends AsyncTask<Void, Void, Boolean> {
|
||||||
String walletName;
|
final String walletName;
|
||||||
String walletPassword;
|
final String walletPassword;
|
||||||
WalletCreator walletCreator;
|
final WalletCreator walletCreator;
|
||||||
|
|
||||||
File newWalletFile;
|
File newWalletFile;
|
||||||
|
|
||||||
public AsyncCreateWallet(String name, String password, WalletCreator walletCreator) {
|
public AsyncCreateWallet(final String name, final String password,
|
||||||
|
final WalletCreator walletCreator) {
|
||||||
super();
|
super();
|
||||||
this.walletName = name;
|
this.walletName = name;
|
||||||
this.walletPassword = password;
|
this.walletPassword = password;
|
||||||
|
@ -814,12 +815,7 @@ public class LoginActivity extends SecureActivity
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
File newWalletFolder = Helper.getNewWalletDir(getApplicationContext());
|
newWalletFile = new File(walletFolder, walletName);
|
||||||
if (!newWalletFolder.isDirectory()) {
|
|
||||||
Timber.e("New Wallet dir " + newWalletFolder.getAbsolutePath() + "is not a directory");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
newWalletFile = new File(newWalletFolder, walletName);
|
|
||||||
boolean success = walletCreator.createWallet(newWalletFile, walletPassword);
|
boolean success = walletCreator.createWallet(newWalletFile, walletPassword);
|
||||||
if (success) {
|
if (success) {
|
||||||
return true;
|
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)
|
new AsyncCreateWallet(name, password, walletCreator)
|
||||||
.executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR);
|
.executeOnExecutor(MoneroThreadPoolExecutor.MONERO_THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
@ -865,7 +862,7 @@ public class LoginActivity extends SecureActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGenerate(String name, String password) {
|
public void onGenerate(final String name, final String password) {
|
||||||
createWallet(name, password,
|
createWallet(name, password,
|
||||||
new WalletCreator() {
|
new WalletCreator() {
|
||||||
public boolean createWallet(File aFile, String password) {
|
public boolean createWallet(File aFile, String password) {
|
||||||
|
@ -883,16 +880,15 @@ public class LoginActivity extends SecureActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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,
|
createWallet(name, password,
|
||||||
new WalletCreator() {
|
new WalletCreator() {
|
||||||
public boolean createWallet(File aFile, String password) {
|
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);
|
boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
|
||||||
if (success) {
|
if (!success) {
|
||||||
newWallet.setPassword(password);
|
|
||||||
success = success && newWallet.store();
|
|
||||||
} else {
|
|
||||||
Timber.e(newWallet.getErrorString());
|
Timber.e(newWallet.getErrorString());
|
||||||
toast(newWallet.getErrorString());
|
toast(newWallet.getErrorString());
|
||||||
}
|
}
|
||||||
|
@ -903,19 +899,17 @@ public class LoginActivity extends SecureActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGenerate(String name, String password,
|
public void onGenerate(final String name, final String password,
|
||||||
final String address, final String viewKey, final String spendKey, final long restoreHeight) {
|
final String address, final String viewKey, final String spendKey,
|
||||||
|
final long restoreHeight) {
|
||||||
createWallet(name, password,
|
createWallet(name, password,
|
||||||
new WalletCreator() {
|
new WalletCreator() {
|
||||||
public boolean createWallet(File aFile, String password) {
|
public boolean createWallet(File aFile, String password) {
|
||||||
Wallet newWallet = WalletManager.getInstance()
|
Wallet newWallet = WalletManager.getInstance()
|
||||||
.createWalletFromKeys(aFile, MNEMONIC_LANGUAGE, restoreHeight,
|
.createWalletWithKeys(aFile, password, MNEMONIC_LANGUAGE, restoreHeight,
|
||||||
address, viewKey, spendKey);
|
address, viewKey, spendKey);
|
||||||
boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
|
boolean success = (newWallet.getStatus() == Wallet.Status.Status_Ok);
|
||||||
if (success) {
|
if (!success) {
|
||||||
newWallet.setPassword(password);
|
|
||||||
success = success && newWallet.store();
|
|
||||||
} else {
|
|
||||||
Timber.e(newWallet.getErrorString());
|
Timber.e(newWallet.getErrorString());
|
||||||
toast(newWallet.getErrorString());
|
toast(newWallet.getErrorString());
|
||||||
}
|
}
|
||||||
|
@ -936,16 +930,10 @@ public class LoginActivity extends SecureActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccept(final String name, final String password) {
|
public void onAccept(final String name, final String password) {
|
||||||
File newWalletFile = new File(Helper.getNewWalletDir(getApplicationContext()), name);
|
File walletFolder = getStorageRoot();
|
||||||
Timber.d("New Wallet %s", newWalletFile.getAbsolutePath());
|
File walletFile = new File(walletFolder, name);
|
||||||
newWalletFile.delete(); // when recovering wallets, the cache seems corrupt
|
Timber.d("New Wallet %s", walletFile.getAbsolutePath());
|
||||||
// TODO: figure out why this is so? Only for a private testnet?
|
walletFile.delete(); // when recovering wallets, the cache seems corrupt
|
||||||
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
boolean rc = testWallet(walletFile.getAbsolutePath(), password) == Wallet.Status.Status_Ok;
|
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);
|
private native long openWalletJ(String path, String password, boolean isTestNet);
|
||||||
|
|
||||||
public Wallet recoveryWallet(File aFile, String mnemonic) {
|
public Wallet recoveryWallet(File aFile, String password, String mnemonic) {
|
||||||
Wallet wallet = recoveryWallet(aFile, mnemonic, 0);
|
return recoveryWallet(aFile, password, mnemonic, 0);
|
||||||
manageWallet(wallet);
|
|
||||||
return wallet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Wallet recoveryWallet(File aFile, String mnemonic, long restoreHeight) {
|
public Wallet recoveryWallet(File aFile, String password, String mnemonic, long restoreHeight) {
|
||||||
long walletHandle = recoveryWalletJ(aFile.getAbsolutePath(), mnemonic, isTestNet(), restoreHeight);
|
long walletHandle = recoveryWalletJ(aFile.getAbsolutePath(), password, mnemonic,
|
||||||
|
isTestNet(), restoreHeight);
|
||||||
Wallet wallet = new Wallet(walletHandle);
|
Wallet wallet = new Wallet(walletHandle);
|
||||||
manageWallet(wallet);
|
manageWallet(wallet);
|
||||||
return 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) {
|
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);
|
addressString, viewKeyString, spendKeyString);
|
||||||
Wallet wallet = new Wallet(walletHandle);
|
Wallet wallet = new Wallet(walletHandle);
|
||||||
manageWallet(wallet);
|
manageWallet(wallet);
|
||||||
return wallet;
|
return wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native long createWalletFromKeysJ(String path, String language,
|
private native long createWalletWithKeysJ(String path, String password,
|
||||||
|
String language,
|
||||||
boolean isTestNet,
|
boolean isTestNet,
|
||||||
long restoreHeight,
|
long restoreHeight,
|
||||||
String addressString,
|
String addressString,
|
||||||
|
|
|
@ -58,17 +58,6 @@ public class Helper {
|
||||||
|
|
||||||
static public int DISPLAY_DIGITS_INFO = 5;
|
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) {
|
static public File getStorageRoot(Context context) {
|
||||||
if (!isExternalStorageWritable()) {
|
if (!isExternalStorageWritable()) {
|
||||||
String msg = context.getString(R.string.message_strorage_not_writable);
|
String msg = context.getString(R.string.message_strorage_not_writable);
|
||||||
|
|
|
@ -630,6 +630,18 @@ struct WalletManager
|
||||||
virtual Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) = 0;
|
virtual Wallet * openWallet(const std::string &path, const std::string &password, bool testnet = false) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
* \brief recovers existing wallet using memo (electrum seed)
|
||||||
|
* \param path Name of wallet file to be created
|
||||||
|
* \param password Password of wallet file
|
||||||
|
* \param memo memo (25 words electrum seed)
|
||||||
|
* \param testnet testnet
|
||||||
|
* \param restoreHeight restore from start height
|
||||||
|
* \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
|
||||||
|
*/
|
||||||
|
virtual Wallet * recoveryWallet(const std::string &path, const std::string &password, const std::string &memo, bool testnet = false, uint64_t restoreHeight = 0) = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \deprecated this method creates a wallet WITHOUT a psssphrase, use the alternate recoverWallet() method
|
||||||
* \brief recovers existing wallet using memo (electrum seed)
|
* \brief recovers existing wallet using memo (electrum seed)
|
||||||
* \param path Name of wallet file to be created
|
* \param path Name of wallet file to be created
|
||||||
* \param memo memo (25 words electrum seed)
|
* \param memo memo (25 words electrum seed)
|
||||||
|
@ -640,6 +652,28 @@ struct WalletManager
|
||||||
virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet = false, uint64_t restoreHeight = 0) = 0;
|
virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet = false, uint64_t restoreHeight = 0) = 0;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
* \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
|
||||||
|
* \param path Name of wallet file to be created
|
||||||
|
* \param password Password of wallet file
|
||||||
|
* \param language language
|
||||||
|
* \param testnet testnet
|
||||||
|
* \param restoreHeight restore from start height
|
||||||
|
* \param addressString public address
|
||||||
|
* \param viewKeyString view key
|
||||||
|
* \param spendKeyString spend key (optional)
|
||||||
|
* \return Wallet instance (Wallet::status() needs to be called to check if recovered successfully)
|
||||||
|
*/
|
||||||
|
virtual Wallet * createWalletWithKeys(const std::string &path,
|
||||||
|
const std::string &password,
|
||||||
|
const std::string &language,
|
||||||
|
bool testnet,
|
||||||
|
uint64_t restoreHeight,
|
||||||
|
const std::string &addressString,
|
||||||
|
const std::string &viewKeyString,
|
||||||
|
const std::string &spendKeyString = "") = 0;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \deprecated this method creates a wallet WITHOUT a psssphrase, use createWalletWithKeys() instead
|
||||||
* \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
|
* \brief recovers existing wallet using keys. Creates a view only wallet if spend key is omitted
|
||||||
* \param path Name of wallet file to be created
|
* \param path Name of wallet file to be created
|
||||||
* \param language language
|
* \param language language
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue