Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clef: make external signing work + follow up fixes #19003

Merged
merged 10 commits into from
Feb 12, 2019

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Feb 6, 2019

This is a follow-up PR to fix issues after the merging of external-signer, bidirectional communication and implementation of eip 712/192.

It contains

  • Make use of notifications,
  • Tests
  • Implement sign text via external signer
  • Implement sign text to use hex-encoded data
  • implement signing of clique headers,
  • tests for clique signing
  • improvements to the standard CLI user interface, e..g better quoting (%q)
  • rename --networkid into --chainid

One thing still remaining is to display remote and local address for ipc communication, but that can be left for a later PR.

@holiman holiman requested a review from karalabe as a code owner February 6, 2019 07:50
@holiman
Copy link
Contributor Author

holiman commented Feb 6, 2019

Output on clef-side when running the script

--------- Transaction request-------------
to:    0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192
from:     0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 [chksum ok]
value:    1 wei
gas:      0x1 (1)
gasprice: 1 wei
nonce:    0x1 (1)

Request context:
	127.0.0.1:59870 -> HTTP/1.1 -> localhost:8550

Additional HTTP header data, provided by the external caller:
	User-Agent: Go-http-client/1.1
	Origin: 
-------------------------------------------
Approve? [y/N]:
> y
Enter password to approve:
> 
-----------------------
Transaction signed:
 {
    "nonce": "0x1",
    "gasPrice": "0x1",
    "gas": "0x1",
    "to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192",
    "value": "0x1",
    "input": "0x",
    "v": "0x25",
    "r": "0x14db715bd0732d20326ab05a8fae876361bddf8a26e686b61bd47281ffbf4dfc",
    "s": "0x3418905cd13d55e9791f070285eae47e7c935467381d9723131629346f7d5b0a",
    "hash": "0xf4d2a2cffe610463d79604f7d84ffd49af30c77d4cc8984aa8c5836863aae09d"
  }
DEBUG[02-06|14:41:43.152] Served account_signTransaction           conn=127.0.0.1:59870 reqid=5 t=9.908189608s
-------- Sign data request--------------
Account:  0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 [chksum ok]
message:
  message [text/plain]: "\x19Ethereum Signed Message:\n11hello world"

raw data:  
"\x19Ethereum Signed Message:\n11hello world"
message hash:  0xd9eba16ed0ecae432b71fe008c98cc872bb4cc214d3220a36f365326cf807d68
-------------------------------------------
Request context:
	127.0.0.1:59870 -> HTTP/1.1 -> localhost:8550

Additional HTTP header data, provided by the external caller:
	User-Agent: Go-http-client/1.1
	Origin: 
Approve? [y/N]:
> y
Enter password to approve:
> 
-----------------------
DEBUG[02-06|14:41:48.550] Served account_signData                  conn=127.0.0.1:59870 reqid=6 t=5.39591164s
-------- Sign data request--------------
Account:  0x8A8eAFb1cf62BfBeb1741769DAE1a9dd47996192 [chksum ok]
message:
  Clique header [clique]: "clique header 0 [0xbbb0740043d19c1f4af66719b75c8774c0defcf31dd45603e565c0ef1969762f]"

raw data:  
"\xf9\x02\x14\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0\x1d\xccM\xe8\xde\xc7]z\xab\x85\xb5g\xb6\xcc\xd4\x1a\xd3\x12E\x1b\x94\x8at\x13\xf0\xa1B\xfd@ԓG\x94\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0\xd7\xf8\x97O\xb5\xacx٬\t\x9b\x9a\xd5\x01\x8b\xed\xc2\xce\nr\xdaтz\x17\t\xda0X\x0f\x05D\xa0V\xe8\x1f\x17\x1b\xccU\xa6\xff\x83E\xe6\x92\xc0\xf8n[H\xe0\x1b\x99l\xad\xc0\x01b/\xb5\xe3c\xb4!\xa0V\xe8\x1f\x17\x1b\xccU\xa6\xff\x83E\xe6\x92\xc0\xf8n[H\xe0\x1b\x99l\xad\xc0\x01b/\xb5\xe3c\xb4!\xb9\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x85\x04\x00\x00\x00\x00\x80\x82\x13\x88\x80\x80\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x88\x00\x00\x00\x00\x00\x00\x00B"
message hash:  0x3a67764a660b30cafc80bacc32ffaec452ac9552d46543e4a0be364423d4f793
-------------------------------------------
Request context:
	127.0.0.1:59870 -> HTTP/1.1 -> localhost:8550

Additional HTTP header data, provided by the external caller:
	User-Agent: Go-http-client/1.1
	Origin: 
Approve? [y/N]:
> y
Enter password to approve:
> 

@holiman holiman changed the title Clef WIP clef: make external signing work + follow up fixes Feb 6, 2019
Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple nitpicks

@@ -1,8 +1,15 @@
### Changelog for internal API (ui-api)

### 3.2.0

* Make `ShowError`, `OnApprovedTx`, `OnSignerStartup` be json-rpc [notification](https://www.jsonrpc.org/specification#notification):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make ShowError, OnApprovedTx, AND OnSignerStartup (remove be) json-rpc [notificationS]

@@ -1481,6 +1482,42 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (stri
return fmt.Sprintf("%x", encoded), nil
}

// TestSignCliqueBlock fetches the given block number, and attempts to sign it as a clique header with the
// given address, returning the address of the recovered signature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: Peter said that this should be noted as TODO/to remove

func (api *SignerAPI) determineSignatureFormat(ctx context.Context, contentType string, addr common.MixedcaseAddress, data interface{}) (*SignDataRequest, bool, error) {
var (
req *SignDataRequest
useLegacyV = true // Default to use V = 27 or 28, the legacy Ethereum format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our conversation, let's use useEthereumV or useCliqueV as a name instead.

var tests = [
testTx,
testSignText,
testClique,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we also have tests to check the error conditions?

Copy link
Contributor Author

@holiman holiman Feb 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any particular error conditions you're thinking of?
I mean, there are quite a lot of ways for signing to fail. This js-test is meant as an integration test, to test the whole geth-external-ui and back again flow.

It's not for CI, but for a dev to run manually to test things more easily.

Individual tests within signer/clef should test things like rejection and tx validation etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking of the 27/28 vs 0/1 in particular.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added for transactions. For clique, the new debug endpoint will deliver the derived signer. And if the wrong v-type is used, it will derive another address as sealer of that block.

So the js-test already checks that the requested signer-address equals what the endpoint returns, thus checks that the geth and clef are in agreement (without explicitly checking v)

Copy link
Member

@gballet gballet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman merged commit 75d292b into ethereum:master Feb 12, 2019
kiku-jw pushed a commit to kiku-jw/go-ethereum that referenced this pull request Mar 29, 2019
* signer/clef: make use of json-rpc notification

* signer: tidy up output of OnApprovedTx

* accounts/external, signer: implement remote signing of text, make accounts_sign take hexdata

* clef: added basic testscript

* signer, external, api: add clique signing test to debug rpc, fix clique signing in clef

* signer: fix clique interoperability between geth and clef

* clef: rename networkid switch to chainid

* clef: enable chainid flag

* clef, signer: minor changes from review

* clef: more tests for signer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants