From d5f22c2ca40c612a0c34642fa54f8c3025609f6c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 7 Oct 2019 17:07:31 +0900 Subject: [PATCH 1/3] fix(resolve): correctly handle .eth domains This should have been handled down inside the DNSLink resolver. Otherwise, we'll break any name happens to end in `.eth`. also fixes #6699 --- go.mod | 2 +- go.sum | 4 ++-- namesys/dns.go | 9 +++++++++ namesys/namesys.go | 8 -------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 636c62adc..cb0cbb92b 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,7 @@ require ( github.com/ipfs/go-unixfs v0.2.1 github.com/ipfs/go-verifcid v0.0.1 github.com/ipfs/interface-go-ipfs-core v0.2.3 - github.com/jbenet/go-is-domain v1.0.2 + github.com/jbenet/go-is-domain v1.0.3 github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2 github.com/jbenet/goprocess v0.1.3 diff --git a/go.sum b/go.sum index c999c92f0..95d3d260f 100644 --- a/go.sum +++ b/go.sum @@ -261,8 +261,8 @@ github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+ github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs= github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= -github.com/jbenet/go-is-domain v1.0.2 h1:11r5MSptcNFZyBoqubBQnVMUKRWLuRjL1banaIk+iYo= -github.com/jbenet/go-is-domain v1.0.2/go.mod h1:xbRLRb0S7FgzDBTJlguhDVwLYM/5yNtvktxj2Ttfy7Q= +github.com/jbenet/go-is-domain v1.0.3 h1:FuRBJ0h79p00eseyaLckJT5KnE8RyqI+HLopvNSyNE0= +github.com/jbenet/go-is-domain v1.0.3/go.mod h1:xbRLRb0S7FgzDBTJlguhDVwLYM/5yNtvktxj2Ttfy7Q= github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c h1:uUx61FiAa1GI6ZmVd2wf2vULeQZIKG66eybjNXKYCz4= github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c/go.mod h1:sdx1xVM9UuLw1tXnhJWN3piypTUO3vCIHYmG15KE/dU= github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2 h1:vhC1OXXiT9R2pczegwz6moDvuRpggaroAXhPIseh57A= diff --git a/namesys/dns.go b/namesys/dns.go index 931edec00..984a27aa8 100644 --- a/namesys/dns.go +++ b/namesys/dns.go @@ -11,6 +11,9 @@ import ( isd "github.com/jbenet/go-is-domain" ) +const ethTLD = "eth" +const linkTLD = "link" + type LookupTXTFunc func(name string) (txt []string, err error) // DNSResolver implements a Resolver on DNS domains @@ -62,6 +65,12 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options fqdn = domain + "." } + if strings.HasSuffix(fqdn, "."+ethTLD+".") { + // This is an ENS name. As we're resolving via an arbitrary DNS server + // that may not know about .eth we need to add our link domain suffix. + fqdn += linkTLD + "." + } + rootChan := make(chan lookupRes, 1) go workDomain(r, fqdn, rootChan) diff --git a/namesys/namesys.go b/namesys/namesys.go index 0646fef7b..7ae93e3e2 100644 --- a/namesys/namesys.go +++ b/namesys/namesys.go @@ -80,9 +80,6 @@ func (ns *mpns) ResolveAsync(ctx context.Context, name string, options ...opts.R return resolveAsync(ctx, ns, name, opts.ProcessOpts(options)) } -const ethTLD = ".eth" -const linkTLD = ".link" - // resolveOnce implements resolver. func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.ResolveOpts) <-chan onceResult { out := make(chan onceResult, 1) @@ -90,11 +87,6 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts. if !strings.HasPrefix(name, ipnsPrefix) { name = ipnsPrefix + name } - if strings.HasSuffix(name, ethTLD) { - // This is an ENS name. As we're resolving via an arbitrary DNS server - // that may not know about .eth we need to add our link domain suffix. - name = name + linkTLD - } segments := strings.SplitN(name, "/", 4) if len(segments) < 3 || segments[0] != "" { log.Debugf("invalid name syntax for %s", name) From 1ead3c8fd24dda7226e2830598dde59bf7ab964a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 7 Oct 2019 17:33:38 +0900 Subject: [PATCH 2/3] test(namesys): remove broken test --- namesys/namesys_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/namesys/namesys_test.go b/namesys/namesys_test.go index 524037dcf..a0ffbc50d 100644 --- a/namesys/namesys_test.go +++ b/namesys/namesys_test.go @@ -60,8 +60,7 @@ func mockResolverOne() *mockResolver { func mockResolverTwo() *mockResolver { return &mockResolver{ entries: map[string]string{ - "ipfs.io": "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", - "www.wealdtech.eth.link": "/ipns/QmQ4QZh8nrsczdUEwTyfBope4THUhqxqc1fx6qYhhzZQei", + "ipfs.io": "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", }, } } @@ -83,8 +82,6 @@ func TestNamesysResolution(t *testing.T) { testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 1, "/ipns/ipfs.io", ErrResolveRecursion) testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 2, "/ipns/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", ErrResolveRecursion) testResolution(t, r, "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", 3, "/ipns/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy", ErrResolveRecursion) - testResolution(t, r, "/ipns/www.wealdtech.eth", 1, "/ipns/QmQ4QZh8nrsczdUEwTyfBope4THUhqxqc1fx6qYhhzZQei", ErrResolveRecursion) - testResolution(t, r, "/ipns/www.wealdtech.eth", 2, "/ipfs/QmP3ouCnU8NNLsW6261pAx2pNLV2E4dQoisB1sgda12Act", nil) } func TestPublishWithCache0(t *testing.T) { From 554155f609c83b2b1270a0437292625d999bcc68 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 7 Oct 2019 22:23:35 +0900 Subject: [PATCH 3/3] test(namesys): add fixed eth.link test --- namesys/dns_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/namesys/dns_test.go b/namesys/dns_test.go index 8d53887be..653c3c788 100644 --- a/namesys/dns_test.go +++ b/namesys/dns_test.go @@ -126,6 +126,9 @@ func newMockDNS() *mockDNS { "fqdn.example.com.": []string{ "dnslink=/ipfs/QmYvMB9yrsSf7RKBghkfwmHJkzJhW2ZgVwq3LxBXXPasFr", }, + "www.wealdtech.eth.link.": []string{ + "dnslink=/ipns/ipfs.example.com", + }, }, } } @@ -163,4 +166,7 @@ func TestDNSResolution(t *testing.T) { testResolution(t, r, "double.example.com", opts.DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", nil) testResolution(t, r, "conflict.example.com", opts.DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjE", nil) testResolution(t, r, "fqdn.example.com.", opts.DefaultDepthLimit, "/ipfs/QmYvMB9yrsSf7RKBghkfwmHJkzJhW2ZgVwq3LxBXXPasFr", nil) + testResolution(t, r, "www.wealdtech.eth", 1, "/ipns/ipfs.example.com", ErrResolveRecursion) + testResolution(t, r, "www.wealdtech.eth", 2, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", nil) + testResolution(t, r, "www.wealdtech.eth.link", 2, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", nil) }