From 37f4857a4d05b88a4241078f48301bc0b92ae921 Mon Sep 17 00:00:00 2001 From: divingpetrel Date: Tue, 13 Apr 2021 16:53:22 +0100 Subject: [PATCH] feat support non-ICANN DNS This commit was moved from ipfs/kubo@24dd662d381cb60502a996e5be23e1bfd0c51a87 --- gateway/core/corehttp/hostname.go | 9 ++++++--- gateway/core/corehttp/hostname_test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gateway/core/corehttp/hostname.go b/gateway/core/corehttp/hostname.go index 6740f0e59..b6246e281 100644 --- a/gateway/core/corehttp/hostname.go +++ b/gateway/core/corehttp/hostname.go @@ -13,8 +13,9 @@ import ( core "github.com/ipfs/go-ipfs/core" coreapi "github.com/ipfs/go-ipfs/core/coreapi" namesys "github.com/ipfs/go-namesys" - isd "github.com/jbenet/go-is-domain" "github.com/libp2p/go-libp2p-core/peer" + dns "github.com/miekg/dns" + mbase "github.com/multiformats/go-multibase" config "github.com/ipfs/go-ipfs-config" @@ -351,9 +352,11 @@ func knownSubdomainDetails(hostname string, knownGateways gatewayHosts) (gw *con // isDNSLinkName returns bool if a valid DNS TXT record exist for provided host func isDNSLinkName(ctx context.Context, ipfs iface.CoreAPI, host string) bool { fqdn := stripPort(host) - if len(fqdn) == 0 && !isd.IsDomain(fqdn) { + + if _, ok := dns.IsDomainName(fqdn); !ok && len(fqdn) == 0 { return false } + name := "/ipns/" + fqdn // check if DNSLink exists depth := options.Name.ResolveOption(nsopts.Depth(1)) @@ -473,7 +476,7 @@ func toSubdomainURL(hostname, path string, r *http.Request, ipfs iface.CoreAPI) } // Normalize problematic PeerIDs (eg. ed25519+identity) to CID representation - if isPeerIDNamespace(ns) && !isd.IsDomain(rootID) { + if _, ok := dns.IsDomainName(rootID); !ok && isPeerIDNamespace(ns) { peerID, err := peer.Decode(rootID) // Note: PeerID CIDv1 with protobuf multicodec will fail, but we fix it // in the next block diff --git a/gateway/core/corehttp/hostname_test.go b/gateway/core/corehttp/hostname_test.go index 3ece5e88f..9bee6768a 100644 --- a/gateway/core/corehttp/hostname_test.go +++ b/gateway/core/corehttp/hostname_test.go @@ -55,7 +55,7 @@ func TestToSubdomainURL(t *testing.T) { {httpRequest, "localhost", "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", "http://k2k4r8n0flx3ra0y5dr8fmyvwbzy3eiztmtq6th694k5a3rznayp3e4o.ipns.localhost/", nil}, {httpRequest, "localhost", "/ipns/bafybeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm", "http://k2k4r8l9ja7hkzynavdqup76ou46tnvuaqegbd04a4o1mpbsey0meucb.ipns.localhost/", nil}, // PeerID: ed25519+identity multihash → CIDv1Base36 - {httpRequest, "localhost", "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", "http://k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna.ipns.localhost/", nil}, + {httpRequest, "localhost", "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", "http://12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5.ipns.localhost/", nil}, {httpRequest, "sub.localhost", "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.sub.localhost/", nil}, // HTTPS requires DNSLink name to fit in a single DNS label – see "Option C" from https://github.com/ipfs/in-web-browsers/issues/169 {httpRequest, "dweb.link", "/ipns/dnslink.long-name.example.com", "http://dnslink.long-name.example.com.ipns.dweb.link/", nil},