-
Notifications
You must be signed in to change notification settings - Fork 7
/
example_test.go
56 lines (49 loc) · 1.1 KB
/
example_test.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package dane_test
/*
* An example program.
*/
import (
"fmt"
"log"
"github.com/shuque/dane"
)
func Example() {
var daneconfig *dane.Config
servers := []*dane.Server{dane.NewServer("", "8.8.8.8", 53)}
resolver := dane.NewResolver(servers)
hostname := "www.example.com"
tlsa, err := dane.GetTLSA(resolver, hostname, 443)
if err != nil {
log.Fatalf("%s", err)
}
if tlsa == nil {
log.Fatalf("No TLSA records found, where expected.")
}
iplist, err := dane.GetAddresses(resolver, hostname, true)
if err != nil {
log.Fatalf("%s", err)
}
if len(iplist) < 1 {
log.Fatalf("Got less than expected addresses.")
}
for _, ip := range iplist {
daneconfig = dane.NewConfig(hostname, ip, 443)
daneconfig.SetTLSA(tlsa)
conn, err := dane.DialTLS(daneconfig)
if daneconfig.TLSA != nil {
daneconfig.TLSA.Results()
}
if err != nil {
fmt.Printf("Result: FAILED: %s\n", err.Error())
continue
}
conn.Close()
if daneconfig.Okdane {
fmt.Printf("Result: DANE OK\n")
} else if daneconfig.Okpkix {
fmt.Printf("Result: PKIX OK\n")
} else {
fmt.Printf("Result: FAILED\n")
}
}
}