提交 c236f8cb 作者: Brian Tiger Chow

refactor(identify) extract hello

上级 7bf9ff61
......@@ -31,22 +31,20 @@ var SupportedHashes = "SHA256,SHA512,SHA1"
// ErrUnsupportedKeyType is returned when a private key cast/type switch fails.
var ErrUnsupportedKeyType = errors.New("unsupported key type")
// Performs initial communication with this peer to share node ID's and
// initiate communication. (secureIn, secureOut, error)
func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-chan []byte, chan<- []byte, error) {
func genRandHello(self *peer.Peer) (*Hello, error) {
hello := new(Hello)
// Generate and send Hello packet.
// Hello = (rand, PublicKey, Supported)
nonce := make([]byte, 16)
_, err := rand.Read(nonce)
if err != nil {
return nil, nil, err
return nil, err
}
hello := new(Hello)
myPubKey, err := self.PubKey.Bytes()
if err != nil {
return nil, nil, err
return nil, err
}
hello.Rand = nonce
......@@ -54,8 +52,18 @@ func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-
hello.Exchanges = &SupportedExchanges
hello.Ciphers = &SupportedCiphers
hello.Hashes = &SupportedHashes
return hello, nil
}
encoded, err := proto.Marshal(hello)
// Performs initial communication with this peer to share node ID's and
// initiate communication. (secureIn, secureOut, error)
func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-chan []byte, chan<- []byte, error) {
h, err := genRandHello(self)
if err != nil {
return nil, nil, err
}
encoded, err := proto.Marshal(h)
if err != nil {
return nil, nil, err
}
......@@ -160,6 +168,11 @@ func Handshake(self, remote *peer.Peer, in <-chan []byte, out chan<- []byte) (<-
return nil, nil, err
}
myPubKey, err := self.PubKey.Bytes()
if err != nil {
return nil, nil, err
}
cmp := bytes.Compare(myPubKey, helloResp.GetPubkey())
mIV, tIV, mCKey, tCKey, mMKey, tMKey := ci.KeyStretcher(cmp, cipherType, hashType, secret)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论