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

RLPx p2p crypto layer (work in progress, do not merge) #262

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e82d0aa
initial hook for crypto handshake (void, off by default)
zelig Jan 18, 2015
a325b45
add privkey to clientIdentity + tests
zelig Jan 18, 2015
ac4e71f
fix protocol to accomodate privkey
zelig Jan 18, 2015
b8f0620
add crypto auth logic to p2p
zelig Jan 18, 2015
e2e0849
rewrite to comply with latest spec
zelig Jan 18, 2015
248ab71
fix crash
zelig Jan 19, 2015
605ee4d
handshake test to crypto
zelig Jan 19, 2015
a314bbf
handshake test to crypto
zelig Jan 19, 2015
b5734f3
completed the test. FAIL now. it crashes at diffie-hellman. ECIES -> …
zelig Jan 19, 2015
6ed5a1f
Merge remote-tracking branch 'upstream/develop' into p2p.crypto
zelig Jan 19, 2015
44779d8
integrate cryptoId into peer and connection lifecycle
zelig Jan 19, 2015
a8b3c03
first stab at integrating crypto in our p2p
zelig Jan 19, 2015
6bb203d
add minor comments to the test
zelig Jan 20, 2015
20ac187
add equality check for nonce and remote nonce
zelig Jan 20, 2015
2d4f598
important fix for peer pubkey. when taken from identity, chop first f…
zelig Jan 20, 2015
0433cae
changes that fix it all:
zelig Jan 20, 2015
8f938c7
add code documentation
zelig Jan 21, 2015
012d9e1
add initial peer level test (failing)
zelig Jan 21, 2015
1dda555
chop first byte when cryptoid.PubKeyS is set from identity.Pubkey() s…
zelig Jan 21, 2015
92bd253
peer-level integration test for crypto handshake
zelig Jan 21, 2015
c5001a4
add temporary forced session token generation
zelig Jan 21, 2015
1853903
reorg and comment to prepare for refactor of read/write
zelig Jan 21, 2015
7a33109
write via proto.out channel
zelig Jan 21, 2015
b29b7fe
remove peer.writeMsg
zelig Jan 21, 2015
4bfe53e
Messenger and SecureMessenger implement MsgChanReadWriter
zelig Jan 22, 2015
9918dad
Merge remote-tracking branch 'upstream/develop' into p2p.crypto
zelig Jan 22, 2015
ba8318d
private and public key method names consistent
zelig Jan 22, 2015
cd235b2
Refactor message read/write
zelig Jan 23, 2015
a4b4f68
add encryption/authentication with test
zelig Jan 23, 2015
2f00e5c
add correct authentication with HMAC
zelig Jan 23, 2015
7f12ac7
add -crypto option to switch encryption on by a flag
zelig Jan 23, 2015
876fd8b
return from peer loop if crypto fails, oops
zelig Jan 23, 2015
2e76f1b
Merge remote-tracking branch 'upstream/develop' into p2p.crypto
zelig Jan 23, 2015
94af107
a few minor changes from review
zelig Jan 26, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/ethereum/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var (
SHH bool
Dial bool
PrintVersion bool
Encryption bool
)

// flags specific to cli client
Expand Down Expand Up @@ -115,6 +116,7 @@ func Init() {
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
flag.StringVar(&ImportChain, "chain", "", "Imports given chain")

flag.BoolVar(&Encryption, "crypto", false, "whether to use encryption (experimental, temporary)")
flag.BoolVar(&Dump, "dump", false, "output the ethereum state in JSON format. Sub args [number, hash]")
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")
Expand Down
1 change: 1 addition & 0 deletions cmd/ethereum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func main() {
KeyRing: KeyRing,
Shh: SHH,
Dial: Dial,
Encryption: Encryption,
})

