-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
54 lines (44 loc) · 1.25 KB
/
main.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
package main
import (
"fmt"
"net/http"
"os"
log "github.com/Sirupsen/logrus"
"github.com/dhiltgen/golang-tofu"
)
func main() {
log.SetLevel(log.DebugLevel)
if len(os.Args) < 2 {
fmt.Println("You must specify a host[:port] as the first argument")
os.Exit(1)
}
details, err := tofu.GetFingerprints(os.Args[1])
if err != nil {
fmt.Printf("Failed to get fingerprints: %s\n", err)
os.Exit(1)
} else {
for i, detail := range details {
fmt.Printf("%02d: Subject: \"%s\"\n", i, detail.Subject)
fmt.Printf("%02d: Issuer: \"%s\"\n", i, detail.Issuer)
fmt.Printf("%02d: Fingerprint: \"%s\"\n", i, detail.Fingerprint)
}
}
// Do your "user validation" here to establish trust with the cert(s)
trustedFingerprint := details[0].Fingerprint
httpClient, err := tofu.GetTofuClient(trustedFingerprint)
if err != nil {
fmt.Printf("Failed to get Trust-On-First-Use client: %s\n", err)
os.Exit(1)
}
req, err := http.NewRequest("GET", fmt.Sprintf("https://%s/", os.Args[1]), nil)
if err != nil {
fmt.Printf("Failed to get build request: %s\n", err)
os.Exit(1)
}
resp, err := httpClient.Do(req)
if err != nil {
fmt.Printf("Failed to get do request: %s\n", err)
os.Exit(1)
}
fmt.Printf("Response code: %d\n", resp.StatusCode)
}