mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-03 12:00:59 +00:00
fsm: Add NEMDecryptMessage
This commit is contained in:
parent
810443f197
commit
f17a0a85e0
@ -1431,6 +1431,72 @@ void fsm_msgNEMSignTx(NEMSignTx *msg) {
|
|||||||
layoutHome();
|
layoutHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fsm_msgNEMDecryptMessage(NEMDecryptMessage *msg)
|
||||||
|
{
|
||||||
|
RESP_INIT(NEMDecryptedMessage);
|
||||||
|
|
||||||
|
CHECK_INITIALIZED
|
||||||
|
|
||||||
|
CHECK_PARAM(nem_network_name(msg->network), _("Invalid NEM network"));
|
||||||
|
CHECK_PARAM(msg->has_payload, _("No payload provided"));
|
||||||
|
CHECK_PARAM(msg->payload.size >= NEM_ENCRYPTED_PAYLOAD_SIZE(0), _("Invalid encrypted payload"));
|
||||||
|
CHECK_PARAM(msg->has_public_key, _("No public key provided"));
|
||||||
|
CHECK_PARAM(msg->public_key.size == 32, _("Invalid public key"));
|
||||||
|
|
||||||
|
char address[NEM_ADDRESS_SIZE + 1];
|
||||||
|
nem_get_address(msg->public_key.bytes, msg->network, address);
|
||||||
|
|
||||||
|
layoutNEMDialog(&bmp_icon_question,
|
||||||
|
_("Cancel"),
|
||||||
|
_("Confirm"),
|
||||||
|
_("Decrypt message"),
|
||||||
|
_("Confirm address?"),
|
||||||
|
address);
|
||||||
|
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||||
|
layoutHome();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK_PIN
|
||||||
|
|
||||||
|
HDNode *node = fsm_getDerivedNode(ED25519_KECCAK_NAME, msg->address_n, msg->address_n_count);
|
||||||
|
if (!node) return;
|
||||||
|
|
||||||
|
const uint8_t *salt = msg->payload.bytes;
|
||||||
|
uint8_t *iv = &msg->payload.bytes[NEM_SALT_SIZE];
|
||||||
|
|
||||||
|
const uint8_t *payload = &msg->payload.bytes[NEM_SALT_SIZE + AES_BLOCK_SIZE];
|
||||||
|
size_t size = msg->payload.size - NEM_SALT_SIZE - AES_BLOCK_SIZE;
|
||||||
|
|
||||||
|
// hdnode_nem_decrypt mutates the IV, so this will modify msg
|
||||||
|
bool ret = hdnode_nem_decrypt(node,
|
||||||
|
msg->public_key.bytes,
|
||||||
|
iv,
|
||||||
|
salt,
|
||||||
|
payload,
|
||||||
|
size,
|
||||||
|
resp->payload.bytes);
|
||||||
|
if (!ret) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_ProcessError, _("Failed to decrypt payload"));
|
||||||
|
layoutHome();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resp->has_payload = true;
|
||||||
|
resp->payload.size = NEM_DECRYPTED_SIZE(resp->payload.bytes, size);
|
||||||
|
|
||||||
|
layoutNEMTransferPayload(resp->payload.bytes, resp->payload.size, true);
|
||||||
|
if (!protectButton(ButtonRequestType_ButtonRequest_Other, false)) {
|
||||||
|
fsm_sendFailure(FailureType_Failure_ActionCancelled, NULL);
|
||||||
|
layoutHome();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg_write(MessageType_MessageType_NEMDecryptedMessage, resp);
|
||||||
|
layoutHome();
|
||||||
|
}
|
||||||
|
|
||||||
void fsm_msgCosiCommit(CosiCommit *msg)
|
void fsm_msgCosiCommit(CosiCommit *msg)
|
||||||
{
|
{
|
||||||
RESP_INIT(CosiCommitment);
|
RESP_INIT(CosiCommitment);
|
||||||
|
@ -68,6 +68,7 @@ void fsm_msgEthereumVerifyMessage(EthereumVerifyMessage *msg);
|
|||||||
|
|
||||||
void fsm_msgNEMGetAddress(NEMGetAddress *msg);
|
void fsm_msgNEMGetAddress(NEMGetAddress *msg);
|
||||||
void fsm_msgNEMSignTx(NEMSignTx *msg);
|
void fsm_msgNEMSignTx(NEMSignTx *msg);
|
||||||
|
void fsm_msgNEMDecryptMessage(NEMDecryptMessage *msg);
|
||||||
|
|
||||||
void fsm_msgCosiCommit(CosiCommit *msg);
|
void fsm_msgCosiCommit(CosiCommit *msg);
|
||||||
void fsm_msgCosiSign(CosiSign *msg);
|
void fsm_msgCosiSign(CosiSign *msg);
|
||||||
|
@ -150,6 +150,12 @@ NEMAddress.address max_size:41
|
|||||||
NEMSignedTx.data max_size:2048
|
NEMSignedTx.data max_size:2048
|
||||||
NEMSignedTx.signature max_size:64
|
NEMSignedTx.signature max_size:64
|
||||||
|
|
||||||
|
NEMDecryptMessage.address_n max_count:8
|
||||||
|
NEMDecryptMessage.public_key max_size:32
|
||||||
|
NEMDecryptMessage.payload max_size:320
|
||||||
|
|
||||||
|
NEMDecryptedMessage.payload max_size:256
|
||||||
|
|
||||||
CosiCommit.address_n max_count:8
|
CosiCommit.address_n max_count:8
|
||||||
CosiCommit.data max_size:32
|
CosiCommit.data max_size:32
|
||||||
|
|
||||||
|
2
vendor/trezor-crypto
vendored
2
vendor/trezor-crypto
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 764cc4c6e8ef32e7e1a77f0496ae090f11a36def
|
Subproject commit 74e74f5eed886ff871dc1fb36088e4b465917689
|
Loading…
Reference in New Issue
Block a user