Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
b90d7bd7
提交
b90d7bd7
authored
1月 21, 2018
作者:
Dirk McCormick
提交者:
Steven Allen
1月 25, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unneccesary split in IpnsValidator
License: MIT Signed-off-by:
Dirk McCormick
<
dirkmdev@gmail.com
>
上级
281d5eaf
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
68 行增加
和
27 行删除
+68
-27
ipns_validate_test.go
namesys/ipns_validate_test.go
+67
-24
publisher.go
namesys/publisher.go
+1
-3
没有找到文件。
namesys/ipns_validate_test.go
浏览文件 @
b90d7bd7
package
namesys
import
(
"io"
"testing"
"time"
...
...
@@ -18,10 +19,7 @@ func TestValidation(t *testing.T) {
// Generate a key for signing the records
r
:=
u
.
NewSeededRand
(
15
)
// generate deterministic keypair
priv
,
pubk
,
err
:=
ci
.
GenerateKeyPairWithReader
(
ci
.
RSA
,
1024
,
r
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
priv
,
ipnsPath
:=
genKeys
(
t
,
r
)
// Create entry with expiry in one hour
ts
:=
time
.
Now
()
...
...
@@ -30,64 +28,109 @@ func TestValidation(t *testing.T) {
t
.
Fatal
(
err
)
}
// Get IPNS record path
pubkb
,
err
:=
pubk
.
Bytes
()
val
,
err
:=
proto
.
Marshal
(
entry
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pubkh
:=
u
.
Hash
(
pubkb
)
.
B58String
()
ipnsPath
:=
"/ipns/"
+
pubkh
val
,
err
:=
proto
.
Marshal
(
entry
)
// Create the record
rec
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsPath
,
val
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Create the record
r1
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsPath
,
val
,
true
)
// Validate the record
err
=
validator
.
VerifyRecord
(
r
1
)
err
=
validator
.
VerifyRecord
(
r
ec
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Create IPNS record path with a different key
_
,
pubk2
,
err
:=
ci
.
GenerateKeyPairWithReader
(
ci
.
RSA
,
1024
,
r
)
_
,
ipnsWrongAuthor
:=
genKeys
(
t
,
r
)
wrongAuthorRec
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsWrongAuthor
,
val
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pubkb2
,
err
:=
pubk2
.
Bytes
()
// Record should fail validation because path doesn't match author
err
=
validator
.
VerifyRecord
(
wrongAuthorRec
)
if
err
!=
ErrInvalidAuthor
{
t
.
Fatal
(
"ValidateIpnsRecord should have returned ErrInvalidAuthor"
)
}
// Create IPNS record path with extra path components after author
extraPath
:=
ipnsPath
+
"/some/path"
extraPathRec
,
err
:=
record
.
MakePutRecord
(
priv
,
extraPath
,
val
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pubkh2
:=
u
.
Hash
(
pubkb2
)
.
B58String
()
ipnsWrongPath
:=
"/ipns/"
+
pubkh2
r2
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsWrongPath
,
val
,
true
)
// Record should fail validation because path has extra components after author
err
=
validator
.
VerifyRecord
(
extraPathRec
)
if
err
!=
ErrInvalidAuthor
{
t
.
Fatal
(
"ValidateIpnsRecord should have returned ErrInvalidAuthor"
)
}
// Record should fail validation because path doesn't match author
err
=
validator
.
VerifyRecord
(
r2
)
// Create unsigned IPNS record
unsignedRec
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsPath
,
val
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Record should fail validation because IPNS records require signature
err
=
validator
.
VerifyRecord
(
unsignedRec
)
if
err
!=
ErrInvalidAuthor
{
t
.
Fatal
(
"ValidateIpnsRecord should have returned ErrInvalidAuthor"
)
}
// Create unsigned IPNS record with no author
unsignedRecNoAuthor
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsPath
,
val
,
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
noAuth
:=
""
unsignedRecNoAuthor
.
Author
=
&
noAuth
// Record should fail validation because IPNS records require author
err
=
validator
.
VerifyRecord
(
unsignedRecNoAuthor
)
if
err
!=
ErrInvalidAuthor
{
t
.
Fatal
(
"ValidateIpnsRecord should have returned ErrInvalidAuthor"
)
}
// Create expired entry
expired
,
err
:=
CreateRoutingEntryData
(
priv
,
path
.
Path
(
"foo"
),
1
,
ts
.
Add
(
-
1
*
time
.
Hour
))
expired
Entry
,
err
:=
CreateRoutingEntryData
(
priv
,
path
.
Path
(
"foo"
),
1
,
ts
.
Add
(
-
1
*
time
.
Hour
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
valExp
,
err
:=
proto
.
Marshal
(
expired
)
valExp
,
err
:=
proto
.
Marshal
(
expired
Entry
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Create record with the expired entry
r3
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsPath
,
valExp
,
true
)
expiredRec
,
err
:=
record
.
MakePutRecord
(
priv
,
ipnsPath
,
valExp
,
true
)
// Record should fail validation because entry is expired
err
=
validator
.
VerifyRecord
(
r3
)
err
=
validator
.
VerifyRecord
(
expiredRec
)
if
err
!=
ErrExpiredRecord
{
t
.
Fatal
(
"ValidateIpnsRecord should have returned ErrExpiredRecord"
)
}
}
func
genKeys
(
t
*
testing
.
T
,
r
io
.
Reader
)
(
ci
.
PrivKey
,
string
)
{
priv
,
pubk
,
err
:=
ci
.
GenerateKeyPairWithReader
(
ci
.
RSA
,
1024
,
r
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pubkb
,
err
:=
pubk
.
Bytes
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
p
:=
"/ipns/"
+
u
.
Hash
(
pubkb
)
.
B58String
()
return
priv
,
p
}
namesys/publisher.go
浏览文件 @
b90d7bd7
...
...
@@ -5,7 +5,6 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"
pb
"github.com/ipfs/go-ipfs/namesys/pb"
...
...
@@ -319,8 +318,7 @@ func ValidateIpnsRecord(r *record.ValidationRecord) error {
// need to do that here
// Author in key must match author in record
parts
:=
strings
.
Split
(
r
.
Key
,
"/"
)
pid
,
err
:=
peer
.
IDB58Decode
(
parts
[
0
])
pid
,
err
:=
peer
.
IDB58Decode
(
r
.
Key
)
if
err
!=
nil
{
return
ErrInvalidAuthor
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论