if err != nil {
Expand Down
20 changes: 11 additions & 9 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type Config struct {
NATType string
PMPGateway string

Shh bool
Dial bool
Shh bool
Dial bool
Encryption bool

KeyManager *crypto.KeyManager
}
Expand Down Expand Up @@ -107,7 +108,7 @@ func New(config *Config) (*Ethereum, error) {
keyManager.Init(config.KeyRing, 0, false)

// Create a new client id for this instance. This will help identifying the node on the network
clientId := p2p.NewSimpleClientIdentity(config.Name, config.Version, config.Identifier, keyManager.PublicKey())
clientId := p2p.NewSimpleClientIdentity(config.Name, config.Version, config.Identifier, keyManager.PrivateKey(), keyManager.PublicKey())

saveProtocolVersion(db)
//ethutil.Config.Db = db
Expand Down Expand Up @@ -143,12 +144,13 @@ func New(config *Config) (*Ethereum, error) {
fmt.Println(nat)

eth.net = &p2p.Server{
Identity: clientId,
MaxPeers: config.MaxPeers,
Protocols: protocols,
Blacklist: eth.blacklist,
NAT: p2p.UPNP(),
NoDial: !config.Dial,
Identity: clientId,
MaxPeers: config.MaxPeers,
Protocols: protocols,
Blacklist: eth.blacklist,
NAT: p2p.UPNP(),
NoDial: !config.Dial,
Encryption: config.Encryption,
}

if len(config.Port) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPoo
blockPool: blockPool,
rw: rw,
peer: peer,
id: fmt.Sprintf("%x", peer.Identity().Pubkey()[:8]),
id: fmt.Sprintf("%x", peer.PublicKey()[:8]),
}
err = self.handleStatus()
if err == nil {
Expand Down
17 changes: 12 additions & 5 deletions p2p/client_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (

// ClientIdentity represents the identity of a peer.
type ClientIdentity interface {
String() string // human readable identity
Pubkey() []byte // 512-bit public key
String() string // human readable identity
PublicKey() []byte // 512-bit public key represented in 65 byte format as per golang/elliptic.Marshal, first byte encodes curve
PrivateKey() []byte // 256-bit private key
}

type SimpleClientIdentity struct {
Expand All @@ -17,17 +18,19 @@ type SimpleClientIdentity struct {
customIdentifier string
os string
implementation string
privkey []byte
pubkey []byte
}

func NewSimpleClientIdentity(clientIdentifier string, version string, customIdentifier string, pubkey []byte) *SimpleClientIdentity {
func NewSimpleClientIdentity(clientIdentifier string, version string, customIdentifier string, privkey []byte, pubkey []byte) *SimpleClientIdentity {
clientIdentity := &SimpleClientIdentity{
clientIdentifier: clientIdentifier,
version: version,
customIdentifier: customIdentifier,
os: runtime.GOOS,
implementation: runtime.Version(),
pubkey: pubkey,
privkey: privkey,
}

return clientIdentity
Expand All @@ -50,8 +53,12 @@ func (c *SimpleClientIdentity) String() string {
c.implementation)
}

func (c *SimpleClientIdentity) Pubkey() []byte {
return []byte(c.pubkey)
func (c *SimpleClientIdentity) PrivateKey() []byte {
return c.privkey
}

func (c *SimpleClientIdentity) PublicKey() []byte {
return c.pubkey
}

func (c *SimpleClientIdentity) SetCustomIdentifier(customIdentifier string) {
Expand Down
11 changes: 10 additions & 1 deletion p2p/client_identity_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package p2p

import (
"bytes"
"fmt"
"runtime"
"testing"
)

func TestClientIdentity(t *testing.T) {
clientIdentity := NewSimpleClientIdentity("Ethereum(G)", "0.5.16", "test", []byte("pubkey"))
clientIdentity := NewSimpleClientIdentity("Ethereum(G)", "0.5.16", "test", []byte("privkey"), []byte("pubkey"))
key := clientIdentity.PrivateKey()
if !bytes.Equal(key, []byte("privkey")) {
t.Errorf("Expected Privkey to be %x, got %x", key, []byte("privkey"))
}
key = clientIdentity.PublicKey()
if !bytes.Equal(key, []byte("pubkey")) {
t.Errorf("Expected Pubkey to be %x, got %x", key, []byte("pubkey"))
}
clientString := clientIdentity.String()
expected := fmt.Sprintf("Ethereum(G)/v0.5.16/test/%s/%s", runtime.GOOS, runtime.Version())
if clientString != expected {
Expand Down
Loading