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
  • Loading branch information
bigs committed Aug 3, 2019
1 parent cd3fcb9 commit 048cdc0
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 79 deletions.
2 changes: 1 addition & 1 deletion core/coreapi/test/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (NodeProvider) MakeAPISwarm(ctx context.Context, fullIdentity bool, n int)
for i := 0; i < n; i++ {
var ident config.Identity
if fullIdentity {
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 512)
sk, pk, err := ci.GenerateKeyPair(ci.RSA, 2048)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (cfg *BuildCfg) options(ctx context.Context) (fx.Option, *cfg.Config) {

func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
c := cfg.Config{}
priv, pub, err := ci.GenerateKeyPairWithReader(ci.RSA, 1024, rand.Reader)
priv, pub, err := ci.GenerateKeyPairWithReader(ci.RSA, 2048, rand.Reader)
if err != nil {
return nil, err
}
Expand Down
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,30 @@ require (
github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2
github.com/jbenet/goprocess v0.1.3
github.com/libp2p/go-eventbus v0.0.3 // indirect
github.com/libp2p/go-libp2p v0.2.0
github.com/libp2p/go-libp2p v0.3.0
github.com/libp2p/go-libp2p-autonat-svc v0.1.0
github.com/libp2p/go-libp2p-circuit v0.1.0
github.com/libp2p/go-libp2p-circuit v0.1.1
github.com/libp2p/go-libp2p-connmgr v0.1.0
github.com/libp2p/go-libp2p-core v0.0.6
github.com/libp2p/go-libp2p-core v0.2.0
github.com/libp2p/go-libp2p-http v0.1.2
github.com/libp2p/go-libp2p-kad-dht v0.1.1
github.com/libp2p/go-libp2p-kad-dht v0.2.0
github.com/libp2p/go-libp2p-kbucket v0.2.0
github.com/libp2p/go-libp2p-loggables v0.1.0
github.com/libp2p/go-libp2p-mplex v0.2.1
github.com/libp2p/go-libp2p-peerstore v0.1.2-0.20190621130618-cfa9bb890c1a
github.com/libp2p/go-libp2p-peerstore v0.1.3
github.com/libp2p/go-libp2p-pnet v0.1.0
github.com/libp2p/go-libp2p-pubsub v0.1.0
github.com/libp2p/go-libp2p-pubsub-router v0.1.0
github.com/libp2p/go-libp2p-quic-transport v0.1.1
github.com/libp2p/go-libp2p-record v0.1.0
github.com/libp2p/go-libp2p-record v0.1.1
github.com/libp2p/go-libp2p-routing-helpers v0.1.0
github.com/libp2p/go-libp2p-secio v0.1.0
github.com/libp2p/go-libp2p-swarm v0.1.1
github.com/libp2p/go-libp2p-testing v0.0.4
github.com/libp2p/go-libp2p-secio v0.2.0
github.com/libp2p/go-libp2p-swarm v0.2.0
github.com/libp2p/go-libp2p-testing v0.1.0
github.com/libp2p/go-libp2p-tls v0.1.0
github.com/libp2p/go-libp2p-yamux v0.2.1
github.com/libp2p/go-maddr-filter v0.0.5
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mr-tron/base58 v1.1.2
github.com/multiformats/go-multiaddr v0.0.4
Expand Down
46 changes: 28 additions & 18 deletions go.sum

Large diffs are not rendered by default.

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 @@ -84,7 +84,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 048cdc0

Please sign in to comment.