diff --git a/firmware/fsm.h b/firmware/fsm.h index b8af6d1549..dc80280a61 100644 --- a/firmware/fsm.h +++ b/firmware/fsm.h @@ -81,6 +81,7 @@ void fsm_msgCosiCommit(CosiCommit *msg); void fsm_msgCosiSign(CosiSign *msg); // Stellar +void fsm_msgStellarGetAddress(StellarGetAddress *msg); void fsm_msgStellarGetPublicKey(StellarGetPublicKey *msg); void fsm_msgStellarSignTx(StellarSignTx *msg); void fsm_msgStellarPaymentOp(StellarPaymentOp *msg); diff --git a/firmware/fsm_msg_stellar.h b/firmware/fsm_msg_stellar.h index d621323a52..38b176586c 100644 --- a/firmware/fsm_msg_stellar.h +++ b/firmware/fsm_msg_stellar.h @@ -1,3 +1,41 @@ +void fsm_msgStellarGetAddress(StellarGetAddress *msg) +{ + RESP_INIT(StellarAddress); + + CHECK_INITIALIZED + + CHECK_PIN + + HDNode *node = stellar_deriveNode(msg->address_n, msg->address_n_count); + if (!node) { + fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to derive private key")); + return; + } + + if (msg->has_show_display && msg->show_display) { + const char **str_addr_rows = stellar_lineBreakAddress(node->public_key + 1); + layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), _("Share public account ID?"), + str_addr_rows[0], + str_addr_rows[1], + str_addr_rows[2], + NULL, + NULL, NULL + ); + if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } + + resp->has_address = true; + stellar_publicAddressAsStr(node->public_key + 1, resp->address, sizeof(resp->address)); + + msg_write(MessageType_MessageType_StellarAddress, resp); + + layoutHome(); +} + void fsm_msgStellarGetPublicKey(StellarGetPublicKey *msg) { RESP_INIT(StellarPublicKey); @@ -6,13 +44,34 @@ void fsm_msgStellarGetPublicKey(StellarGetPublicKey *msg) CHECK_PIN - // Will exit if the user does not confirm - stellar_layoutGetPublicKey(msg->address_n, msg->address_n_count); + HDNode *node = stellar_deriveNode(msg->address_n, msg->address_n_count); + if (!node) { + fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to derive private key")); + return; + } + + if (msg->has_show_display && msg->show_display) { + char hex[32 * 2 + 1]; + data2hex(node->public_key + 1, 32, hex); + const char **str_pubkey_rows = split_message((const uint8_t *)hex, 32 * 2, 16); + layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), _("Share public account ID?"), + str_pubkey_rows[0], + str_pubkey_rows[1], + str_pubkey_rows[2], + str_pubkey_rows[3], + NULL, NULL + ); + if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { + fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); + layoutHome(); + return; + } + } // Read public key and write it to the response resp->has_public_key = true; resp->public_key.size = 32; - stellar_getPubkeyAtAddress(msg->address_n, msg->address_n_count, resp->public_key.bytes, sizeof(resp->public_key.bytes)); + memcpy(resp->public_key.bytes, node->public_key + 1, 32); msg_write(MessageType_MessageType_StellarPublicKey, resp); diff --git a/firmware/layout2.c b/firmware/layout2.c index 6d47a8322d..9e3d42ee14 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -153,7 +153,7 @@ static const char *address_n_str(const uint32_t *address_n, size_t address_n_cou } // split longer string into 4 rows, rowlen chars each -static const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen) +const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen) { static char str[4][32 + 1]; if (rowlen > 32) { diff --git a/firmware/layout2.h b/firmware/layout2.h index 2c523a242e..43f1d76a8a 100644 --- a/firmware/layout2.h +++ b/firmware/layout2.h @@ -68,4 +68,6 @@ void layoutNEMLevy(const NEMMosaicDefinition *definition, uint8_t network); void layoutCosiCommitSign(const uint32_t *address_n, size_t address_n_count, const uint8_t *data, uint32_t len, bool final_sign); +const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen); + #endif diff --git a/firmware/protob/messages.options b/firmware/protob/messages.options index 0c66b476d8..84f440c16c 100644 --- a/firmware/protob/messages.options +++ b/firmware/protob/messages.options @@ -177,6 +177,10 @@ CosiSignature.signature max_size:32 # Stellar +StellarGetAddress.address_n max_count:10 + +StellarAddress.address max_size:57 + StellarGetPublicKey.address_n max_count:10 StellarPublicKey.public_key max_size:32 @@ -242,6 +246,9 @@ LiskGetPublicKey skip_message:true LiskAddress skip_message:true LiskSignedTx skip_message:true LiskPublicKey skip_message:true +LiskSignMessage skip_message:true +LiskMessageSignature skip_message:true +LiskVerifyMessage skip_message:true # used only in debug firmware diff --git a/firmware/stellar.c b/firmware/stellar.c index 8f13218273..195c82eb16 100644 --- a/firmware/stellar.c +++ b/firmware/stellar.c @@ -45,32 +45,6 @@ static bool stellar_signing = false; static StellarTransaction stellar_activeTx; -static const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen) -{ - static char str[4][32 + 1]; - if (rowlen > 32) { - rowlen = 32; - } - memset(str, 0, sizeof(str)); - strlcpy(str[0], (char *)msg, rowlen + 1); - if (len > rowlen) { - strlcpy(str[1], (char *)msg + rowlen, rowlen + 1); - } - if (len > rowlen * 2) { - strlcpy(str[2], (char *)msg + rowlen * 2, rowlen + 1); - } - if (len > rowlen * 3) { - strlcpy(str[3], (char *)msg + rowlen * 3, rowlen + 1); - } - if (len > rowlen * 4) { - str[3][rowlen - 1] = '.'; - str[3][rowlen - 2] = '.'; - str[3][rowlen - 3] = '.'; - } - static const char *ret[4] = { str[0], str[1], str[2], str[3] }; - return ret; -} - /* * Starts the signing process and parses the transaction header */ @@ -100,16 +74,19 @@ void stellar_signingInit(StellarSignTx *msg) stellar_hashupdate_bytes(tx_type_bytes, sizeof(tx_type_bytes)); // Public key comes from deriving the specified account path - uint8_t bytes_pubkey[32]; - stellar_getPubkeyAtAddress(msg->address_n, msg->address_n_count, bytes_pubkey, sizeof(bytes_pubkey)); - memcpy(&(stellar_activeTx.signing_pubkey), bytes_pubkey, sizeof(stellar_activeTx.signing_pubkey)); + HDNode *node = stellar_deriveNode(msg->address_n, msg->address_n_count); + if (!node) { + // TODO: bail on error + return; + } + memcpy(&(stellar_activeTx.signing_pubkey), node->public_key + 1, sizeof(stellar_activeTx.signing_pubkey)); stellar_activeTx.address_n_count = msg->address_n_count; // todo: fix sizeof check memcpy(&(stellar_activeTx.address_n), &(msg->address_n), sizeof(stellar_activeTx.address_n)); // Hash: public key - stellar_hashupdate_address(bytes_pubkey); + stellar_hashupdate_address(node->public_key + 1); // Hash: fee stellar_hashupdate_uint32(msg->fee); @@ -1319,23 +1296,6 @@ uint16_t stellar_crc16(uint8_t *bytes, uint32_t length) return crc & 0xffff; } -/* - * Writes 32-byte public key to out - */ -void stellar_getPubkeyAtAddress(uint32_t *address_n, size_t address_n_count, uint8_t *out, size_t outlen) -{ - if (outlen < 32) return; - - HDNode *node = stellar_deriveNode(address_n, address_n_count); - - if (node == 0) { - stellar_signingAbort(); - return; - } - - memcpy(out, node->public_key + 1, outlen); -} - /* * Derives the HDNode at the given index * Standard Stellar prefix is m/44'/148'/ and the default account is m/44'/148'/0' @@ -1637,8 +1597,11 @@ void stellar_layoutSigningDialog(const char *line1, const char *line2, const cha int offset_y = 1; int line_height = 9; - uint8_t public_key[32]; - stellar_getPubkeyAtAddress(address_n, address_n_count, public_key, sizeof(public_key)); + HDNode *node = stellar_deriveNode(address_n, address_n_count); + if (!node) { + // TODO: bail on error + return; + } char str_pubaddr_truncated[12]; // G???? + null memset(str_pubaddr_truncated, 0, sizeof(str_pubaddr_truncated)); @@ -1650,7 +1613,7 @@ void stellar_layoutSigningDialog(const char *line1, const char *line2, const cha // Load up public address char str_pubaddr[56+1]; memset(str_pubaddr, 0, sizeof(str_pubaddr)); - stellar_publicAddressAsStr(public_key, str_pubaddr, sizeof(str_pubaddr)); + stellar_publicAddressAsStr(node->public_key + 1, str_pubaddr, sizeof(str_pubaddr)); memcpy(str_pubaddr_truncated, str_pubaddr, sizeof(str_pubaddr_truncated) - 1); // Header @@ -1742,25 +1705,4 @@ void stellar_layoutTransactionDialog(const char *line1, const char *line2, const str_warning, false ); -} - -void stellar_layoutGetPublicKey(uint32_t *address_n, size_t address_n_count) -{ - // Derive node and calculate address - uint8_t pubkey_bytes[32]; - stellar_getPubkeyAtAddress(address_n, address_n_count, pubkey_bytes, sizeof(pubkey_bytes)); - const char **str_addr_rows = stellar_lineBreakAddress(pubkey_bytes); - - layoutDialogSwipe(&bmp_icon_question, _("Cancel"), _("Confirm"), _("Share public account ID?"), - str_addr_rows[0], - str_addr_rows[1], - str_addr_rows[2], - NULL, - NULL, NULL - ); - if (!protectButton(ButtonRequestType_ButtonRequest_ProtectCall, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL); - layoutHome(); - return; - } } \ No newline at end of file diff --git a/firmware/stellar.h b/firmware/stellar.h index 57c1697b22..81b287a35f 100644 --- a/firmware/stellar.h +++ b/firmware/stellar.h @@ -58,7 +58,6 @@ void stellar_confirmManageDataOp(StellarManageDataOp *msg); void stellar_confirmBumpSequenceOp(StellarBumpSequenceOp *msg); // Layout -void stellar_layoutGetPublicKey(uint32_t *address_n, size_t address_n_count); void stellar_layoutTransactionDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5); void stellar_layoutTransactionSummary(StellarSignTx *msg); void stellar_layoutSigningDialog(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, uint32_t *address_n, size_t address_n_count, const char *warning, bool is_final_step); @@ -68,7 +67,6 @@ HDNode *stellar_deriveNode(uint32_t *address_n, size_t address_n_count); size_t stellar_publicAddressAsStr(uint8_t *bytes, char *out, size_t outlen); const char **stellar_lineBreakAddress(uint8_t *addrbytes); -void stellar_getPubkeyAtAddress(uint32_t *address_n, size_t address_n_count, uint8_t *out, size_t outlen); void stellar_hashupdate_uint32(uint32_t value); void stellar_hashupdate_uint64(uint64_t value); diff --git a/vendor/trezor-common b/vendor/trezor-common index 018eebac7e..0bf60dbda9 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit 018eebac7e64ed082486d746d78d279fe815c65d +Subproject commit 0bf60dbda9bd85db01ed36e5d9045a223744a35c