mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Add the possibility to export private view key for fast scan.
On client startup the device asks for authorization to export the private view key. If user agree, the client hold the private view key allowing a fast blockchain scan. If the user does not agree, the blockchain scan is fully done via the device.
This commit is contained in:
parent
ebbf84900d
commit
709a0557d2
4 changed files with 39 additions and 50 deletions
|
@ -78,6 +78,7 @@ namespace hw {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class device {
|
class device {
|
||||||
protected:
|
protected:
|
||||||
std::string name;
|
std::string name;
|
||||||
|
@ -89,10 +90,12 @@ namespace hw {
|
||||||
virtual ~device() {}
|
virtual ~device() {}
|
||||||
|
|
||||||
explicit virtual operator bool() const = 0;
|
explicit virtual operator bool() const = 0;
|
||||||
|
enum device_mode {
|
||||||
static const int SIGNATURE_REAL = 0;
|
NONE,
|
||||||
static const int SIGNATURE_FAKE = 1;
|
TRANSACTION_CREATE_REAL,
|
||||||
|
TRANSACTION_CREATE_FAKE,
|
||||||
|
TRANSACTION_PARSE
|
||||||
|
};
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* SETUP/TEARDOWN */
|
/* SETUP/TEARDOWN */
|
||||||
|
@ -106,6 +109,9 @@ namespace hw {
|
||||||
virtual bool connect(void) = 0;
|
virtual bool connect(void) = 0;
|
||||||
virtual bool disconnect(void) = 0;
|
virtual bool disconnect(void) = 0;
|
||||||
|
|
||||||
|
virtual bool set_mode(device_mode mode) = 0;
|
||||||
|
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* LOCKER */
|
/* LOCKER */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
|
@ -82,6 +82,9 @@ namespace hw {
|
||||||
dfns();
|
dfns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool device_default::set_mode(device_mode mode) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* LOCKER */
|
/* LOCKER */
|
||||||
|
|
|
@ -511,12 +511,13 @@ namespace hw {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool device_ledger::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) {
|
bool device_ledger::get_secret_keys(crypto::secret_key &vkey , crypto::secret_key &skey) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
memset(viewkey.data, 0x00, 32);
|
|
||||||
memset(spendkey.data, 0xFF, 32);
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
//secret key are represented as fake key on the wallet side
|
||||||
|
memset(vkey.data, 0x00, 32);
|
||||||
|
memset(skey.data, 0xFF, 32);
|
||||||
|
|
||||||
//spcialkey, normal conf handled in decrypt
|
//spcialkey, normal conf handled in decrypt
|
||||||
int offset;
|
int offset;
|
||||||
reset_buffer();
|
reset_buffer();
|
||||||
|
@ -535,11 +536,21 @@ namespace hw {
|
||||||
this->length_send = offset;
|
this->length_send = offset;
|
||||||
this->exchange();
|
this->exchange();
|
||||||
|
|
||||||
//clear key
|
//View key is retrievied, if allowed, to speed up blockchain parsing
|
||||||
memmove(ledger::viewkey.data, this->buffer_recv+64, 32);
|
memmove(this->viewkey.data, this->buffer_recv+0, 32);
|
||||||
memmove(ledger::spendkey.data, this->buffer_recv+96, 32);
|
if (is_fake_view_key(this->viewkey)) {
|
||||||
|
MDEBUG("Have Not view key");
|
||||||
|
this->has_view_key = false;
|
||||||
|
} else {
|
||||||
|
MDEBUG("Have view key");
|
||||||
|
this->has_view_key = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_HWDEVICE
|
||||||
|
memmove(dbg_viewkey.data, this->buffer_recv+0, 32);
|
||||||
|
memmove(dbg_spendkey.data, this->buffer_recv+32, 32);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -585,8 +596,6 @@ namespace hw {
|
||||||
|
|
||||||
bool device_ledger::derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub){
|
bool device_ledger::derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub){
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::public_key pub_x = pub;
|
const crypto::public_key pub_x = pub;
|
||||||
crypto::key_derivation derivation_x;
|
crypto::key_derivation derivation_x;
|
||||||
|
@ -643,7 +652,7 @@ namespace hw {
|
||||||
|
|
||||||
//pub key
|
//pub key
|
||||||
memmove(derived_pub.data, &this->buffer_recv[0], 32);
|
memmove(derived_pub.data, &this->buffer_recv[0], 32);
|
||||||
|
}
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data);
|
hw::ledger::check32("derive_subaddress_public_key", "derived_pub", derived_pub_x.data, derived_pub.data);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1033,7 +1042,7 @@ namespace hw {
|
||||||
|
|
||||||
bool device_ledger::generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) {
|
bool device_ledger::generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
bool r = false;
|
||||||
|
|
||||||
#ifdef DEBUG_HWDEVICE
|
#ifdef DEBUG_HWDEVICE
|
||||||
const crypto::public_key pub_x = pub;
|
const crypto::public_key pub_x = pub;
|
||||||
|
@ -1095,10 +1104,6 @@ namespace hw {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) {
|
bool device_ledger::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
int offset;
|
||||||
|
@ -1384,32 +1389,6 @@ namespace hw {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool device_ledger::set_signature_mode(unsigned int sig_mode) {
|
|
||||||
AUTO_LOCK_CMD();
|
|
||||||
int offset ;
|
|
||||||
|
|
||||||
reset_buffer();
|
|
||||||
|
|
||||||
this->buffer_send[0] = 0x00;
|
|
||||||
this->buffer_send[1] = INS_SET_SIGNATURE_MODE;
|
|
||||||
this->buffer_send[2] = 0x01;
|
|
||||||
this->buffer_send[3] = 0x00;
|
|
||||||
this->buffer_send[4] = 0x00;
|
|
||||||
offset = 5;
|
|
||||||
//options
|
|
||||||
this->buffer_send[offset] = 0x00;
|
|
||||||
offset += 1;
|
|
||||||
//account
|
|
||||||
this->buffer_send[offset] = sig_mode;
|
|
||||||
offset += 1;
|
|
||||||
|
|
||||||
this->buffer_send[4] = offset-5;
|
|
||||||
this->length_send = offset;
|
|
||||||
this->exchange();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) {
|
bool device_ledger::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) {
|
||||||
AUTO_LOCK_CMD();
|
AUTO_LOCK_CMD();
|
||||||
int offset;
|
int offset;
|
||||||
|
|
|
@ -138,6 +138,7 @@ namespace hw {
|
||||||
bool connect(void) override;
|
bool connect(void) override;
|
||||||
bool disconnect() override;
|
bool disconnect() override;
|
||||||
|
|
||||||
|
bool set_mode(device_mode mode) override;
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* LOCKER */
|
/* LOCKER */
|
||||||
|
|
Loading…
Reference in a new issue