-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.go
75 lines (63 loc) · 2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"os"
"github.com/genkiroid/cert"
)
var version = ""
func main() {
var format string
var template string
var skipVerify bool
var utc bool
var timeout int
var showVersion bool
var cipherSuite string
flag.StringVar(&format, "f", "simple table", "Output format. md: as markdown, json: as JSON. ")
flag.StringVar(&format, "format", "simple table", "Output format. md: as markdown, json: as JSON. ")
flag.StringVar(&template, "t", "", "Output format as Go template string or Go template file path.")
flag.StringVar(&template, "template", "", "Output format as Go template string or Go template file path.")
flag.BoolVar(&skipVerify, "k", false, "Skip verification of server's certificate chain and host name.")
flag.BoolVar(&skipVerify, "skip-verify", false, "Skip verification of server's certificate chain and host name.")
flag.BoolVar(&utc, "u", false, "Use UTC to represent NotBefore and NotAfter.")
flag.BoolVar(&utc, "utc", false, "Use UTC to represent NotBefore and NotAfter.")
flag.IntVar(&timeout, "s", 3, "Timeout seconds.")
flag.IntVar(&timeout, "timeout", 3, "Timeout seconds.")
flag.BoolVar(&showVersion, "v", false, "Show version.")
flag.BoolVar(&showVersion, "version", false, "Show version.")
flag.StringVar(&cipherSuite, "c", "", "Specify cipher suite. Refer to https://golang.org/pkg/crypto/tls/#pkg-constants for supported cipher suites.")
flag.StringVar(&cipherSuite, "cipher", "", "Specify cipher suite. Refer to https://golang.org/pkg/crypto/tls/#pkg-constants for supported cipher suites.")
flag.Parse()
if showVersion {
fmt.Println("cert version ", version)
return
}
var certs cert.Certs
var err error
cert.SkipVerify = skipVerify
cert.UTC = utc
cert.TimeoutSeconds = timeout
cert.CipherSuite = cipherSuite
certs, err = cert.NewCerts(flag.Args())
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
if template == "" {
switch format {
case "md":
fmt.Printf("%s", certs.Markdown())
case "json":
fmt.Printf("%s", certs.JSON())
default:
fmt.Printf("%s", certs)
}
return
}
if err := cert.SetUserTempl(template); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
fmt.Printf("%s", certs)
}