Skip to content

Commit

Permalink
feat: support non-ICANN DNSLink
Browse files Browse the repository at this point in the history
- removes reliance on TLD safelist from jbenet/go-is-domain
  as noted in
  jbenet/go-is-domain#16 (comment)
  jbenet/go-is-domain#19 (review)

- switch DNSLink checks to `net.isDomainName` which only cares about
  name being compliant with RFC 1035, RFC 3696, and is not concerned
  if TLD was blessed by ICANN or some other authority
  • Loading branch information
lidel committed Feb 5, 2021
1 parent 884a5ae commit b383895
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
13 changes: 6 additions & 7 deletions core/corehttp/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
core "github.com/ipfs/go-ipfs/core"
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
namesys "github.com/ipfs/go-ipfs/namesys"
isd "github.com/jbenet/go-is-domain"
"github.com/libp2p/go-libp2p-core/peer"
mbase "github.com/multiformats/go-multibase"

Expand Down Expand Up @@ -368,7 +367,7 @@ 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 len(fqdn) == 0 && !net.isDomainName(fqdn) {
return false
}
name := "/ipns/" + fqdn
Expand Down Expand Up @@ -490,11 +489,11 @@ 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) {
peerID, err := peer.Decode(rootID)
// Note: PeerID CIDv1 with protobuf multicodec will fail, but we fix it
// in the next block
if err == nil {
if isPeerIDNamespace(ns) {
// could be a CID or DNSLink name, so we check if it is a CID
if peerID, err := peer.Decode(rootID); err == nil {
// Note: PeerID CIDv1 with protobuf multicodec will fail, but we fix it
// in the next block
rootID = peer.ToCid(peerID).String()
}
}
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ require (
github.com/ipfs/go-verifcid v0.0.1
github.com/ipfs/interface-go-ipfs-core v0.4.0
github.com/ipld/go-car v0.1.1-0.20201015032735-ff6ccdc46acc
github.com/jbenet/go-is-domain v1.0.5
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
github.com/jbenet/go-temp-err-catcher v0.1.0
github.com/jbenet/goprocess v0.1.4
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,6 @@ github.com/jackpal/go-nat-pmp v1.0.2/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.5 h1:r92uiHbMEJo9Fkey5pMBtZAzjPQWic0ieo7Jw1jEuQQ=
github.com/jbenet/go-is-domain v1.0.5/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/go.mod h1:8GXXJV31xl8whumTzdZsTt3RnUIiPqzkyf7mxToRCMs=
Expand Down
5 changes: 2 additions & 3 deletions namesys/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package namesys
import (
"context"
"errors"
"fmt"
"net"
"strings"
"fmt"

path "github.com/ipfs/go-path"
opts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
isd "github.com/jbenet/go-is-domain"
)

const ethTLD = "eth"
Expand Down Expand Up @@ -53,7 +52,7 @@ func (r *DNSResolver) resolveOnceAsync(ctx context.Context, name string, options
segments := strings.SplitN(name, "/", 2)
domain := segments[0]

if !isd.IsDomain(domain) {
if !net.isDomainName(domain) {
out <- onceResult{err: fmt.Errorf("not a valid domain name: %s", domain)}
close(out)
return out
Expand Down
4 changes: 2 additions & 2 deletions namesys/namesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package namesys
import (
"context"
"fmt"
"net"
"os"
"strings"
"time"
Expand All @@ -12,7 +13,6 @@ import (
ds "github.com/ipfs/go-datastore"
path "github.com/ipfs/go-path"
opts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
isd "github.com/jbenet/go-is-domain"
ci "github.com/libp2p/go-libp2p-core/crypto"
peer "github.com/libp2p/go-libp2p-core/peer"
routing "github.com/libp2p/go-libp2p-core/routing"
Expand Down Expand Up @@ -162,7 +162,7 @@ func (ns *mpns) resolveOnceAsync(ctx context.Context, name string, options opts.

if err == nil {
res = ns.ipnsResolver
} else if isd.IsDomain(key) {
} else if net.isDomainName(key) {
res = ns.dnsResolver
} else {
res = ns.proquintResolver
Expand Down

0 comments on commit b383895

Please sign in to comment.