Skip to content

Commit 37f4857

Browse files
cong-oraschmahmann
authored andcommitted
feat support non-ICANN DNS
This commit was moved from ipfs/kubo@24dd662
1 parent c5b259e commit 37f4857

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

gateway/core/corehttp/hostname.go

Lines changed: 6 additions & 3 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"
@@ -351,9 +352,11 @@ func knownSubdomainDetails(hostname string, knownGateways gatewayHosts) (gw *con
351352
// isDNSLinkName returns bool if a valid DNS TXT record exist for provided host
352353
func isDNSLinkName(ctx context.Context, ipfs iface.CoreAPI, host string) bool {
353354
fqdn := stripPort(host)
354-
if len(fqdn) == 0 && !isd.IsDomain(fqdn) {
355+
356+
if _, ok := dns.IsDomainName(fqdn); !ok && len(fqdn) == 0 {
355357
return false
356358
}
359+
357360
name := "/ipns/" + fqdn
358361
// check if DNSLink exists
359362
depth := options.Name.ResolveOption(nsopts.Depth(1))
@@ -473,7 +476,7 @@ func toSubdomainURL(hostname, path string, r *http.Request, ipfs iface.CoreAPI)
473476
}
474477

475478
// Normalize problematic PeerIDs (eg. ed25519+identity) to CID representation
476-
if isPeerIDNamespace(ns) && !isd.IsDomain(rootID) {
479+
if _, ok := dns.IsDomainName(rootID); !ok && isPeerIDNamespace(ns) {
477480
peerID, err := peer.Decode(rootID)
478481
// Note: PeerID CIDv1 with protobuf multicodec will fail, but we fix it
479482
// in the next block

gateway/core/corehttp/hostname_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestToSubdomainURL(t *testing.T) {
5555
{httpRequest, "localhost", "/ipns/QmY3hE8xgFCjGcz6PHgnvJz5HZi1BaKRfPkn1ghZUcYMjD", "http://k2k4r8n0flx3ra0y5dr8fmyvwbzy3eiztmtq6th694k5a3rznayp3e4o.ipns.localhost/", nil},
5656
{httpRequest, "localhost", "/ipns/bafybeickencdqw37dpz3ha36ewrh4undfjt2do52chtcky4rxkj447qhdm", "http://k2k4r8l9ja7hkzynavdqup76ou46tnvuaqegbd04a4o1mpbsey0meucb.ipns.localhost/", nil},
5757
// PeerID: ed25519+identity multihash → CIDv1Base36
58-
{httpRequest, "localhost", "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", "http://k51qzi5uqu5di608geewp3nqkg0bpujoasmka7ftkyxgcm3fh1aroup0gsdrna.ipns.localhost/", nil},
58+
{httpRequest, "localhost", "/ipns/12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5", "http://12D3KooWFB51PRY9BxcXSH6khFXw1BZeszeLDy7C8GciskqCTZn5.ipns.localhost/", nil},
5959
{httpRequest, "sub.localhost", "/ipfs/QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n", "http://bafybeif7a7gdklt6hodwdrmwmxnhksctcuav6lfxlcyfz4khzl3qfmvcgu.ipfs.sub.localhost/", nil},
6060
// HTTPS requires DNSLink name to fit in a single DNS label – see "Option C" from https://github.com/ipfs/in-web-browsers/issues/169
6161
{httpRequest, "dweb.link", "/ipns/dnslink.long-name.example.com", "http://dnslink.long-name.example.com.ipns.dweb.link/", nil},

0 commit comments

Comments
 (0)