From 69f44200117beb1de8236a6f851e8c924a8ca083 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 27 May 2019 15:10:14 -0400 Subject: [PATCH] remove wipeable_strings; implemented getDaemonConnection() --- src/daemon/MoneroDaemon.h | 8 ++++---- src/wallet/MoneroWallet.cpp | 23 ++++++++++++++++++----- src/wallet/MoneroWallet.h | 6 +++--- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/daemon/MoneroDaemon.h b/src/daemon/MoneroDaemon.h index aa1b35f..c332dc8 100644 --- a/src/daemon/MoneroDaemon.h +++ b/src/daemon/MoneroDaemon.h @@ -21,10 +21,10 @@ namespace monero { * Models a connection to a daemon. */ struct MoneroRpcConnection { + string uri; + string username; + string password; //MoneroRpcConnection() : uri(""), username(""), password("")) {} - MoneroRpcConnection(const string& uri = "", const string& username = "", const epee::wipeable_string& password = epee::wipeable_string()) : uri(uri), username(username), password(password) {} - const string& uri; - const string& username; - const epee::wipeable_string& password; + MoneroRpcConnection(const string& uri = "", const string& username = "", const string& password = "") : uri(uri), username(username), password(password) {} }; } diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index b064ddd..aa24f90 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -19,6 +19,7 @@ MoneroWallet::MoneroWallet() { } MoneroWallet::MoneroWallet(const MoneroNetworkType networkType, const MoneroRpcConnection& daemonConnection, const string& language) { + cout << "MoneroWallet(3)" << endl; wallet2 = new tools::wallet2(static_cast(networkType), 1, true); MoneroWallet::setDaemonConnection(daemonConnection.uri, daemonConnection.username, daemonConnection.password); wallet2->set_seed_language(language); @@ -36,7 +37,8 @@ MoneroWallet::MoneroWallet(const string& address, const string& viewKey, const s throw runtime_error("Not implemented"); } -MoneroWallet::MoneroWallet(const string& path, const epee::wipeable_string& password, const MoneroNetworkType networkType) { +MoneroWallet::MoneroWallet(const string& path, const string& password, const MoneroNetworkType networkType) { + cout << "MoneroWallet(3b)" << endl; wallet2 = new tools::wallet2(static_cast(networkType), 1, true); wallet2->load(path, password); } @@ -45,7 +47,8 @@ MoneroWallet::~MoneroWallet() { cout << "~MoneroWallet()" << endl; } -void MoneroWallet::setDaemonConnection(const string& uri, const string& username, const epee::wipeable_string& password) { +void MoneroWallet::setDaemonConnection(const string& uri, const string& username, const string& password) { + cout << "setDaemonConnection(" << uri << ", " << username << ", " << password << ")" << endl; // prepare uri, login, and isTrusted for wallet2 boost::optional login{}; @@ -59,15 +62,25 @@ void MoneroWallet::setDaemonConnection(const string& uri, const string& username } MoneroRpcConnection MoneroWallet::getDaemonConnection() { - throw runtime_error("ready to implement getDaemonConnection()"); + MoneroRpcConnection connection; + if (!wallet2->get_daemon_address().empty()) connection.uri = wallet2->get_daemon_address(); + if (wallet2->get_daemon_login()) { + if (!wallet2->get_daemon_login()->username.empty()) connection.username = wallet2->get_daemon_login()->username; + epee::wipeable_string wipeablePassword = wallet2->get_daemon_login()->password; + string password = string(wipeablePassword.data(), wipeablePassword.size()); + if (!password.empty()) connection.password = password; + } + return connection; } MoneroNetworkType MoneroWallet::getNetworkType() { return static_cast(wallet2->nettype()); } -void MoneroWallet::getMnemonic(epee::wipeable_string& mnemonic) const { - wallet2->get_seed(mnemonic); +string MoneroWallet::getMnemonic() const { + epee::wipeable_string wipeablePassword; + wallet2->get_seed(wipeablePassword); + return string(wipeablePassword.data(), wipeablePassword.size()); } string MoneroWallet::getAddress(uint32_t accountIdx, uint32_t subaddressIdx) { diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index b09afc2..432c5af 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -66,7 +66,7 @@ using namespace crypto; * @param password is the password of the wallet file to open * @param networkType is the wallet's network type */ - MoneroWallet(const string& path, const epee::wipeable_string& password, const MoneroNetworkType networkType); + MoneroWallet(const string& path, const string& password, const MoneroNetworkType networkType); /** * Deconstructs the wallet. @@ -82,7 +82,7 @@ using namespace crypto; * @param username is the daemon's username * @param password is the daemon's password */ - void setDaemonConnection(const string& uri, const string& username, const epee::wipeable_string& password); + void setDaemonConnection(const string& uri, const string& username, const string& password); MoneroRpcConnection getDaemonConnection(); @@ -100,7 +100,7 @@ using namespace crypto; * * @param mnemonic is assigned the wallet's mnemonic phrase */ - void getMnemonic(epee::wipeable_string& mnemonic) const; + string getMnemonic() const; /** * Get the address of a specific subaddress.