Skip to content

Commit afa9899

Browse files
authored
Merge pull request #8071 from mycorrhizas/feat/non-icann-dns
feat: support DNSLink on non-ICANN DNS names
2 parents a61fa0d + 28d4d9b commit afa9899

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

core/corehttp/hostname.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import (
1313
core "github.com/ipfs/go-ipfs/core"
1414
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
1515
namesys "github.com/ipfs/go-namesys"
16-
isd "github.com/jbenet/go-is-domain"
1716
"github.com/libp2p/go-libp2p-core/peer"
17+
dns "github.com/miekg/dns"
18+
1819
mbase "github.com/multiformats/go-multibase"
1920

2021
config "github.com/ipfs/go-ipfs-config"
@@ -348,13 +349,27 @@ func knownSubdomainDetails(hostname string, knownGateways gatewayHosts) (gw *con
348349
return nil, "", "", "", false
349350
}
350351

352+
// isDomainNameAndNotPeerID returns bool if string looks like a valid DNS name AND is not a PeerID
353+
func isDomainNameAndNotPeerID(hostname string) bool {
354+
if len(hostname) == 0 {
355+
return false
356+
}
357+
if _, err := peer.Decode(hostname); err == nil {
358+
return false
359+
}
360+
_, ok := dns.IsDomainName(hostname)
361+
return ok
362+
}
363+
351364
// isDNSLinkName returns bool if a valid DNS TXT record exist for provided host
352365
func isDNSLinkName(ctx context.Context, ipfs iface.CoreAPI, host string) bool {
353-
fqdn := stripPort(host)
354-
if len(fqdn) == 0 && !isd.IsDomain(fqdn) {
366+
dnslinkName := stripPort(host)
367+
368+
if !isDomainNameAndNotPeerID(dnslinkName) {
355369
return false
356370
}
357-
name := "/ipns/" + fqdn
371+
372+
name := "/ipns/" + dnslinkName
358373
// check if DNSLink exists
359374
depth := options.Name.ResolveOption(nsopts.Depth(1))
360375
_, err := ipfs.Name().Resolve(ctx, name, depth)
@@ -473,7 +488,7 @@ func toSubdomainURL(hostname, path string, r *http.Request, ipfs iface.CoreAPI)
473488
}
474489

475490
// Normalize problematic PeerIDs (eg. ed25519+identity) to CID representation
476-
if isPeerIDNamespace(ns) && !isd.IsDomain(rootID) {
491+
if isPeerIDNamespace(ns) && !isDomainNameAndNotPeerID(rootID) {
477492
peerID, err := peer.Decode(rootID)
478493
// Note: PeerID CIDv1 with protobuf multicodec will fail, but we fix it
479494
// in the next block

core/corehttp/hostname_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,25 @@ func TestHasPrefix(t *testing.T) {
144144
}
145145
}
146146

147+
func TestIsDomainNameAndNotPeerID(t *testing.T) {
148+
for _, test := range []struct {
149+
hostname string
150+
out bool
151+
}{
152+
{"", false},
153+
{"example.com", true},
154+
{"non-icann.something", true},
155+
{"..", false},
156+
{"12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", false}, // valid peerid
157+
{"k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna", false}, // valid peerid
158+
} {
159+
out := isDomainNameAndNotPeerID(test.hostname)
160+
if out != test.out {
161+
t.Errorf("(%s) returned '%t', expected '%t'", test.hostname, out, test.out)
162+
}
163+
}
164+
}
165+
147166
func TestPortStripping(t *testing.T) {
148167
for _, test := range []struct {
149168
in string

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ require (
5555
github.com/ipfs/go-verifcid v0.0.1
5656
github.com/ipfs/interface-go-ipfs-core v0.4.0
5757
github.com/ipld/go-car v0.3.0
58-
github.com/jbenet/go-is-domain v1.0.5
5958
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
6059
github.com/jbenet/go-temp-err-catcher v0.1.0
6160
github.com/jbenet/goprocess v0.1.4

go.sum

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,6 @@ github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+
518518
github.com/jbenet/go-cienv v0.0.0-20150120210510-1bb1476777ec/go.mod h1:rGaEvXB4uRSZMmzKNLoXvTu1sfx+1kv/DojUlPrSZGs=
519519
github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc=
520520
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
521-
github.com/jbenet/go-is-domain v1.0.5 h1:r92uiHbMEJo9Fkey5pMBtZAzjPQWic0ieo7Jw1jEuQQ=
522-
github.com/jbenet/go-is-domain v1.0.5/go.mod h1:xbRLRb0S7FgzDBTJlguhDVwLYM/5yNtvktxj2Ttfy7Q=
523521
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c h1:uUx61FiAa1GI6ZmVd2wf2vULeQZIKG66eybjNXKYCz4=
524522
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c/go.mod h1:sdx1xVM9UuLw1tXnhJWN3piypTUO3vCIHYmG15KE/dU=
525523
github.com/jbenet/go-temp-err-catcher v0.0.0-20150120210811-aac704a3f4f2/go.mod h1:8GXXJV31xl8whumTzdZsTt3RnUIiPqzkyf7mxToRCMs=
@@ -916,8 +914,6 @@ github.com/miekg/dns v1.1.12/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3N
916914
github.com/miekg/dns v1.1.28/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
917915
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
918916
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
919-
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
920-
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
921917
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
922918
github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c h1:bzE/A84HN25pxAuk9Eej1Kz9OUelF97nAc82bDquQI8=
923919
github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c/go.mod h1:0SQS9kMwD2VsyFEB++InYyBJroV/FRmBgcydeSUcJms=
@@ -1470,6 +1466,7 @@ golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7w
14701466
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14711467
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14721468
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1469+
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14731470
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14741471
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
14751472
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

0 commit comments

Comments
 (0)