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

adds findDOHEndpoint() for given zone to JS API #45

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions golang/sig0/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func FindDOHEndpoint(name string) (*url.URL, error) {
return nil, fmt.Errorf("findDOHEndpoint: no answer section for %s", lookup)
}

// TODO deal with more than one SVCB "_dns." + name in RRSet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call!

we should start making a list of things we need static test vectors for to drop our need for network i/o during tests and this would definitely be one of them.

first := answer.Answer[0]
svcb, ok := first.(*dns.SVCB)
if !ok {
Expand Down
27 changes: 27 additions & 0 deletions golang/wasm/pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,30 @@ function getKeysForDomain() {

return
}

// findDOHEndpoint()
// for a given domain, find DOH Endpoint URL for update returned as string
//
async function findDOHEndpoint() {
var dohDomain = document.getElementById("doh-for-domain").value
if (! dohDomain.endsWith('.')) {
dohDomain = dohDomain + '.'
}

const div = document.getElementById("domain-doh-endpoint")
if (div.children.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if it is possible to have more then one but instead of removing the first you can also just div.innerHTML = "", i think.

div.removeChild(div.children[0])
}

const ul = document.createElement("ul")

const dohEndpoint = window.goFuncs.findDOHEndpoint
k = await dohEndpoint(dohDomain)
const li = document.createElement("li")
li.innerHTML = k
ul.appendChild(li)

div.appendChild(ul)

return
}
6 changes: 6 additions & 0 deletions golang/wasm/wasm_exec.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ <h3>Search Keystore for Key to sign update for a given Subdomain</h3>
<button onclick="getKeysForDomain()">Find key in keystore</button>
<div id="domain-key"></div>
</p>
<h3>Find DOH Endpoint for a given Subdomain</h3>
<p>
<input type="text" id="doh-for-domain" placeholder="mythingymajig.zenr.io">
<button onclick="findDOHEndpoint()">Find DOH endpoint</button>
<div id="domain-doh-endpoint"></div>
</p>
<h3>Import Key pair files from filesystem into Browser Keystore</h3>
<p>
<input type="file" id="input-key" accept=".key"/>
Expand Down
29 changes: 29 additions & 0 deletions golang/wasm/wrapper_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func main() {
goFuncs.Set("newKeyRequest", js.FuncOf(newKeyRequest))
goFuncs.Set("newUpdater", js.FuncOf(newUpdater))
goFuncs.Set("checkKeyStatus", js.FuncOf(checkKeyStatus))
goFuncs.Set("findDOHEndpoint", js.FuncOf(findDOHEndpoint))

// cant let main return
forever := make(chan bool)
Expand Down Expand Up @@ -208,6 +209,34 @@ func checkKeyStatus(_ js.Value, args []js.Value) any {
return promiseConstructor.New(handler)
}

func findDOHEndpoint(_ js.Value, args []js.Value) any {
if len(args) != 1 {
return "expected 1 argument: domainName"
adam-burns marked this conversation as resolved.
Show resolved Hide resolved
}
dohDomain := args[0].String()

handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
resolve := args[0]
reject := args[1]

go func() {
// Note sig0.FindDOHEnpoint returns single cooked value from first SVCB RR resolved
dohUrl, err := sig0.FindDOHEndpoint(dohDomain)
if err != nil {
reject.Invoke(jsErr(err))
return
}
resolve.Invoke(dohUrl.String())
}()

return nil
})

promiseConstructor := js.Global().Get("Promise")
return promiseConstructor.New(handler)

}

// create a keypair and request a key
// arguments: the name to request
// returns nill or an error string
Expand Down
Loading