Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
1803c65e
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1803c65e
编写于
1月 19, 2015
作者:
Z
zelig
提交者:
Felix Lange
2月 06, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
integrate cryptoId into peer and connection lifecycle
上级
489d9562
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
3 deletion
+33
-3
p2p/crypto.go
p2p/crypto.go
+15
-0
p2p/peer.go
p2p/peer.go
+18
-3
未找到文件。
p2p/crypto.go
浏览文件 @
1803c65e
...
...
@@ -53,6 +53,21 @@ func newCryptoId(id ClientIdentity) (self *cryptoId, err error) {
return
}
func
(
self
*
cryptoId
)
Run
(
remotePubKeyDER
[]
byte
)
(
rw
*
secretRW
)
{
if
self
.
initiator
{
auth
,
initNonce
,
randomPrvKey
,
randomPubKey
,
err
:=
initiator
.
initAuth
(
remotePubKeyDER
,
sessionToken
)
respNonce
,
remoteRandomPubKey
,
_
,
_
:=
initiator
.
verifyAuthResp
(
response
)
}
else
{
// we are listening connection. we are responders in the haandshake.
// Extract info from the authentication. The initiator starts by sending us a handshake that we need to respond to.
response
,
remoteRespNonce
,
remoteInitNonce
,
remoteRandomPrivKey
,
_
:=
responder
.
verifyAuth
(
auth
,
sessionToken
,
pubInit
)
}
initSessionToken
,
initSecretRW
,
_
:=
initiator
.
newSession
(
initNonce
,
respNonce
,
auth
,
randomPrvKey
,
remoteRandomPubKey
)
respSessionToken
,
respSecretRW
,
_
:=
responder
.
newSession
(
remoteInitNonce
,
remoteRespNonce
,
auth
,
remoteRandomPrivKey
,
randomPubKey
)
}
/* startHandshake is called by peer if it initiated the connection.
By protocol spec, the party who initiates the connection (initiator) will send an 'auth' packet
New: authInitiator -> E(remote-pubk, S(ecdhe-random, ecdh-shared-secret^nonce) || H(ecdhe-random-pubk) || pubk || nonce || 0x0)
...
...
p2p/peer.go
浏览文件 @
1803c65e
...
...
@@ -222,10 +222,14 @@ func (p *Peer) loop() (reason DiscReason, err error) {
defer
close
(
p
.
closed
)
defer
p
.
conn
.
Close
()
var
readLoop
func
(
chan
Msg
,
chan
error
,
chan
bool
)
if
p
.
cryptoHandshake
{
if
err
:=
p
.
handleCryptoHandshake
();
err
!=
nil
{
if
readLoop
,
err
:=
p
.
handleCryptoHandshake
();
err
!=
nil
{
// from here on everything can be encrypted, authenticated
return
DiscProtocolError
,
err
// no graceful disconnect
}
}
else
{
readLoop
=
p
.
readLoop
}
// read loop
...
...
@@ -233,7 +237,7 @@ func (p *Peer) loop() (reason DiscReason, err error) {
readErr
:=
make
(
chan
error
)
readNext
:=
make
(
chan
bool
,
1
)
protoDone
:=
make
(
chan
struct
{},
1
)
go
p
.
readLoop
(
readMsg
,
readErr
,
readNext
)
go
readLoop
(
readMsg
,
readErr
,
readNext
)
readNext
<-
true
if
p
.
runBaseProtocol
{
...
...
@@ -329,8 +333,19 @@ func (p *Peer) dispatch(msg Msg, protoDone chan struct{}) (wait bool, err error)
}
func
(
p
*
Peer
)
handleCryptoHandshake
()
(
err
error
)
{
// cryptoId is just created for the lifecycle of the handshake
// it is survived by an encrypted readwriter
if
p
.
dialAddr
!=
0
{
// this should have its own method Outgoing() bool
initiator
=
true
}
// create crypto layer
cryptoId
:=
newCryptoId
(
p
.
identity
,
initiator
,
sessionToken
)
// run on peer
if
rw
,
err
:=
cryptoId
.
Run
(
p
.
Pubkey
());
err
!=
nil
{
return
err
}
p
.
conn
=
rw
.
Run
(
p
.
conn
)
return
nil
}
func
(
p
*
Peer
)
startBaseProtocol
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录