diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index d8a6595ea..4ac3d143d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,6 +1,6 @@ { "ImportPath": "github.com/jbenet/go-ipfs", - "GoVersion": "go1.3.3", + "GoVersion": "devel +9340f9f6dfc9 Fri Oct 31 00:48:57 2014 -0300", "Packages": [ "./..." ], @@ -98,7 +98,7 @@ }, { "ImportPath": "github.com/jbenet/go-msgio", - "Rev": "c9069ab79c95aa0686347b516972c7329c4391f2" + "Rev": "ab0e7a0e111d7c7d814ad238bcbf3934efb76ac3" }, { "ImportPath": "github.com/jbenet/go-multiaddr", diff --git a/blockstore/blockstore.go b/blockstore/blockstore.go index ca55046bb..1a2bf540d 100644 --- a/blockstore/blockstore.go +++ b/blockstore/blockstore.go @@ -36,12 +36,8 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) { if !ok { return nil, ValueTypeMismatch } - //TODO: we *could* verify data coming in from the datastore here - // but its probably very unecessary - return &blocks.Block{ - Data: bdata, - Multihash: mh.Multihash(k), - }, nil + + return blocks.NewBlockWithHash(bdata, mh.Multihash(k)) } func (bs *blockstore) Put(block *blocks.Block) error { diff --git a/crypto/key.go b/crypto/key.go index 856866aaa..872bbd0c9 100644 --- a/crypto/key.go +++ b/crypto/key.go @@ -51,7 +51,7 @@ type PrivKey interface { // Generate a secret string of bytes GenSecret() []byte - Unencrypt(b []byte) ([]byte, error) + Decrypt(b []byte) ([]byte, error) } type PubKey interface { diff --git a/crypto/rsa.go b/crypto/rsa.go index bb131e06a..1ef99776b 100644 --- a/crypto/rsa.go +++ b/crypto/rsa.go @@ -71,7 +71,7 @@ func (sk *RsaPrivateKey) GetPublic() PubKey { 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) } diff --git a/crypto/spipe/handshake.go b/crypto/spipe/handshake.go index d802f9f90..fdcd51a13 100644 --- a/crypto/spipe/handshake.go +++ b/crypto/spipe/handshake.go @@ -276,7 +276,6 @@ func (s *SecurePipe) handleSecureIn(hashType, cipherType string, tIV, tCKey, tMK hmacOk := hmac.Equal(data[mark:], expected) if !hmacOk { - s.Duplex.In <- nil continue } diff --git a/crypto/spipe/internal/pb/spipe.pb.go b/crypto/spipe/internal/pb/spipe.pb.go index 9b5b867e2..684ce5da9 100644 --- a/crypto/spipe/internal/pb/spipe.pb.go +++ b/crypto/spipe/internal/pb/spipe.pb.go @@ -15,7 +15,7 @@ It has these top-level messages: */ 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" // Reference imports to suppress errors if they are not otherwise used. @@ -96,7 +96,7 @@ func (m *Exchange) GetSignature() []byte { type DataSig struct { 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"` XXX_unrecognized []byte `json:"-"` } @@ -112,9 +112,9 @@ func (m *DataSig) GetData() []byte { return nil } -func (m *DataSig) GetSig() []byte { +func (m *DataSig) GetSignature() []byte { if m != nil { - return m.Sig + return m.Signature } return nil } diff --git a/crypto/spipe/internal/pb/spipe.proto b/crypto/spipe/internal/pb/spipe.proto index 94e4f06f7..5f263e7dd 100644 --- a/crypto/spipe/internal/pb/spipe.proto +++ b/crypto/spipe/internal/pb/spipe.proto @@ -15,6 +15,6 @@ message Exchange { message DataSig { optional bytes data = 1; - optional bytes sig = 2; + optional bytes signature = 2; optional uint64 id = 3; } diff --git a/crypto/spipe/signedpipe.go b/crypto/spipe/signedpipe.go index 938b88f1b..3bc7b1d6f 100644 --- a/crypto/spipe/signedpipe.go +++ b/crypto/spipe/signedpipe.go @@ -25,8 +25,8 @@ type SignedPipe struct { ctx context.Context cancel context.CancelFunc - mesid uint64 - theirmesid uint64 + localMsgID uint64 + removeMsgID uint64 } // 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 { var out uint64 for _, b := range cha { @@ -134,8 +136,8 @@ func (sp *SignedPipe) handshake() error { return context.Canceled } - // Unencrypt and verify their challenge - unenc, err := sp.local.PrivKey().Unencrypt(theirEnc) + // Decrypt and verify their challenge + unenc, err := sp.local.PrivKey().Decrypt(theirEnc) if err != nil { return err } @@ -182,8 +184,8 @@ func (sp *SignedPipe) handshake() error { return errors.New("Incorrect signature on challenge") } - sp.theirmesid = reduceChallenge(challenge) - sp.mesid = reduceChallenge(unenc) + sp.removeMsgID = reduceChallenge(challenge) + sp.localMsgID = reduceChallenge(unenc) go sp.handleIn(theirPubKey) go sp.handleOut(sp.local.PrivKey()) @@ -235,14 +237,14 @@ func (sp *SignedPipe) handleOut(pk ci.PrivKey) { } sdata.Data = data - sdata.Sig = sig - sdata.Id = proto.Uint64(sp.mesid) + sdata.Signature = sig + sdata.Id = proto.Uint64(sp.localMsgID) b, err := proto.Marshal(sdata) if err != nil { log.Error("Error marshaling signed data object: %s", err) return } - sp.mesid++ + sp.localMsgID++ select { case sp.insecure.Out <- b: @@ -273,7 +275,7 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) { log.Error("Failed to unmarshal sigdata object") continue } - correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSig()) + correct, err := theirPubkey.Verify(sdata.GetData(), sdata.GetSignature()) if err != nil { log.Error(err) continue @@ -283,11 +285,11 @@ func (sp *SignedPipe) handleIn(theirPubkey ci.PubKey) { continue } - if sdata.GetId() != sp.theirmesid { + if sdata.GetId() != sp.removeMsgID { log.Critical("Out of order message id!") return } - sp.theirmesid++ + sp.removeMsgID++ select { case <-sp.ctx.Done(): diff --git a/crypto/spipe/spipe_test.go b/crypto/spipe/spipe_test.go index c4e0a0b7f..c0f15ac85 100644 --- a/crypto/spipe/spipe_test.go +++ b/crypto/spipe/spipe_test.go @@ -118,7 +118,7 @@ func runEncryptBenchmark(b *testing.B) { }() data := make([]byte, 1024*512) - util.NewFastRand().Read(data) + util.NewTimeSeededRand().Read(data) // Begin actual benchmarking b.ResetTimer() @@ -170,7 +170,7 @@ func BenchmarkSignedChannel(b *testing.B) { }() data := make([]byte, 1024*512) - util.NewFastRand().Read(data) + util.NewTimeSeededRand().Read(data) // Begin actual benchmarking b.ResetTimer() @@ -199,7 +199,7 @@ func BenchmarkDataTransfer(b *testing.B) { }() data := make([]byte, 1024*512) - util.NewFastRand().Read(data) + util.NewTimeSeededRand().Read(data) // Begin actual benchmarking b.ResetTimer() diff --git a/routing/dht/pb/dht.pb.go b/routing/dht/pb/dht.pb.go index 22c87bac9..6c488c51a 100644 --- a/routing/dht/pb/dht.pb.go +++ b/routing/dht/pb/dht.pb.go @@ -13,7 +13,7 @@ It has these top-level messages: */ 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" // Reference imports to suppress errors if they are not otherwise used.