1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-25 03:32:50 +08:00

cleanup from CR

This commit is contained in:
Jeromy
2014-10-31 06:26:28 +00:00
parent 09004e4989
commit 5edbca2e70
10 changed files with 29 additions and 32 deletions

4
Godeps/Godeps.json generated
View File

@ -1,6 +1,6 @@
{ {
"ImportPath": "github.com/jbenet/go-ipfs", "ImportPath": "github.com/jbenet/go-ipfs",
"GoVersion": "go1.3.3", "GoVersion": "devel +9340f9f6dfc9 Fri Oct 31 00:48:57 2014 -0300",
"Packages": [ "Packages": [
"./..." "./..."
], ],
@ -98,7 +98,7 @@
}, },
{ {
"ImportPath": "github.com/jbenet/go-msgio", "ImportPath": "github.com/jbenet/go-msgio",
"Rev": "c9069ab79c95aa0686347b516972c7329c4391f2" "Rev": "ab0e7a0e111d7c7d814ad238bcbf3934efb76ac3"
}, },
{ {
"ImportPath": "github.com/jbenet/go-multiaddr", "ImportPath": "github.com/jbenet/go-multiaddr",

View File

@ -36,12 +36,8 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
if !ok { if !ok {
return nil, ValueTypeMismatch return nil, ValueTypeMismatch
} }
//TODO: we *could* verify data coming in from the datastore here
// but its probably very unecessary return blocks.NewBlockWithHash(bdata, mh.Multihash(k))
return &blocks.Block{
Data: bdata,
Multihash: mh.Multihash(k),
}, nil
} }
func (bs *blockstore) Put(block *blocks.Block) error { func (bs *blockstore) Put(block *blocks.Block) error {

View File

@ -51,7 +51,7 @@ type PrivKey interface {
// Generate a secret string of bytes // Generate a secret string of bytes
GenSecret() []byte GenSecret() []byte
Unencrypt(b []byte) ([]byte, error) Decrypt(b []byte) ([]byte, error)
} }
type PubKey interface { type PubKey interface {

View File

@ -71,7 +71,7 @@ func (sk *RsaPrivateKey) GetPublic() PubKey {
return &RsaPublicKey{&sk.k.PublicKey} return &RsaPublicKey{&sk.k.PublicKey}
} }
func (sk *RsaPrivateKey) Unencrypt(b []byte) ([]byte, error) { func (sk *RsaPrivateKey) Decrypt(b []byte) ([]byte, error) {
return rsa.DecryptPKCS1v15(rand.Reader, sk.k, b) return rsa.DecryptPKCS1v15(rand.Reader, sk.k, b)
} }

View File

@ -276,7 +276,6 @@ func (s *SecurePipe) handleSecureIn(hashType, cipherType string, tIV, tCKey, tMK
hmacOk := hmac.Equal(data[mark:], expected) hmacOk := hmac.Equal(data[mark:], expected)
if !hmacOk { if !hmacOk {
s.Duplex.In <- nil
continue continue
} }

View File

@ -15,7 +15,7 @@ It has these top-level messages:
*/ */
package spipe_pb package spipe_pb
import proto "code.google.com/p/gogoprotobuf/proto" import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import math "math" import math "math"
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
@ -96,7 +96,7 @@ func (m *Exchange) GetSignature() []byte {
type DataSig struct { type DataSig struct {
Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"` Data []byte `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
Sig []byte `protobuf:"bytes,2,opt,name=sig" json:"sig,omitempty"` Signature []byte `protobuf:"bytes,2,opt,name=signature" json:"signature,omitempty"`
Id *uint64 `protobuf:"varint,3,opt,name=id" json:"id,omitempty"` Id *uint64 `protobuf:"varint,3,opt,name=id" json:"id,omitempty"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
} }
@ -112,9 +112,9 @@ func (m *DataSig) GetData() []byte {
return nil return nil
} }
func (m *DataSig) GetSig() []byte { func (m *DataSig) GetSignature() []byte {
if m != nil { if m != nil {
return m.Sig return m.Signature
} }
return nil return nil
} }

View File

@ -15,6 +15,6 @@ message Exchange {
message DataSig { message DataSig {
optional bytes data = 1; optional bytes data = 1;
optional bytes sig = 2; optional bytes signature = 2;
optional uint64 id = 3; optional uint64 id = 3;
} }

View File

@ -25,8 +25,8 @@ type SignedPipe struct {
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
mesid uint64 localMsgID uint64
theirmesid uint64 removeMsgID uint64
} }
// secureChallengeSize is a constant that determines the initial challenge, and every subsequent // secureChallengeSize is a constant that determines the initial challenge, and every subsequent
@ -77,6 +77,8 @@ func (sp *SignedPipe) tryRecv() ([]byte, bool) {
} }
} }
// reduceChallenge reduces a series of bytes into a
// single uint64 we can use as a seed for message IDs
func reduceChallenge(cha []byte) uint64 { func reduceChallenge(cha []byte) uint64 {
var out uint64 var out uint64
for _, b := range cha { for _, b := range cha {
@ -134,8 +136,8 @@ func (sp *SignedPipe) handshake() error {
return context.Canceled return context.Canceled
} }
// Unencrypt and verify their challenge // Decrypt and verify their challenge
unenc, err := sp.local.PrivKey().Unencrypt(theirEnc) unenc, err := sp.local.PrivKey().Decrypt(theirEnc)
if err != nil { if err != nil {
return err return err
} }
@ -182,8 +184,8 @@ func (sp *SignedPipe) handshake() error {
return errors.New("Incorrect signature on challenge") return errors.New("Incorrect signature on challenge")
} }
sp.theirmesid = reduceChallenge(challenge) sp.removeMsgID = reduceChallenge(challenge)
sp.mesid = reduceChallenge(unenc) sp.localMsgID = reduceChallenge(unenc)
go sp.handleIn(theirPubKey) go sp.handleIn(theirPubKey)
go sp.handleOut(sp.local.PrivKey()) go sp.handleOut(sp.local.PrivKey())
@ -235,14 +237,14 @@ func (sp *SignedPipe) handleOut(pk ci.PrivKey) {
} }
sdata.Data = data sdata.Data = data
sdata.Sig = sig sdata.Signature = sig
sdata.Id = proto.Uint64(sp.mesid) sdata.Id = proto.Uint64(sp.localMsgID)
b, err := proto.Marshal(sdata) b, err := proto.Marshal(sdata)
if err != nil { if err != nil {
log.Error("Error marshaling signed data object: %s", err) log.Error("Error marshaling signed data object: %s", err)
return return
} }
sp.mesid++ sp.localMsgID++
select { select {
case sp.insecure.Out <- b: case sp.insecure.Out <- b:
@ -273,7 +275,7 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) {
log.Error("Failed to unmarshal sigdata object") log.Error("Failed to unmarshal sigdata object")
continue continue
} }
correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSig()) correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSignature())
if err != nil { if err != nil {
log.Error(err) log.Error(err)
continue continue
@ -283,11 +285,11 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) {
continue continue
} }
if sdata.GetId() != sp.theirmesid { if sdata.GetId() != sp.removeMsgID {
log.Critical("Out of order message id!") log.Critical("Out of order message id!")
return return
} }
sp.theirmesid++ sp.removeMsgID++
select { select {
case <-sp.ctx.Done(): case <-sp.ctx.Done():

View File

@ -118,7 +118,7 @@ func runEncryptBenchmark(b *testing.B) {
}() }()
data := make([]byte, 1024*512) data := make([]byte, 1024*512)
util.NewFastRand().Read(data) util.NewTimeSeededRand().Read(data)
// Begin actual benchmarking // Begin actual benchmarking
b.ResetTimer() b.ResetTimer()
@ -170,7 +170,7 @@ func BenchmarkSignedChannel(b *testing.B) {
}() }()
data := make([]byte, 1024*512) data := make([]byte, 1024*512)
util.NewFastRand().Read(data) util.NewTimeSeededRand().Read(data)
// Begin actual benchmarking // Begin actual benchmarking
b.ResetTimer() b.ResetTimer()
@ -199,7 +199,7 @@ func BenchmarkDataTransfer(b *testing.B) {
}() }()
data := make([]byte, 1024*512) data := make([]byte, 1024*512)
util.NewFastRand().Read(data) util.NewTimeSeededRand().Read(data)
// Begin actual benchmarking // Begin actual benchmarking
b.ResetTimer() b.ResetTimer()

View File

@ -13,7 +13,7 @@ It has these top-level messages:
*/ */
package dht_pb package dht_pb
import proto "code.google.com/p/gogoprotobuf/proto" import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import math "math" import math "math"
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.