Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
bc129ac5
提交
bc129ac5
authored
6月 05, 2018
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
embed public keys inside ipns records, use for validation
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
上级
f7a98092
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
77 行增加
和
13 行删除
+77
-13
namesys.pb.go
namesys/pb/namesys.pb.go
+24
-9
namesys.proto
namesys/pb/namesys.proto
+6
-0
publisher.go
namesys/publisher.go
+13
-0
validator.go
namesys/validator.go
+34
-4
没有找到文件。
namesys/pb/namesys.pb.go
浏览文件 @
bc129ac5
// Code generated by protoc-gen-gogo.
// source: namesys.proto
// source: namesys
/pb/namesys
.proto
// DO NOT EDIT!
/*
Package namesys_pb is a generated protocol buffer package.
It is generated from these files:
namesys.proto
namesys
/pb/namesys
.proto
It has these top-level messages:
IpnsEntry
...
...
@@ -14,10 +14,12 @@ It has these top-level messages:
package
namesys_pb
import
proto
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
import
fmt
"fmt"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
fmt
.
Errorf
var
_
=
math
.
Inf
type
IpnsEntry_ValidityType
int32
...
...
@@ -52,13 +54,18 @@ func (x *IpnsEntry_ValidityType) UnmarshalJSON(data []byte) error {
}
type
IpnsEntry
struct
{
Value
[]
byte
`protobuf:"bytes,1,req,name=value" json:"value,omitempty"`
Signature
[]
byte
`protobuf:"bytes,2,req,name=signature" json:"signature,omitempty"`
ValidityType
*
IpnsEntry_ValidityType
`protobuf:"varint,3,opt,name=validityType,enum=namesys.pb.IpnsEntry_ValidityType" json:"validityType,omitempty"`
Validity
[]
byte
`protobuf:"bytes,4,opt,name=validity" json:"validity,omitempty"`
Sequence
*
uint64
`protobuf:"varint,5,opt,name=sequence" json:"sequence,omitempty"`
Ttl
*
uint64
`protobuf:"varint,6,opt,name=ttl" json:"ttl,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
Value
[]
byte
`protobuf:"bytes,1,req,name=value" json:"value,omitempty"`
Signature
[]
byte
`protobuf:"bytes,2,req,name=signature" json:"signature,omitempty"`
ValidityType
*
IpnsEntry_ValidityType
`protobuf:"varint,3,opt,name=validityType,enum=namesys.pb.IpnsEntry_ValidityType" json:"validityType,omitempty"`
Validity
[]
byte
`protobuf:"bytes,4,opt,name=validity" json:"validity,omitempty"`
Sequence
*
uint64
`protobuf:"varint,5,opt,name=sequence" json:"sequence,omitempty"`
Ttl
*
uint64
`protobuf:"varint,6,opt,name=ttl" json:"ttl,omitempty"`
// in order for nodes to properly validate a record upon receipt, they need the public
// key associated with it. For old RSA keys, its easiest if we just send this as part of
// the record itself. For newer ed25519 keys, the public key can be embedded in the
// peerID, making this field unnecessary.
PubKey
[]
byte
`protobuf:"bytes,7,opt,name=pubKey" json:"pubKey,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
IpnsEntry
)
Reset
()
{
*
m
=
IpnsEntry
{}
}
...
...
@@ -107,6 +114,14 @@ func (m *IpnsEntry) GetTtl() uint64 {
return
0
}
func
(
m
*
IpnsEntry
)
GetPubKey
()
[]
byte
{
if
m
!=
nil
{
return
m
.
PubKey
}
return
nil
}
func
init
()
{
proto
.
RegisterType
((
*
IpnsEntry
)(
nil
),
"namesys.pb.IpnsEntry"
)
proto
.
RegisterEnum
(
"namesys.pb.IpnsEntry_ValidityType"
,
IpnsEntry_ValidityType_name
,
IpnsEntry_ValidityType_value
)
}
namesys/pb/namesys.proto
浏览文件 @
bc129ac5
...
...
@@ -14,4 +14,10 @@ message IpnsEntry {
optional
uint64
sequence
=
5
;
optional
uint64
ttl
=
6
;
// in order for nodes to properly validate a record upon receipt, they need the public
// key associated with it. For old RSA keys, its easiest if we just send this as part of
// the record itself. For newer ed25519 keys, the public key can be embedded in the
// peerID, making this field unnecessary.
optional
bytes
pubKey
=
7
;
}
namesys/publisher.go
浏览文件 @
bc129ac5
...
...
@@ -240,6 +240,17 @@ func PutRecordToRouting(ctx context.Context, r routing.ValueStore, k ci.PubKey,
return
err
}
// if we can't derive the public key from the peerID, embed the entire pubkey in
// the record to make the verifiers job easier
if
extractedPublicKey
==
nil
{
pubkeyBytes
,
err
:=
k
.
Bytes
()
if
err
!=
nil
{
return
err
}
entry
.
PubKey
=
pubkeyBytes
}
namekey
,
ipnskey
:=
IpnsKeysForID
(
id
)
go
func
()
{
...
...
@@ -247,6 +258,8 @@ func PutRecordToRouting(ctx context.Context, r routing.ValueStore, k ci.PubKey,
}()
// Publish the public key if a public key cannot be extracted from the ID
// TODO: once v0.4.16 is widespread enough, we can stop doing this
// and at that point we can even deprecate the /pk/ namespace in the dht
if
extractedPublicKey
==
nil
{
go
func
()
{
errs
<-
PublishPublicKey
(
ctx
,
r
,
namekey
,
k
)
...
...
namesys/validator.go
浏览文件 @
bc129ac5
...
...
@@ -3,11 +3,13 @@ package namesys
import
(
"bytes"
"errors"
"fmt"
"time"
pb
"github.com/ipfs/go-ipfs/namesys/pb"
peer
"gx/ipfs/QmcJukH2sAFjY3HdBKq35WDzWoL3UUu2gt9wdfqZTUyM74/go-libp2p-peer"
pstore
"gx/ipfs/QmdeiKhUy1TVGBaKxt7y1QmBDLBdisSrLJ1x58Eoj4PXUh/go-libp2p-peerstore"
ic
"gx/ipfs/Qme1knMqwt1hKZbc1BmQFmnm9f36nyQGwXxPGVpVJ9rMK5/go-libp2p-crypto"
u
"gx/ipfs/QmNiJuT8Ja3hMVpBHXv3Q6dwmperaQ6JjLtpMQgMCD7xvx/go-ipfs-util"
record
"gx/ipfs/QmTUyK82BVPA6LmSzEJpfEunk9uBaQzWtMsNP917tVj4sT/go-libp2p-record"
...
...
@@ -65,10 +67,10 @@ func (v IpnsValidator) Validate(key string, value []byte) error {
log
.
Debugf
(
"failed to parse ipns record key %s into peer ID"
,
pidString
)
return
ErrKeyFormat
}
pubk
:=
v
.
KeyBook
.
PubKey
(
pid
)
if
pubk
==
nil
{
log
.
Debugf
(
"public key with hash %s not found in peer store"
,
pid
)
return
ErrPublicKeyNotFound
pubk
,
err
:=
v
.
getPublicKey
(
pid
,
entry
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"getting public key failed: %s"
,
err
)
}
// Check the ipns record signature with the public key
...
...
@@ -94,6 +96,34 @@ func (v IpnsValidator) Validate(key string, value []byte) error {
return
nil
}
func
(
v
IpnsValidator
)
getPublicKey
(
pid
peer
.
ID
,
entry
*
pb
.
IpnsEntry
)
(
ic
.
PubKey
,
error
)
{
if
entry
.
PubKey
!=
nil
{
pk
,
err
:=
ic
.
UnmarshalPublicKey
(
entry
.
PubKey
)
if
err
!=
nil
{
// TODO: i think this counts as a 'malformed record' and should be discarded
log
.
Debugf
(
"public key in ipns record failed to parse: "
,
err
)
return
nil
,
err
}
expPid
,
err
:=
peer
.
IDFromPublicKey
(
pk
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"could not regenerate peerID from pubkey: %s"
,
err
)
}
if
pid
!=
expPid
{
return
nil
,
fmt
.
Errorf
(
"pubkey in record did not match expected pubkey"
)
}
return
pk
,
nil
}
pubk
:=
v
.
KeyBook
.
PubKey
(
pid
)
if
pubk
==
nil
{
log
.
Debugf
(
"public key with hash %s not found in peer store"
,
pid
)
return
nil
,
ErrPublicKeyNotFound
}
return
pubk
,
nil
}
// IpnsSelectorFunc selects the best record by checking which has the highest
// sequence number and latest EOL
func
(
v
IpnsValidator
)
Select
(
k
string
,
vals
[][]
byte
)
(
int
,
error
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论