Skip to content

Commit

Permalink
Update go-libp2p, fix tests with weak RSA keys
Browse files Browse the repository at this point in the history
This commit was moved from ipfs/go-namesys@f6aa2bd
  • Loading branch information
bigs authored and Stebalien committed Aug 23, 2019
1 parent f400d0b commit cb28b8f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 49 deletions.
13 changes: 5 additions & 8 deletions namesys/ipns_resolver_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/test"

ds "github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
mockrouting "github.com/ipfs/go-ipfs-routing/mock"
offline "github.com/ipfs/go-ipfs-routing/offline"
u "github.com/ipfs/go-ipfs-util"
ipns "github.com/ipfs/go-ipns"
path "github.com/ipfs/go-path"
opts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
Expand Down Expand Up @@ -137,19 +138,15 @@ func TestResolverValidation(t *testing.T) {
}

func genKeys(t *testing.T) (ci.PrivKey, peer.ID, string, string) {
sr := u.NewTimeSeededRand()
priv, _, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, sr)
sk, pk, err := test.RandTestKeyPair(ci.RSA, 2048)
if err != nil {
t.Fatal(err)
}

// Create entry with expiry in one hour
pid, err := peer.IDFromPrivateKey(priv)
id, err := peer.IDFromPublicKey(pk)
if err != nil {
t.Fatal(err)
}

return priv, pid, PkKeyForID(pid), ipns.RecordKey(pid)
return sk, id, PkKeyForID(id), ipns.RecordKey(id)
}

type mockValueStore struct {
Expand Down
2 changes: 1 addition & 1 deletion namesys/namesys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestNamesysResolution(t *testing.T) {

func TestPublishWithCache0(t *testing.T) {
dst := dssync.MutexWrap(ds.NewMapDatastore())
priv, _, err := ci.GenerateKeyPair(ci.RSA, 1024)
priv, _, err := ci.GenerateKeyPair(ci.RSA, 2048)
if err != nil {
t.Fatal(err)
}
Expand Down
54 changes: 14 additions & 40 deletions namesys/resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
mockrouting "github.com/ipfs/go-ipfs-routing/mock"
ipns "github.com/ipfs/go-ipns"
path "github.com/ipfs/go-path"
ci "github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
test "github.com/libp2p/go-libp2p-core/test"
testutil "github.com/libp2p/go-libp2p-testing/net"
tnet "github.com/libp2p/go-libp2p-testing/net"
)

func TestRoutingResolve(t *testing.T) {
Expand All @@ -26,23 +24,15 @@ func TestRoutingResolve(t *testing.T) {
resolver := NewIpnsResolver(d)
publisher := NewIpnsPublisher(d, dstore)

privk, pubk, err := test.RandTestKeyPair(ci.RSA, 512)
if err != nil {
t.Fatal(err)
}
identity := tnet.RandIdentityOrFatal(t)

h := path.FromString("/ipfs/QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN")
err = publisher.Publish(context.Background(), privk, h)
err := publisher.Publish(context.Background(), identity.PrivateKey(), h)
if err != nil {
t.Fatal(err)
}

pid, err := peer.IDFromPublicKey(pubk)
if err != nil {
t.Fatal(err)
}

res, err := resolver.Resolve(context.Background(), pid.Pretty())
res, err := resolver.Resolve(context.Background(), identity.ID().Pretty())
if err != nil {
t.Fatal(err)
}
Expand All @@ -59,36 +49,28 @@ func TestPrexistingExpiredRecord(t *testing.T) {
resolver := NewIpnsResolver(d)
publisher := NewIpnsPublisher(d, dstore)

privk, pubk, err := test.RandTestKeyPair(ci.RSA, 512)
if err != nil {
t.Fatal(err)
}

id, err := peer.IDFromPublicKey(pubk)
if err != nil {
t.Fatal(err)
}
identity := tnet.RandIdentityOrFatal(t)

// Make an expired record and put it in the datastore
h := path.FromString("/ipfs/QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN")
eol := time.Now().Add(time.Hour * -1)

entry, err := ipns.Create(privk, []byte(h), 0, eol)
entry, err := ipns.Create(identity.PrivateKey(), []byte(h), 0, eol)
if err != nil {
t.Fatal(err)
}
err = PutRecordToRouting(context.Background(), d, pubk, entry)
err = PutRecordToRouting(context.Background(), d, identity.PublicKey(), entry)
if err != nil {
t.Fatal(err)
}

// Now, with an old record in the system already, try and publish a new one
err = publisher.Publish(context.Background(), privk, h)
err = publisher.Publish(context.Background(), identity.PrivateKey(), h)
if err != nil {
t.Fatal(err)
}

err = verifyCanResolve(resolver, id.Pretty(), h)
err = verifyCanResolve(resolver, identity.ID().Pretty(), h)
if err != nil {
t.Fatal(err)
}
Expand All @@ -101,35 +83,27 @@ func TestPrexistingRecord(t *testing.T) {
resolver := NewIpnsResolver(d)
publisher := NewIpnsPublisher(d, dstore)

privk, pubk, err := test.RandTestKeyPair(ci.RSA, 512)
if err != nil {
t.Fatal(err)
}

id, err := peer.IDFromPublicKey(pubk)
if err != nil {
t.Fatal(err)
}
identity := tnet.RandIdentityOrFatal(t)

// Make a good record and put it in the datastore
h := path.FromString("/ipfs/QmZULkCELmmk5XNfCgTnCyFgAVxBRBXyDHGGMVoLFLiXEN")
eol := time.Now().Add(time.Hour)
entry, err := ipns.Create(privk, []byte(h), 0, eol)
entry, err := ipns.Create(identity.PrivateKey(), []byte(h), 0, eol)
if err != nil {
t.Fatal(err)
}
err = PutRecordToRouting(context.Background(), d, pubk, entry)
err = PutRecordToRouting(context.Background(), d, identity.PublicKey(), entry)
if err != nil {
t.Fatal(err)
}

// Now, with an old record in the system already, try and publish a new one
err = publisher.Publish(context.Background(), privk, h)
err = publisher.Publish(context.Background(), identity.PrivateKey(), h)
if err != nil {
t.Fatal(err)
}

err = verifyCanResolve(resolver, id.Pretty(), h)
err = verifyCanResolve(resolver, identity.ID().Pretty(), h)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit cb28b8f

Please sign in to comment.