Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
9c3e8d7b
提交
9c3e8d7b
authored
9月 13, 2014
作者:
Brian Tiger Chow
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #63 from jbenet/fix/identify-test_handshake-issue-61
fix(identify) Handshake
上级
5a41a2ac
24b7703f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
9 行删除
+29
-9
identify.go
identify/identify.go
+27
-7
conn.go
swarm/conn.go
+2
-2
没有找到文件。
identify/identify.go
浏览文件 @
9c3e8d7b
...
...
@@ -33,11 +33,14 @@ 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
,
out
chan
[]
byte
)
(
chan
[]
byte
,
chan
[]
byte
,
error
)
{
func
Handshake
(
self
,
remote
*
peer
.
Peer
,
in
<-
chan
[]
byte
,
out
chan
<-
[]
byte
)
(
<-
chan
[]
byte
,
chan
<-
[]
byte
,
error
)
{
// Generate and send Hello packet.
// Hello = (rand, PublicKey, Supported)
nonce
:=
make
([]
byte
,
16
)
rand
.
Read
(
nonce
)
_
,
err
:=
rand
.
Read
(
nonce
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
hello
:=
new
(
Hello
)
...
...
@@ -95,6 +98,9 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) (chan []byte, chan
}
epubkey
,
done
,
err
:=
ci
.
GenerateEKeyPair
(
exchange
)
// Generate EphemeralPubKey
if
err
!=
nil
{
return
nil
,
nil
,
err
}
var
handshake
bytes
.
Buffer
// Gather corpus to sign.
handshake
.
Write
(
encoded
)
...
...
@@ -110,6 +116,9 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) (chan []byte, chan
}
exEncoded
,
err
:=
proto
.
Marshal
(
exPacket
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
out
<-
exEncoded
...
...
@@ -124,9 +133,18 @@ func Handshake(self, remote *peer.Peer, in, out chan []byte) (chan []byte, chan
}
var
theirHandshake
bytes
.
Buffer
theirHandshake
.
Write
(
resp
)
theirHandshake
.
Write
(
encoded
)
theirHandshake
.
Write
(
exchangeResp
.
GetEpubkey
())
_
,
err
=
theirHandshake
.
Write
(
resp
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
_
,
err
=
theirHandshake
.
Write
(
encoded
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
_
,
err
=
theirHandshake
.
Write
(
exchangeResp
.
GetEpubkey
())
if
err
!=
nil
{
return
nil
,
nil
,
err
}
ok
,
err
:=
remote
.
PubKey
.
Verify
(
theirHandshake
.
Bytes
(),
exchangeResp
.
GetSignature
())
if
err
!=
nil
{
...
...
@@ -176,7 +194,7 @@ func makeMac(hashType string, key []byte) (hash.Hash, int) {
}
}
func
secureInProxy
(
in
,
secureIn
chan
[]
byte
,
hashType
string
,
tIV
,
tCKey
,
tMKey
[]
byte
)
{
func
secureInProxy
(
in
<-
chan
[]
byte
,
secureIn
chan
<-
[]
byte
,
hashType
string
,
tIV
,
tCKey
,
tMKey
[]
byte
)
{
theirBlock
,
_
:=
aes
.
NewCipher
(
tCKey
)
theirCipher
:=
cipher
.
NewCTR
(
theirBlock
,
tIV
)
...
...
@@ -185,6 +203,7 @@ func secureInProxy(in, secureIn chan []byte, hashType string, tIV, tCKey, tMKey
for
{
data
,
ok
:=
<-
in
if
!
ok
{
close
(
secureIn
)
return
}
...
...
@@ -211,7 +230,7 @@ func secureInProxy(in, secureIn chan []byte, hashType string, tIV, tCKey, tMKey
}
}
func
secureOutProxy
(
out
,
secureOut
chan
[]
byte
,
hashType
string
,
mIV
,
mCKey
,
mMKey
[]
byte
)
{
func
secureOutProxy
(
out
chan
<-
[]
byte
,
secureOut
<-
chan
[]
byte
,
hashType
string
,
mIV
,
mCKey
,
mMKey
[]
byte
)
{
myBlock
,
_
:=
aes
.
NewCipher
(
mCKey
)
myCipher
:=
cipher
.
NewCTR
(
myBlock
,
mIV
)
...
...
@@ -220,6 +239,7 @@ func secureOutProxy(out, secureOut chan []byte, hashType string, mIV, mCKey, mMK
for
{
data
,
ok
:=
<-
secureOut
if
!
ok
{
close
(
out
)
return
}
...
...
swarm/conn.go
浏览文件 @
9c3e8d7b
...
...
@@ -25,8 +25,8 @@ type Conn struct {
Closed
chan
bool
Outgoing
*
msgio
.
Chan
Incoming
*
msgio
.
Chan
secIn
chan
[]
byte
secOut
chan
[]
byte
secIn
<-
chan
[]
byte
secOut
chan
<-
[]
byte
}
// ConnMap maps Keys (Peer.IDs) to Connections.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论