aboutsummaryrefslogtreecommitdiff
path: root/src/device/device_ledger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/device/device_ledger.cpp')
-rw-r--r--src/device/device_ledger.cpp49
1 files changed, 39 insertions, 10 deletions
diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp
index bfb41bbe4..9daf62d37 100644
--- a/src/device/device_ledger.cpp
+++ b/src/device/device_ledger.cpp
@@ -176,7 +176,7 @@ namespace hw {
#define INS_GET_RESPONSE 0xc0
- device_ledger::device_ledger(): hw_device(0x0101, 0x05, 64, 120000) {
+ device_ledger::device_ledger(): hw_device(0x0101, 0x05, 64, 2000) {
this->id = device_id++;
this->reset_buffer();
this->mode = NONE;
@@ -235,6 +235,9 @@ namespace hw {
/* IO */
/* ======================================================================= */
+ #define IO_SW_DENY 0x6982
+ #define IO_SECRET_KEY 0x02
+
void device_ledger::logCMD() {
if (apdu_verbose) {
char strbuffer[1024];
@@ -283,7 +286,12 @@ namespace hw {
void device_ledger::send_simple(unsigned char ins, unsigned char p1) {
this->length_send = set_command_header_noopt(ins, p1);
- this->exchange();
+ if (ins == INS_GET_KEY && p1 == IO_SECRET_KEY) {
+ // export view key user input
+ this->exchange_wait_on_input();
+ } else {
+ this->exchange();
+ }
}
bool device_ledger::reset() {
@@ -294,7 +302,7 @@ namespace hw {
unsigned int device_ledger::exchange(unsigned int ok, unsigned int mask) {
logCMD();
- this->length_recv = hw_device.exchange(this->buffer_send, this->length_send, this->buffer_recv, BUFFER_SEND_SIZE);
+ this->length_recv = hw_device.exchange(this->buffer_send, this->length_send, this->buffer_recv, BUFFER_SEND_SIZE, false);
ASSERT_X(this->length_recv>=2, "Communication error, less than tow bytes received");
this->length_recv -= 2;
@@ -305,6 +313,25 @@ namespace hw {
return this->sw;
}
+ unsigned int device_ledger::exchange_wait_on_input(unsigned int ok, unsigned int mask) {
+ logCMD();
+ unsigned int deny = 0;
+ this->length_recv = hw_device.exchange(this->buffer_send, this->length_send, this->buffer_recv, BUFFER_SEND_SIZE, true);
+ ASSERT_X(this->length_recv>=2, "Communication error, less than two bytes received");
+
+ this->length_recv -= 2;
+ this->sw = (this->buffer_recv[length_recv]<<8) | this->buffer_recv[length_recv+1];
+ if (this->sw == IO_SW_DENY) {
+ // cancel on device
+ deny = 1;
+ } else {
+ ASSERT_SW(this->sw,ok,msk);
+ }
+
+ logRESP();
+ return deny;
+ }
+
void device_ledger::reset_buffer() {
this->length_send = 0;
memset(this->buffer_send, 0, BUFFER_SEND_SIZE);
@@ -322,7 +349,7 @@ namespace hw {
}
const std::string device_ledger::get_name() const {
- if (this->full_name.empty() || !this->connected()) {
+ if (!this->connected()) {
return std::string("<disconnected:").append(this->name).append(">");
}
return this->name;
@@ -1140,13 +1167,13 @@ namespace hw {
return true;
}
- bool device_ledger::ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & AKout) {
+ bool device_ledger::ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & AKout, bool short_amount) {
AUTO_LOCK_CMD();
#ifdef DEBUG_HWDEVICE
const rct::key AKout_x = hw::ledger::decrypt(AKout);
rct::ecdhTuple unmasked_x = unmasked;
- this->controle_device->ecdhEncode(unmasked_x, AKout_x);
+ this->controle_device->ecdhEncode(unmasked_x, AKout_x, short_amount);
#endif
int offset = set_command_header_noopt(INS_BLIND);
@@ -1177,13 +1204,13 @@ namespace hw {
return true;
}
- bool device_ledger::ecdhDecode(rct::ecdhTuple & masked, const rct::key & AKout) {
+ bool device_ledger::ecdhDecode(rct::ecdhTuple & masked, const rct::key & AKout, bool short_amount) {
AUTO_LOCK_CMD();
#ifdef DEBUG_HWDEVICE
const rct::key AKout_x = hw::ledger::decrypt(AKout);
rct::ecdhTuple masked_x = masked;
- this->controle_device->ecdhDecode(masked_x, AKout_x);
+ this->controle_device->ecdhDecode(masked_x, AKout_x, short_amount);
#endif
int offset = set_command_header_noopt(INS_UNBLIND);
@@ -1260,7 +1287,8 @@ namespace hw {
this->buffer_send[4] = offset-5;
this->length_send = offset;
- this->exchange();
+ // check fee user input
+ CHECK_AND_ASSERT_THROW_MES(this->exchange_wait_on_input() == 0, "Fee denied on device.");
//pseudoOuts
if (type == rct::RCTTypeSimple) {
@@ -1328,7 +1356,8 @@ namespace hw {
this->buffer_send[4] = offset-5;
this->length_send = offset;
- this->exchange();
+ // check transaction user input
+ CHECK_AND_ASSERT_THROW_MES(this->exchange_wait_on_input() == 0, "Transaction denied on device.");
#ifdef DEBUG_HWDEVICE
hw::ledger::log_hexbuffer("Prehash AKV input", (char*)&this->buffer_recv[64], 3*32);
#endif