Skip to content

Commit

Permalink
ledger: throw error if device is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
tobtoht committed Dec 18, 2024
1 parent 665c304 commit f10ad63
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/device/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace hw {
public:
virtual void on_button_request(uint64_t code=0) {}
virtual void on_button_pressed() {}
virtual void on_error(const std::string &message) {}
virtual void on_error(const std::string &message, unsigned int error_code = 0) {}
virtual boost::optional<epee::wipeable_string> on_pin_request() { return boost::none; }
virtual boost::optional<epee::wipeable_string> on_passphrase_request(bool & on_device) { on_device = true; return boost::none; }
virtual void on_progress(const device_progress& event) {}
Expand Down
8 changes: 8 additions & 0 deletions src/device/device_ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ namespace hw {
MDEBUG("Device "<< this->id << " exchange: sw: " << this->sw << " expected: " << ok);
ASSERT_X(sw != SW_CLIENT_NOT_SUPPORTED, "Monero Ledger App doesn't support current monero version. Try to update the Monero Ledger App, at least " << MINIMAL_APP_VERSION_MAJOR<< "." << MINIMAL_APP_VERSION_MINOR << "." << MINIMAL_APP_VERSION_MICRO << " is required.");
ASSERT_X(sw != SW_PROTOCOL_NOT_SUPPORTED, "Make sure no other program is communicating with the Ledger.");
if (sw == SW_UNKNOWN_PROBABLY_LOCKED) {
hw_device.disconnected = true;
if (m_callback) {
m_callback->on_error("Make sure the device is unlocked", sw);
}
throw hw::error::device_disconnected("Device is locked");
}

ASSERT_SW(this->sw,ok,mask);

return this->sw;
Expand Down
1 change: 1 addition & 0 deletions src/device/device_ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace hw {
#define SW_INS_NOT_SUPPORTED 0x6d00
#define SW_PROTOCOL_NOT_SUPPORTED 0x6e00
#define SW_UNKNOWN 0x6f00
#define SW_UNKNOWN_PROBABLY_LOCKED 0x5515

namespace {
bool apdu_verbose =true;
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/api/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ struct Wallet2CallbackImpl : public tools::i_wallet2_callback
}
}

virtual void on_device_error(const std::string &message)
virtual void on_device_error(const std::string &message, unsigned int error_code)
{
if (m_listener) {
m_listener->onDeviceError(message);
m_listener->onDeviceError(message, error_code);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wallet/api/wallet2_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ struct WalletListener
/**
* @brief called by device if an error occurred
*/
virtual void onDeviceError(const std::string &msg) {};
virtual void onDeviceError(const std::string &msg, unsigned int errorCode) {};

/**
* @brief called by device when PIN is needed
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,10 +1173,10 @@ void wallet_device_callback::on_button_pressed()
wallet->on_device_button_pressed();
}

void wallet_device_callback::on_error(const std::string &message)
void wallet_device_callback::on_error(const std::string &message, unsigned int error_code)
{
if (wallet)
wallet->on_device_error(message);
wallet->on_device_error(message, error_code);
}

boost::optional<epee::wipeable_string> wallet_device_callback::on_pin_request()
Expand Down Expand Up @@ -1528,7 +1528,7 @@ bool wallet2::reconnect_device()

r = hwdev.connect();
if (!r){
m_callback->on_device_error("Unable to reconnect to device");
m_callback->on_device_error("Unable to reconnect to device", 0);
MERROR("Could not connect to the device");
return false;
}
Expand Down Expand Up @@ -15744,10 +15744,10 @@ void wallet2::on_device_button_pressed()
m_callback->on_device_button_pressed();
}
//----------------------------------------------------------------------------------------------------
void wallet2::on_device_error(const std::string &message)
void wallet2::on_device_error(const std::string &message, unsigned int error_code)
{
if (nullptr != m_callback)
m_callback->on_device_error(message);
m_callback->on_device_error(message, error_code);
}
//----------------------------------------------------------------------------------------------------
boost::optional<epee::wipeable_string> wallet2::on_device_pin_request()
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ namespace tools
// Device callbacks
virtual void on_device_button_request(uint64_t code) {}
virtual void on_device_button_pressed() {}
virtual void on_device_error(const std::string &msg) {}
virtual void on_device_error(const std::string &msg, unsigned int errorCode) {}
virtual boost::optional<epee::wipeable_string> on_device_pin_request() { return boost::none; }
virtual boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device) { on_device = true; return boost::none; }
virtual void on_device_progress(const hw::device_progress& event) {};
Expand All @@ -168,7 +168,7 @@ namespace tools
wallet_device_callback(wallet2 * wallet): wallet(wallet) {};
void on_button_request(uint64_t code=0) override;
void on_button_pressed() override;
void on_error(const std::string &message) override;
void on_error(const std::string &message, unsigned int error_code) override;
boost::optional<epee::wipeable_string> on_pin_request() override;
boost::optional<epee::wipeable_string> on_passphrase_request(bool & on_device) override;
void on_progress(const hw::device_progress& event) override;
Expand Down Expand Up @@ -1895,7 +1895,7 @@ namespace tools
wallet_device_callback * get_device_callback();
void on_device_button_request(uint64_t code);
void on_device_button_pressed();
void on_device_error(const std::string &message);
void on_device_error(const std::string &message, unsigned int errorCode);
boost::optional<epee::wipeable_string> on_device_pin_request();
boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device);
void on_device_progress(const hw::device_progress& event);
Expand Down

0 comments on commit f10ad63

Please sign in to comment.