From a9449520b8f6c0dc17157f71580f92f8b9f8a5ab Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 24 May 2016 22:22:30 +0100 Subject: [PATCH] Ethereum signing skeleton --- firmware/Makefile | 1 + firmware/ethereum.c | 61 +++++++++++++++++++++++++++++++++++++++++++++ firmware/ethereum.h | 32 ++++++++++++++++++++++++ firmware/fsm.c | 21 +++++++++++++--- 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 firmware/ethereum.c create mode 100644 firmware/ethereum.h diff --git a/firmware/Makefile b/firmware/Makefile index dbb7a4658..845d3c02c 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -17,6 +17,7 @@ OBJS += recovery.o OBJS += reset.o OBJS += signing.o OBJS += crypto.o +OBJS += ethereum.o OBJS += debug.o diff --git a/firmware/ethereum.c b/firmware/ethereum.c new file mode 100644 index 000000000..f9653bbb7 --- /dev/null +++ b/firmware/ethereum.c @@ -0,0 +1,61 @@ +/* + * This file is part of the TREZOR project. + * + * Copyright (C) 2016 Alex Beregszaszi + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#include "ethereum.h" +#include "fsm.h" +#include "layout2.h" +#include "messages.h" +#include "transaction.h" +#include "ecdsa.h" +#include "protect.h" +#include "crypto.h" +#include "secp256k1.h" +#include "sha3.h" + +static bool signing = false; + +void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node) +{ + (void)node; + + signing = true; + + fsm_sendFailure(FailureType_Failure_Other, "Unsupported feature"); +} + +void ethereum_signing_txack(EthereumTxAck *tx) +{ + (void)tx; + + if (!signing) { + fsm_sendFailure(FailureType_Failure_UnexpectedMessage, "Not in Signing mode"); + layoutHome(); + return; + } + + fsm_sendFailure(FailureType_Failure_Other, "Unsupported feature"); +} + +void ethereum_signing_abort(void) +{ + if (signing) { + layoutHome(); + signing = false; + } +} diff --git a/firmware/ethereum.h b/firmware/ethereum.h new file mode 100644 index 000000000..8c55d2db5 --- /dev/null +++ b/firmware/ethereum.h @@ -0,0 +1,32 @@ +/* + * This file is part of the TREZOR project. + * + * Copyright (C) 2016 Alex Beregszaszi + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . + */ + +#ifndef __ETHEREUM_H__ +#define __ETHEREUM_H__ + +#include +#include +#include "bip32.h" +#include "messages.pb.h" + +void ethereum_signing_init(EthereumSignTx *msg, const HDNode *node); +void ethereum_signing_abort(void); +void ethereum_signing_txack(EthereumTxAck *msg); + +#endif diff --git a/firmware/fsm.c b/firmware/fsm.c index 3ab230437..b2e3ef7dc 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -47,6 +47,7 @@ #include "curves.h" #include "secp256k1.h" #include +#include "ethereum.h" // message methods @@ -433,19 +434,31 @@ void fsm_msgCancel(Cancel *msg) (void)msg; recovery_abort(); signing_abort(); + ethereum_signing_abort(); fsm_sendFailure(FailureType_Failure_ActionCancelled, "Aborted"); } void fsm_msgEthereumSignTx(EthereumSignTx *msg) { - (void)msg; - fsm_sendFailure(FailureType_Failure_Other, "Unsupported feature"); + if (!storage_isInitialized()) { + fsm_sendFailure(FailureType_Failure_NotInitialized, "Device not initialized"); + return; + } + + if (!protectPin(true)) { + layoutHome(); + return; + } + + const HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count); + if (!node) return; + + ethereum_signing_init(msg, node); } void fsm_msgEthereumTxAck(EthereumTxAck *msg) { - (void)msg; - fsm_sendFailure(FailureType_Failure_Other, "Unsupported feature"); + ethereum_signing_txack(msg); } void fsm_msgCipherKeyValue(CipherKeyValue *msg)