Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
7c9bfa05
提交
7c9bfa05
authored
4月 13, 2015
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1073 from ipfs/secio-err-echo
secio: better error detection
上级
695a15e7
127c0325
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
14 行删除
+16
-14
al.go
p2p/crypto/secio/al.go
+3
-3
protocol.go
p2p/crypto/secio/protocol.go
+13
-11
没有找到文件。
p2p/crypto/secio/al.go
浏览文件 @
7c9bfa05
...
...
@@ -91,11 +91,11 @@ func newBlockCipher(cipherT string, key []byte) (cipher.Block, error) {
// Determines which algorithm to use. Note: f(a, b) = f(b, a)
func
selectBest
(
order
int
,
p1
,
p2
string
)
(
string
,
error
)
{
var
f
,
s
[]
string
switch
order
{
case
-
1
:
switch
{
case
order
<
0
:
f
=
strings
.
Split
(
p2
,
","
)
s
=
strings
.
Split
(
p1
,
","
)
case
1
:
case
order
>
0
:
f
=
strings
.
Split
(
p1
,
","
)
s
=
strings
.
Split
(
p2
,
","
)
default
:
// Exact same preferences.
...
...
p2p/crypto/secio/protocol.go
浏览文件 @
7c9bfa05
...
...
@@ -24,6 +24,9 @@ var ErrUnsupportedKeyType = errors.New("unsupported key type")
// ErrClosed signals the closing of a connection.
var
ErrClosed
=
errors
.
New
(
"connection closed"
)
// ErrEcho is returned when we're attempting to handshake with the same keys and nonces.
var
ErrEcho
=
errors
.
New
(
"same keys and nonces. one side talking to self."
)
// nonceSize is the size of our nonces (in bytes)
const
nonceSize
=
16
...
...
@@ -145,6 +148,10 @@ func (s *secureSession) handshake(ctx context.Context, insecure io.ReadWriter) e
oh1
:=
u
.
Hash
(
append
(
proposeIn
.
GetPubkey
(),
nonceOut
...
))
oh2
:=
u
.
Hash
(
append
(
myPubKeyBytes
,
proposeIn
.
GetRand
()
...
))
order
:=
bytes
.
Compare
(
oh1
,
oh2
)
if
order
==
0
{
return
ErrEcho
// talking to self (same socket. must be reuseport + dialing self)
}
s
.
local
.
curveT
,
err
=
selectBest
(
order
,
SupportedExchanges
,
proposeIn
.
GetExchanges
())
if
err
!=
nil
{
return
err
...
...
@@ -242,19 +249,14 @@ func (s *secureSession) handshake(ctx context.Context, insecure io.ReadWriter) e
k1
,
k2
:=
ci
.
KeyStretcher
(
s
.
local
.
cipherT
,
s
.
local
.
hashT
,
s
.
sharedSecret
)
// use random nonces to decide order.
switch
order
{
case
1
:
case
-
1
:
switch
{
case
order
>
0
:
// just break
case
order
<
0
:
k1
,
k2
=
k2
,
k1
// swap
default
:
log
.
Error
(
"WOAH: same keys (AND same nonce: 1/(2^128) chance!)."
)
log
.
Errorf
(
"k1: %v, k2: %v, insecure: %v, insecureM %v"
,
k1
,
k2
,
s
.
insecure
,
s
.
insecureM
)
// this shouldn't happen. must determine order another way.
// use the same keys but, make sure to copy underlying data!
copy
(
k2
.
IV
,
k1
.
IV
)
copy
(
k2
.
MacKey
,
k1
.
MacKey
)
copy
(
k2
.
CipherKey
,
k1
.
CipherKey
)
// we should've bailed before this. but if not, bail here.
return
ErrEcho
}
s
.
local
.
keys
=
k1
s
.
remote
.
keys
=
k2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论