1package dane_test
2
3import (
4 "context"
5 "crypto/x509"
6 "log"
7 "log/slog"
8
9 "github.com/mjl-/adns"
10
11 "github.com/mjl-/mox/dane"
12 "github.com/mjl-/mox/dns"
13)
14
15func ExampleDial() {
16 ctx := context.Background()
17 resolver := dns.StrictResolver{}
18 usages := []adns.TLSAUsage{adns.TLSAUsageDANETA, adns.TLSAUsageDANEEE}
19 pkixRoots, err := x509.SystemCertPool()
20 if err != nil {
21 log.Fatalf("system pkix roots: %v", err)
22 }
23
24 // Connect to SMTP server, use STARTTLS, and verify TLS certificate with DANE.
25 conn, verifiedRecord, err := dane.Dial(ctx, slog.Default(), resolver, "tcp", "mx.example.com", usages, pkixRoots)
26 if err != nil {
27 log.Fatalf("dial: %v", err)
28 }
29 defer conn.Close()
30
31 log.Printf("connected, conn %v, verified record %s", conn, verifiedRecord)
32}
33