aboutsummaryrefslogtreecommitdiff
path: root/cmd/tmp/dns/main.go
blob: 2b19770eb56c26bdde61d8412b87491f9d397e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main

import (
	"context"
	"flag"
	"fmt"
	"log"

	"git.sigsum.org/sigsum-go/pkg/hex"
	"git.sigsum.org/sigsum-go/pkg/types"
	"git.sigsum.org/sigsum-log-go/pkg/dns"
)

var (
	vk          = flag.String("vk", "5aed7ffc3bc088221f6579567b2e6e3c4ac3579bd5e77670755179052c68d5d3", "verification key (hex)")
	domain_hint = flag.String("domain_hint", "example.com", "domain name that is aware of public key hash in hex")
)

func main() {
	flag.Parse()

	var key types.PublicKey
	mustDecodeHex(*vk, key[:])

	vf := dns.NewDefaultResolver()
	if err := vf.Verify(context.Background(), *domain_hint, &key); err != nil {
		log.Fatal(err)
	}

	fmt.Println("Success!")
}

func mustDecodeHex(s string, buf []byte) {
	b, err := hex.Deserialize(s)
	if err != nil {
		log.Fatal(err)
	}
	if len(b) != len(buf) {
		log.Fatal("bad flag: invalid buffer length")
	}
	copy(buf, b)
}