Skip to content

Apparently simple program fails to behave like native #262

Closed
@FiloSottile

Description

@FiloSottile

Here's a small program

package main

import (
    "fmt"
    "log"
    "strings"

    "github.com/cloudflare/dns"
    "github.com/gopherjs/gopherjs/js"
)

func main() {
    js.Global.Set("go", map[string]interface{}{
        "ToDS": ToDS,
    })
}

func ToDS(zone string) {
    go func() {
        zone := "filippo.io.\t3600\tIN\tDNSKEY\t257 3 13 DGpDkudNu/XQT1KmQkXFtKCfZPxHGV07qSTIcDXS33/WtT8UUG7LyxAgKznsRSFEhiQVR53E69/E57IFm8b6Zw=="

        r := strings.NewReader(zone)
        for {
            rr, err := dns.ReadRR(r, "")
            if err != nil {
                log.Println(err)
                continue
            }
            if rr == nil {
                break
            }

            dnskey, ok := rr.(*dns.DNSKEY)
            if !ok {
                log.Println("Not a DNSKEY:", rr)
                continue
            }

            if dnskey.Flags&dns.SEP == 0 {
                // ZSK
                continue
            }

            ds1 := dnskey.ToDS(dns.SHA1)
            ds2 := dnskey.ToDS(dns.SHA256)

            js.Global.Get("document").Call("write", fmt.Sprintf("%s\n%s\n", ds1, ds2))
        }
    }()
}

I compile it with default options and load it in a empty page, and then from the console:

> go.ToDS("")
< undefined
syscall.go:44 2015/07/21 01:32:52 dns: not a TTL: "DGpDkudNu/XQT1KmQkXFtKCfZPxHGV07qSTIcDXS33/WtT8UUG7LyxAgKznsRSFEhiQVR53E69/E57IFm8b6Zw==" at line: 1:124

The parser fails in some weird way. Different inputs fail in different ways.

Here's a equivalent program, that I run with go run

package main

import (
    "fmt"
    "log"
    "strings"

    "github.com/cloudflare/dns"
)

func main() {
    zone := "filippo.io.\t3600\tIN\tDNSKEY\t257 3 13 DGpDkudNu/XQT1KmQkXFtKCfZPxHGV07qSTIcDXS33/WtT8UUG7LyxAgKznsRSFEhiQVR53E69/E57IFm8b6Zw=="

    r := strings.NewReader(zone)
    for {
        rr, err := dns.ReadRR(r, "")
        if err != nil {
            log.Println(err)
            continue
        }
        if rr == nil {
            break
        }

        dnskey, ok := rr.(*dns.DNSKEY)
        if !ok {
            log.Println("Not a DNSKEY:", rr)
            continue
        }

        if dnskey.Flags&dns.SEP == 0 {
            // ZSK
            continue
        }

        ds1 := dnskey.ToDS(dns.SHA1)
        ds2 := dnskey.ToDS(dns.SHA256)

        println(fmt.Sprintf("%s\n%s\n", ds1, ds2))
    }
}
$ go run src/dnskey-to-ds/test.go
filippo.io. 3600    IN  DS  42 13 1 6D68D297C0AF610513996154BDDDEDA300831957
filippo.io. 3600    IN  DS  42 13 2 2DDD9653A96320688619B6F0EBACEC1A2F4DEBA8D563A6D37C64FB3197C108A7

First time gopherjs user, so I might be missing something, but it looks like a bug in the channel usage of dns.ReadRR (source)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions