-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (49 loc) · 1.2 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
55
56
57
58
59
60
61
package main
import (
"fmt"
"net/url"
"os"
"github.com/krzysdabro/tlscert/internal"
"github.com/spf13/pflag"
)
var (
fChain = pflag.Bool("chain", false, "show certificate chain")
fDisableAIAFetching = pflag.Bool("disable-aia-fetching", false, "disable fetching certificates provided by Authority Information Access extension")
fSCT = pflag.Bool("sct", false, "print Signed Certificate Timestamps")
)
func main() {
pflag.Usage = usage
pflag.Parse()
if pflag.NArg() != 1 {
pflag.Usage()
os.Exit(1)
}
arg := pflag.Arg(0)
u, err := url.Parse(arg)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to parse URL:", err)
os.Exit(1)
}
cert, err := internal.GetCertificate(u)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to get certificates:", err)
os.Exit(1)
}
if !*fDisableAIAFetching {
cert.DownloadIssuingCertificate()
}
opts := &internal.PrintOptions{
SCTs: *fSCT,
}
cert.Print(opts)
if chain := cert.Chain(); *fChain && len(chain) > 0 {
for _, chainCert := range chain {
fmt.Print("\n\n")
chainCert.Print(opts)
}
}
}
func usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] <url>\nOptions:\n", os.Args[0])
pflag.PrintDefaults()
}