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
|
||||
Java_com_m2049r_xmrwallet_model_WalletManager_recoveryWalletJ(JNIEnv *env, jobject instance,
|
||||
jstring path, jstring mnemonic,
|
||||
jstring path, jstring password,
|
||||
jstring mnemonic,
|
||||
jboolean isTestNet,
|
||||
jlong restoreHeight) {
|
||||
const char *_path = env->GetStringUTFChars(path, NULL);
|
||||
const char *_password = env->GetStringUTFChars(password, NULL);
|
||||
const char *_mnemonic = env->GetStringUTFChars(mnemonic, NULL);
|
||||
|
||||
Bitmonero::Wallet *wallet =
|
||||
Bitmonero::WalletManagerFactory::getWalletManager()->recoveryWallet(
|
||||
std::string(_path),
|
||||
std::string(_password),
|
||||
std::string(_mnemonic),
|
||||
isTestNet,
|
||||
restoreHeight);
|
||||
|
||||
env->ReleaseStringUTFChars(path, _path);
|
||||
env->ReleaseStringUTFChars(password, _password);
|
||||
env->ReleaseStringUTFChars(mnemonic, _mnemonic);
|
||||
return reinterpret_cast<jlong>(wallet);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromKeysJ(JNIEnv *env, jobject instance,
|
||||
jstring path, jstring language,
|
||||
Java_com_m2049r_xmrwallet_model_WalletManager_createWalletWithKeysJ(JNIEnv *env, jobject instance,
|
||||
jstring path, jstring password,
|
||||
jstring language,
|
||||
jboolean isTestNet,
|
||||
jlong restoreHeight,
|
||||
jstring addressString,
|
||||
jstring viewKeyString,
|
||||
jstring spendKeyString) {
|
||||
const char *_path = env->GetStringUTFChars(path, NULL);
|
||||
const char *_password = env->GetStringUTFChars(password, NULL);
|
||||
const char *_language = env->GetStringUTFChars(language, NULL);
|
||||
const char *_addressString = env->GetStringUTFChars(addressString, NULL);
|
||||
const char *_viewKeyString = env->GetStringUTFChars(viewKeyString, NULL);
|
||||
const char *_spendKeyString = env->GetStringUTFChars(spendKeyString, NULL);
|
||||
|
||||
Bitmonero::Wallet *wallet =
|
||||
Bitmonero::WalletManagerFactory::getWalletManager()->createWalletFromKeys(
|
||||
Bitmonero::WalletManagerFactory::getWalletManager()->createWalletWithKeys(
|
||||
std::string(_path),
|
||||
std::string(_password),
|
||||
std::string(_language),
|
||||
isTestNet,
|
||||
restoreHeight,
|
||||
|
@ -334,6 +341,7 @@ Java_com_m2049r_xmrwallet_model_WalletManager_createWalletFromKeysJ(JNIEnv *env,
|
|||
std::string(_spendKeyString));
|
||||
|
||||
env->ReleaseStringUTFChars(path, _path);
|
||||
env->ReleaseStringUTFChars(password, _password);
|
||||
env->ReleaseStringUTFChars(language, _language);
|
||||
env->ReleaseStringUTFChars(addressString, _addressString);
|
||||
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
|
||||
|
||||
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);
|
||||
|
|
|
@ -630,6 +630,18 @@ struct WalletManager
|
|||
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)
|
||||
* \param path Name of wallet file to be created
|
||||
* \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;
|
||||
|
||||
/*!
|
||||
* \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
|
||||
* \param path Name of wallet file to be created
|
||||
* \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