From 711c4fcd28997b2041cd5abb38a57a531dc07de2 Mon Sep 17 00:00:00 2001 From: Jorge Izquierdo Date: Thu, 15 Dec 2016 23:51:44 +0100 Subject: [PATCH] internal/ethapi: Fix signHash bug when message is not hex --- internal/ethapi/api.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index fd86b6465f..698a19a77e 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -292,9 +292,12 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs // safely used to calculate a signature from. The hash is calulcated with: // keccak256("\x19Ethereum Signed Message:\n"${message length}${message}). func signHash(message string) []byte { - data := common.FromHex(message) // Give context to the signed message. This prevents an adversery to sign a tx. // It has no cryptographic purpose. + data := common.FromHex(message) + if len(data) == 0 { + data = []byte(message) + } msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data) // Always hash, this prevents choosen plaintext attacks that can extract key information return crypto.Keccak256([]byte(msg))