From d625ddacfde3aa5240fcfb5f8c32cd408b9e590f Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Tue, 26 Sep 2017 18:08:24 +0200 Subject: [PATCH] Validate password in CompleteTransaction with remote node (#367) --- geth/api/backend_test.go | 7 +++++++ geth/node/txqueue_manager.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/geth/api/backend_test.go b/geth/api/backend_test.go index 7cce209e3..91bd1410f 100644 --- a/geth/api/backend_test.go +++ b/geth/api/backend_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/ethereum/go-ethereum/accounts/keystore" gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/les" whisper "github.com/ethereum/go-ethereum/whisper/whisperv5" @@ -345,6 +346,12 @@ func (s *BackendTestSuite) TestCallRPCSendTransactionUpstream() { if signal.Type == node.EventTransactionQueued { event := signal.Event.(map[string]interface{}) txID := event["id"].(string) + + // Complete with a wrong passphrase. + txHash, err = s.backend.CompleteTransaction(common.QueuedTxID(txID), "some-invalid-passphrase") + s.EqualError(err, keystore.ErrDecrypt.Error(), "should return an error as the passphrase was invalid") + + // Complete with a correct passphrase. txHash, err = s.backend.CompleteTransaction(common.QueuedTxID(txID), TestConfig.Account2.Password) s.NoError(err, "cannot complete queued transaction %s", txID) diff --git a/geth/node/txqueue_manager.go b/geth/node/txqueue_manager.go index 7184796a8..60c165801 100644 --- a/geth/node/txqueue_manager.go +++ b/geth/node/txqueue_manager.go @@ -216,6 +216,14 @@ func (m *TxQueueManager) completeRemoteTransaction(queuedTx *common.QueuedTx, pa return emptyHash, err } + if _, err := m.accountManager.VerifyAccountPassword( + config.KeyStoreDir, + selectedAcct.Address.String(), + password, + ); err != nil { + return emptyHash, err + } + // We need to request a new transaction nounce from upstream node. ctx, cancel := context.WithTimeout(context.Background(), time.Minute) defer cancel()