Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
87447f9f
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,发现更多精彩内容 >>
提交
87447f9f
编写于
4月 21, 2015
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
whisper: fix payload loss in case of plaintext decrypt
上级
7f48eb87
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
109 addition
and
4 deletion
+109
-4
whisper/envelope_test.go
whisper/envelope_test.go
+103
-1
whisper/message.go
whisper/message.go
+6
-3
未找到文件。
whisper/envelope_test.go
浏览文件 @
87447f9f
...
...
@@ -4,6 +4,9 @@ import (
"bytes"
"testing"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/ecies"
)
func
TestEnvelopeOpen
(
t
*
testing
.
T
)
{
...
...
@@ -16,7 +19,7 @@ func TestEnvelopeOpen(t *testing.T) {
}
opened
,
err
:=
envelope
.
Open
(
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to open envelope: %v
.
"
,
err
)
t
.
Fatalf
(
"failed to open envelope: %v"
,
err
)
}
if
opened
.
Flags
!=
message
.
Flags
{
t
.
Fatalf
(
"flags mismatch: have %d, want %d"
,
opened
.
Flags
,
message
.
Flags
)
...
...
@@ -38,3 +41,102 @@ func TestEnvelopeOpen(t *testing.T) {
t
.
Fatalf
(
"message hash mismatch: have 0x%x, want 0x%x"
,
opened
.
Hash
,
envelope
.
Hash
())
}
}
func
TestEnvelopeAnonymousOpenUntargeted
(
t
*
testing
.
T
)
{
payload
:=
[]
byte
(
"hello envelope"
)
envelope
,
err
:=
NewMessage
(
payload
)
.
Wrap
(
DefaultPoW
,
Options
{})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to wrap message: %v"
,
err
)
}
opened
,
err
:=
envelope
.
Open
(
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to open envelope: %v"
,
err
)
}
if
opened
.
To
!=
nil
{
t
.
Fatalf
(
"recipient mismatch: have 0x%x, want nil"
,
opened
.
To
)
}
if
bytes
.
Compare
(
opened
.
Payload
,
payload
)
!=
0
{
t
.
Fatalf
(
"payload mismatch: have 0x%x, want 0x%x"
,
opened
.
Payload
,
payload
)
}
}
func
TestEnvelopeAnonymousOpenTargeted
(
t
*
testing
.
T
)
{
key
,
err
:=
crypto
.
GenerateKey
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate test identity: %v"
,
err
)
}
payload
:=
[]
byte
(
"hello envelope"
)
envelope
,
err
:=
NewMessage
(
payload
)
.
Wrap
(
DefaultPoW
,
Options
{
To
:
&
key
.
PublicKey
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to wrap message: %v"
,
err
)
}
opened
,
err
:=
envelope
.
Open
(
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to open envelope: %v"
,
err
)
}
if
opened
.
To
!=
nil
{
t
.
Fatalf
(
"recipient mismatch: have 0x%x, want nil"
,
opened
.
To
)
}
if
bytes
.
Compare
(
opened
.
Payload
,
payload
)
==
0
{
t
.
Fatalf
(
"payload match, should have been encrypted: 0x%x"
,
opened
.
Payload
)
}
}
func
TestEnvelopeIdentifiedOpenUntargeted
(
t
*
testing
.
T
)
{
key
,
err
:=
crypto
.
GenerateKey
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate test identity: %v"
,
err
)
}
payload
:=
[]
byte
(
"hello envelope"
)
envelope
,
err
:=
NewMessage
(
payload
)
.
Wrap
(
DefaultPoW
,
Options
{})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to wrap message: %v"
,
err
)
}
opened
,
err
:=
envelope
.
Open
(
key
)
switch
err
{
case
nil
:
t
.
Fatalf
(
"envelope opened with bad key: %v"
,
opened
)
case
ecies
.
ErrInvalidPublicKey
:
// Ok, key mismatch but opened
default
:
t
.
Fatalf
(
"failed to open envelope: %v"
,
err
)
}
if
opened
.
To
!=
nil
{
t
.
Fatalf
(
"recipient mismatch: have 0x%x, want nil"
,
opened
.
To
)
}
if
bytes
.
Compare
(
opened
.
Payload
,
payload
)
!=
0
{
t
.
Fatalf
(
"payload mismatch: have 0x%x, want 0x%x"
,
opened
.
Payload
,
payload
)
}
}
func
TestEnvelopeIdentifiedOpenTargeted
(
t
*
testing
.
T
)
{
key
,
err
:=
crypto
.
GenerateKey
()
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate test identity: %v"
,
err
)
}
payload
:=
[]
byte
(
"hello envelope"
)
envelope
,
err
:=
NewMessage
(
payload
)
.
Wrap
(
DefaultPoW
,
Options
{
To
:
&
key
.
PublicKey
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"failed to wrap message: %v"
,
err
)
}
opened
,
err
:=
envelope
.
Open
(
key
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to open envelope: %v"
,
err
)
}
if
opened
.
To
!=
nil
{
t
.
Fatalf
(
"recipient mismatch: have 0x%x, want nil"
,
opened
.
To
)
}
if
bytes
.
Compare
(
opened
.
Payload
,
payload
)
!=
0
{
t
.
Fatalf
(
"payload mismatch: have 0x%x, want 0x%x"
,
opened
.
Payload
,
payload
)
}
}
whisper/message.go
浏览文件 @
87447f9f
...
...
@@ -120,9 +120,12 @@ func (self *Message) encrypt(key *ecdsa.PublicKey) (err error) {
}
// decrypt decrypts an encrypted payload with a private key.
func
(
self
*
Message
)
decrypt
(
key
*
ecdsa
.
PrivateKey
)
(
err
error
)
{
self
.
Payload
,
err
=
crypto
.
Decrypt
(
key
,
self
.
Payload
)
return
func
(
self
*
Message
)
decrypt
(
key
*
ecdsa
.
PrivateKey
)
error
{
cleartext
,
err
:=
crypto
.
Decrypt
(
key
,
self
.
Payload
)
if
err
==
nil
{
self
.
Payload
=
cleartext
}
return
err
}
// hash calculates the SHA3 checksum of the message flags and payload.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录