Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only perform DNSLink lookups on fully qualified domain names (FQDN) #5950

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions namesys/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type lookupRes struct {
// TXT records for a given domain name should contain a b58
// encoded multihash.
func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options opts.ResolveOpts) <-chan onceResult {
var fqdn string
out := make(chan onceResult, 1)
segments := strings.SplitN(name, "/", 2)
domain := segments[0]
Expand All @@ -56,11 +57,17 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
}
log.Debugf("DNSResolver resolving %s", domain)

if strings.HasSuffix(domain, ".") {
fqdn = domain
} else {
fqdn = domain + "."
}

rootChan := make(chan lookupRes, 1)
go workDomain(r, domain, rootChan)
go workDomain(r, fqdn, rootChan)

subChan := make(chan lookupRes, 1)
go workDomain(r, "_dnslink."+domain, subChan)
go workDomain(r, "_dnslink."+fqdn, subChan)

appendPath := func(p path.Path) (path.Path, error) {
if len(segments) > 1 {
Expand Down
44 changes: 24 additions & 20 deletions namesys/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,68 +61,71 @@ func TestDnsEntryParsing(t *testing.T) {
func newMockDNS() *mockDNS {
return &mockDNS{
entries: map[string][]string{
"multihash.example.com": []string{
"multihash.example.com.": []string{
"dnslink=QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"ipfs.example.com": []string{
"ipfs.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"_dnslink.dipfs.example.com": []string{
"_dnslink.dipfs.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"dns1.example.com": []string{
"dns1.example.com.": []string{
"dnslink=/ipns/ipfs.example.com",
},
"dns2.example.com": []string{
"dns2.example.com.": []string{
"dnslink=/ipns/dns1.example.com",
},
"multi.example.com": []string{
"multi.example.com.": []string{
"some stuff",
"dnslink=/ipns/dns1.example.com",
"masked dnslink=/ipns/example.invalid",
},
"equals.example.com": []string{
"equals.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/=equals",
},
"loop1.example.com": []string{
"loop1.example.com.": []string{
"dnslink=/ipns/loop2.example.com",
},
"loop2.example.com": []string{
"loop2.example.com.": []string{
"dnslink=/ipns/loop1.example.com",
},
"_dnslink.dloop1.example.com": []string{
"_dnslink.dloop1.example.com.": []string{
"dnslink=/ipns/loop2.example.com",
},
"_dnslink.dloop2.example.com": []string{
"_dnslink.dloop2.example.com.": []string{
"dnslink=/ipns/loop1.example.com",
},
"bad.example.com": []string{
"bad.example.com.": []string{
"dnslink=",
},
"withsegment.example.com": []string{
"withsegment.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment",
},
"withrecsegment.example.com": []string{
"withrecsegment.example.com.": []string{
"dnslink=/ipns/withsegment.example.com/subsub",
},
"withtrailing.example.com": []string{
"withtrailing.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/",
},
"withtrailingrec.example.com": []string{
"withtrailingrec.example.com.": []string{
"dnslink=/ipns/withtrailing.example.com/segment/",
},
"double.example.com": []string{
"double.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"_dnslink.double.example.com": []string{
"_dnslink.double.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"double.conflict.com": []string{
"double.conflict.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD",
},
"_dnslink.conflict.example.com": []string{
"_dnslink.conflict.example.com.": []string{
"dnslink=/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjE",
},
"fqdn.example.com.": []string{
"dnslink=/ipfs/QmYvMB9yrsSf7RKBghkfwmHJkzJhW2ZgVwq3LxBXXPasFr",
},
},
}
}
Expand Down Expand Up @@ -159,4 +162,5 @@ func TestDNSResolution(t *testing.T) {
testResolution(t, r, "withtrailingrec.example.com", opts.DefaultDepthLimit, "/ipfs/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD/sub/segment/", nil)
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)
}