mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
private and public key method names consistent
This commit is contained in:
parent
9918dad19b
commit
ba8318db6a
7 changed files with 27 additions and 27 deletions
|
|
@ -8,8 +8,8 @@ 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
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue