mirror of
https://github.com/monero-project/monero.git
synced 2025-12-27 05:03:14 -08:00
Code modifications to integrate Ledger HW device into monero-wallet-cli.
The basic approach it to delegate all sensitive data (master key, secret ephemeral key, key derivation, ....) and related operations to the device. As device has low memory, it does not keep itself the values (except for view/spend keys) but once computed there are encrypted (with AES are equivalent) and return back to monero-wallet-cli. When they need to be manipulated by the device, they are decrypted on receive. Moreover, using the client for storing the value in encrypted form limits the modification in the client code. Those values are transfered from one C-structure to another one as previously. The code modification has been done with the wishes to be open to any other hardware wallet. To achieve that a C++ class hw::Device has been introduced. Two initial implementations are provided: the "default", which remaps all calls to initial Monero code, and the "Ledger", which delegates all calls to Ledger device.
This commit is contained in:
@@ -40,6 +40,7 @@ extern "C"
|
||||
}
|
||||
#include "cryptonote_basic_impl.h"
|
||||
#include "cryptonote_format_utils.h"
|
||||
#include "device/device.hpp"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "account"
|
||||
@@ -50,6 +51,17 @@ DISABLE_VS_WARNINGS(4244 4345)
|
||||
|
||||
namespace cryptonote
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
hw::device& account_keys::get_device() const {
|
||||
return *m_device;
|
||||
}
|
||||
//-----------------------------------------------------------------
|
||||
void account_keys::set_device( hw::device &hwdev) {
|
||||
m_device = &hwdev;
|
||||
MCDEBUG("device", "account_keys::set_device device type: "<<typeid(hwdev).name());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
account_base::account_base()
|
||||
{
|
||||
@@ -116,6 +128,34 @@ DISABLE_VS_WARNINGS(4244 4345)
|
||||
if (m_creation_timestamp == (uint64_t)-1) // failure
|
||||
m_creation_timestamp = 0; // lowest value
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
void account_base::create_from_device(const std::string &device_name)
|
||||
{
|
||||
|
||||
hw::device &hwdev = hw::get_device(device_name);
|
||||
m_keys.set_device(hwdev);
|
||||
hwdev.set_name(device_name);
|
||||
MCDEBUG("ledger", "device type: "<<typeid(hwdev).name());
|
||||
hwdev.init();
|
||||
hwdev.connect();
|
||||
hwdev.get_public_address(m_keys.m_account_address);
|
||||
#ifdef DEBUG_HWDEVICE
|
||||
hwdev.get_secret_keys(m_keys.m_view_secret_key, m_keys.m_spend_secret_key);
|
||||
#endif
|
||||
struct tm timestamp = {0};
|
||||
timestamp.tm_year = 2014 - 1900; // year 2014
|
||||
timestamp.tm_mon = 4 - 1; // month april
|
||||
timestamp.tm_mday = 15; // 15th of april
|
||||
timestamp.tm_hour = 0;
|
||||
timestamp.tm_min = 0;
|
||||
timestamp.tm_sec = 0;
|
||||
|
||||
m_creation_timestamp = mktime(×tamp);
|
||||
if (m_creation_timestamp == (uint64_t)-1) // failure
|
||||
m_creation_timestamp = 0; // lowest value
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
void account_base::create_from_viewkey(const cryptonote::account_public_address& address, const crypto::secret_key& viewkey)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user