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

Treat Namecoin to non-Namecoin CNAME as insecure #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions ncdomain/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ func (v *Value) appendAlias(out []dns.RR, suffix, apexSuffix string) ([]dns.RR,
if !ok {
return out, fmt.Errorf("bad alias")
}

qn, err := redirectInsecure(qn, suffix, apexSuffix)
if err != nil {
return out, err
}

out = append(out, &dns.CNAME{
Hdr: dns.RR_Header{
Name: suffix,
Expand All @@ -279,6 +285,12 @@ func (v *Value) appendTranslate(out []dns.RR, suffix, apexSuffix string) ([]dns.
if !ok {
return out, fmt.Errorf("bad translate")
}

qn, err := redirectInsecure(qn, suffix, apexSuffix)
if err != nil {
return out, err
}

out = append(out, &dns.DNAME{
Hdr: dns.RR_Header{
Name: suffix,
Expand All @@ -293,6 +305,43 @@ func (v *Value) appendTranslate(out []dns.RR, suffix, apexSuffix string) ([]dns.
return out, nil
}

func redirectInsecure(qn, suffix, apexSuffix string) (string, error) {
subInput, baseInput, rootInput, err := util.SplitDomainByFloatingAnchor(suffix, "bit")
if err != nil {
return "", err
}

_, _, rootOutput, errOutput := util.SplitDomainByFloatingAnchor(qn, "bit")

// CNAME/DNAME from Namecoin to non-Namecoin isn't secure since it would trust the ICANN root.
insecureAllowed := strings.Contains(apexSuffix + ".", ".bit._insecure_bit.")
isSecure := (errOutput == nil) && (rootInput == rootOutput)

if ! insecureAllowed && ! isSecure {
// redirect to the insecure equivalent

// "a.b.c.d.bit.x.y.z." -> subInput="a.b.c", baseInput="d", rootInput="bit.x.y.z"

bit, afterBit := util.SplitDomainTail(rootInput)
// "a.b.c.d.bit.x.y.z." -> bit="bit", afterBit="x.y.z"

insecure := bit + "." + "_insecure_bit" + "."
if afterBit != "" {
insecure = insecure + afterBit + "."
}
if baseInput != "" {
insecure = baseInput + "." + insecure
}
if subInput != "" {
insecure = subInput + "." + insecure
}

return insecure, nil
}

return qn, nil
}

func (v *Value) RRsRecursive(out []dns.RR, suffix, apexSuffix string) ([]dns.RR, error) {
out, err := v.RRs(out, suffix, apexSuffix)
if err != nil {
Expand Down