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

fix(p2p): handshake signature #210

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fixed ABI encoder for `SymbolCode` type.

* Fixed P2P HandshakeMessage signature generation

#### Deprecated

### [**0.10.2**](https://github.com/eoscanada/eos-go/releases/tag/v0.10.2) (January 19th, 2022)
Expand Down
19 changes: 13 additions & 6 deletions p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bufio"
"bytes"
"crypto/rand"
"crypto/sha256"
"encoding/binary"
"encoding/hex"
"fmt"
"io"
Expand Down Expand Up @@ -264,18 +266,23 @@ func (p *Peer) SendTime() error {
}

func (p *Peer) SendHandshake(info *HandshakeInfo) error {
publicKey, err := ecc.NewPublicKey("PUB_K1_1111111111111111111111111111111114T1Anm")
privateKey, err := ecc.NewRandomPrivateKey()
if err != nil {
return fmt.Errorf("sending handshake to %s: create public key: %w", p.Address, err)
return fmt.Errorf("sending handshake to %s: create private key: %w", p.Address, err)
}
publicKey := privateKey.PublicKey()

zlog.Debug("SendHandshake", zap.String("peer", p.Address), zap.Object("info", info))

tstamp := eos.Tstamp{Time: info.HeadBlockTime}

signature := ecc.Signature{
Curve: ecc.CurveK1,
Content: make([]byte, 65, 65),
timestampBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(timestampBytes, uint64(tstamp.Time.UnixNano()))

token := sha256.Sum256(timestampBytes)
signature, err := privateKey.Sign(token[:])
if err != nil {
return fmt.Errorf("sending handshake to %s: sign timestamp: %w", p.Address, err)
}

handshake := &eos.HandshakeMessage{
Expand All @@ -284,7 +291,7 @@ func (p *Peer) SendHandshake(info *HandshakeInfo) error {
NodeID: p.NodeID,
Key: publicKey,
Time: tstamp,
Token: make([]byte, 32, 32),
Token: token[:],
Signature: signature,
P2PAddress: p.Name,
LastIrreversibleBlockNum: info.LastIrreversibleBlockNum,
Expand Down
Loading