diff --git a/p2p/client_identity.go b/p2p/client_identity.go index fca2756bd6..db8cf9dec9 100644 --- a/p2p/client_identity.go +++ b/p2p/client_identity.go @@ -7,9 +7,9 @@ import ( // ClientIdentity represents the identity of a peer. type ClientIdentity interface { - String() string // human readable identity - Pubkey() []byte // 512-bit public key - PrivKey() []byte // 512-bit private 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 { @@ -53,11 +53,11 @@ func (c *SimpleClientIdentity) String() string { c.implementation) } -func (c *SimpleClientIdentity) Privkey() []byte { +func (c *SimpleClientIdentity) PrivateKey() []byte { return c.privkey } -func (c *SimpleClientIdentity) Pubkey() []byte { +func (c *SimpleClientIdentity) PublicKey() []byte { return c.pubkey } diff --git a/p2p/client_identity_test.go b/p2p/client_identity_test.go index 61c34fbf11..9c15b8895c 100644 --- a/p2p/client_identity_test.go +++ b/p2p/client_identity_test.go @@ -9,11 +9,11 @@ import ( func TestClientIdentity(t *testing.T) { clientIdentity := NewSimpleClientIdentity("Ethereum(G)", "0.5.16", "test", []byte("privkey"), []byte("pubkey")) - key := clientIdentity.Privkey() + key := clientIdentity.PrivateKey() if !bytes.Equal(key, []byte("privkey")) { t.Errorf("Expected Privkey to be %x, got %x", key, []byte("privkey")) } - key = clientIdentity.Pubkey() + key = clientIdentity.PublicKey() if !bytes.Equal(key, []byte("pubkey")) { t.Errorf("Expected Pubkey to be %x, got %x", key, []byte("pubkey")) } diff --git a/p2p/crypto.go b/p2p/crypto.go index 622e2608c7..242bad7977 100644 --- a/p2p/crypto.go +++ b/p2p/crypto.go @@ -8,9 +8,9 @@ import ( "net" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/crypto/secp256k1" ethlogger "github.com/ethereum/go-ethereum/logger" "github.com/obscuren/ecies" - "github.com/obscuren/secp256k1-go" ) var clogger = ethlogger.NewLogger("CRYPTOID") @@ -49,7 +49,7 @@ newCryptoId(id ClientIdentity) initialises a crypto layer manager. This object h */ func newCryptoId(id ClientIdentity) (self *cryptoId, err error) { // will be at server init - var prvKeyS []byte = id.PrivKey() + var prvKeyS []byte = id.PrivateKey() if prvKeyS == nil { err = fmt.Errorf("no private key for client") return @@ -68,7 +68,7 @@ func newCryptoId(id ClientIdentity) (self *cryptoId, err error) { // to be created at server init shared between peers and sessions // for reuse, call wth ReadAt, no reset seek needed } - self.pubKeyS = id.Pubkey()[1:] + self.pubKeyS = id.PublicKey()[1:] clogger.Debugf("initialise crypto for NodeId %v", hexkey(self.pubKeyS)) clogger.Debugf("private-key %v\npublic key %v", hexkey(prvKeyS), hexkey(self.pubKeyS)) return diff --git a/p2p/peer.go b/p2p/peer.go index bc2f38c2cc..119e98e128 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -110,7 +110,7 @@ func newServerPeer(server *Server, conn net.Conn, dialAddr *peerAddr) *Peer { // laddr can be updated concurrently by NAT traversal. // newServerPeer must be called with the server lock held. if server.laddr != nil { - p.ourListenAddr = newPeerAddr(server.laddr, server.Identity.Pubkey()) + p.ourListenAddr = newPeerAddr(server.laddr, server.Identity.PublicKey()) } return p } @@ -139,12 +139,12 @@ func (p *Peer) Identity() ClientIdentity { return p.identity } -func (self *Peer) Pubkey() (pubkey []byte) { +func (self *Peer) PublicKey() (pubkey []byte) { self.infolock.Lock() defer self.infolock.Unlock() switch { case self.identity != nil: - pubkey = self.identity.Pubkey()[1:] + pubkey = self.identity.PublicKey()[1:] case self.dialAddr != nil: pubkey = self.dialAddr.Pubkey case self.listenAddr != nil: @@ -323,7 +323,7 @@ func (p *Peer) handleCryptoHandshake() (crw func(net.Conn) MsgChanReadWriter, er // run on peer // this bit handles the handshake and creates a secure communications channel with // var rw *secretRW - if sessionToken, crw, err = crypto.NewSession(p.conn, p.Pubkey(), sessionToken, initiator); err != nil { + if sessionToken, crw, err = crypto.NewSession(p.conn, p.PublicKey(), sessionToken, initiator); err != nil { p.Debugf("unable to setup secure session: %v", err) return } diff --git a/p2p/protocol.go b/p2p/protocol.go index 62ada929d7..3aa39ce9c8 100644 --- a/p2p/protocol.go +++ b/p2p/protocol.go @@ -60,11 +60,11 @@ type handshake struct { func (h *handshake) String() string { return h.ID } -func (h *handshake) Pubkey() []byte { +func (h *handshake) PublicKey() []byte { return h.NodeID } -func (h *handshake) PrivKey() []byte { +func (h *handshake) PrivateKey() []byte { return nil } @@ -265,7 +265,7 @@ func (bp *baseProtocol) handshakeMsg() Msg { bp.peer.ourID.String(), caps, port, - bp.peer.ourID.Pubkey()[1:], + bp.peer.ourID.PublicKey()[1:], ) } diff --git a/p2p/protocol_test.go b/p2p/protocol_test.go index 6804a9d40b..1cd72626d6 100644 --- a/p2p/protocol_test.go +++ b/p2p/protocol_test.go @@ -11,14 +11,14 @@ import ( ) type peerId struct { - privKey, pubkey []byte + privkey, pubkey []byte } func (self *peerId) String() string { - return fmt.Sprintf("test peer %x", self.Pubkey()[:4]) + return fmt.Sprintf("test peer %x", self.PublicKey()[:4]) } -func (self *peerId) Pubkey() (pubkey []byte) { +func (self *peerId) PublicKey() (pubkey []byte) { pubkey = self.pubkey if len(pubkey) == 0 { pubkey = crypto.GenerateNewKeyPair().PublicKey @@ -27,11 +27,11 @@ func (self *peerId) Pubkey() (pubkey []byte) { return } -func (self *peerId) PrivKey() (privKey []byte) { - privKey = self.privKey - if len(privKey) == 0 { - privKey = crypto.GenerateNewKeyPair().PublicKey - self.privKey = privKey +func (self *peerId) PrivateKey() (privkey []byte) { + privkey = self.privkey + if len(privkey) == 0 { + privkey = crypto.GenerateNewKeyPair().PublicKey + self.privkey = privkey } return } diff --git a/p2p/server.go b/p2p/server.go index 4fd1f7d034..9a05a7619d 100644 --- a/p2p/server.go +++ b/p2p/server.go @@ -399,7 +399,7 @@ func (srv *Server) verifyPeer(addr *peerAddr) error { if srv.Blacklist.Exists(addr.Pubkey) { return errors.New("blacklisted") } - if bytes.Equal(srv.Identity.Pubkey()[1:], addr.Pubkey) { + if bytes.Equal(srv.Identity.PublicKey()[1:], addr.Pubkey) { return newPeerError(errPubkeyForbidden, "not allowed to connect to srv") } srv.lock.RLock() @@ -407,7 +407,7 @@ func (srv *Server) verifyPeer(addr *peerAddr) error { for _, peer := range srv.peers { if peer != nil { id := peer.Identity() - if id != nil && bytes.Equal(id.Pubkey(), addr.Pubkey) { + if id != nil && bytes.Equal(id.PublicKey(), addr.Pubkey) { return errors.New("already connected") } }