Skip to content

Commit 9b237ef

Browse files
committed
Use kingpin for command parsing; make SNI a flag instead
1 parent 5cd4a98 commit 9b237ef

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Either build it yourself or grab a pre-compiled download from the [Releases](htt
1111
To check a certificate, simply run:
1212

1313
```bash
14-
./check-ssl [domain]
14+
./check-ssl [server]
1515
```
1616

1717
![](screenshot.png)
@@ -21,9 +21,12 @@ Example of allowed arguments include:
2121
- `example.com`
2222
- `example.com:443`
2323
- `https://www.example.com:443/foo/bar`
24+
- `93.184.216.34`
2425

2526
By default, it'll resolve the IP of the given domain and test against that server. But you can also use this tool to check other servers by providing two arguments: the server to test and the SNI to use. For example:
2627

2728
```bash
28-
./check-ssl [server] [SNI domain]
29+
./check-ssl [server] --sni=[SNI domain]
30+
31+
./check-ssl example.com --sni=foo.example.com
2932
```

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ require (
66
github.com/cloudflare/cfssl v1.6.1
77
github.com/dustin/go-humanize v1.0.0
88
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381
9+
gopkg.in/alecthomas/kingpin.v2 v2.2.6
910
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf
1011
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,11 @@ github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkK
7979
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
8080
github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE=
8181
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
82+
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
8283
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
8384
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
8485
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
86+
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
8587
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
8688
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
8789
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
@@ -1106,6 +1108,7 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
11061108
google.golang.org/protobuf v1.25.1-0.20200805231151-a709e31e5d12/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
11071109
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
11081110
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
1111+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
11091112
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
11101113
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
11111114
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

main.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/cloudflare/cfssl/log"
88
"github.com/cloudflare/cfssl/revoke"
99
"github.com/dustin/go-humanize"
10+
"gopkg.in/alecthomas/kingpin.v2"
1011
"net"
1112
"net/url"
1213
"os"
@@ -16,26 +17,21 @@ import (
1617
. "github.com/logrusorgru/aurora"
1718
)
1819

20+
var (
21+
server = kingpin.Arg("host", "Hostname, IP, or URL of the server to check.").String()
22+
sni = kingpin.Flag("sni", "SNI server to use for the certificate (optional).").Short('s').String()
23+
)
24+
1925
func main() {
20-
if len(os.Args) < 2 || len(os.Args) > 3 {
21-
fmt.Print("go-check-ssl: Simple command line utility to check the status of an SSL certificate.\n\n")
22-
fmt.Printf("Usage: %s server [domain]\n", os.Args[0])
23-
fmt.Println()
24-
fmt.Print("Arguments:\n")
25-
fmt.Print(" - 'server' should be any valid hostname, IP, or URL to test\n")
26-
fmt.Print(" - '[domain]' allows you to provide an arbitrary domain name to use for SNI\n")
27-
fmt.Println()
28-
fmt.Print("Example usage:\n")
29-
fmt.Printf(" - %s example.com\n", os.Args[0])
30-
fmt.Printf(" - %s https://www.example.com:443/foo/bar\n", os.Args[0])
31-
fmt.Printf(" - %s 93.184.216.34 www.example.com\n", os.Args[0])
32-
fmt.Printf(" - %s 93.184.216.34:443 www.example.com\n", os.Args[0])
26+
log.SetLogger(new(logger))
27+
28+
kingpin.Parse()
29+
if server == nil || *server == "" {
30+
kingpin.Usage()
3331
os.Exit(1)
3432
}
3533

36-
log.SetLogger(new(logger))
37-
38-
input := os.Args[1]
34+
input := *server
3935
if !strings.Contains(input, "://") {
4036
input = "https://" + input
4137
}
@@ -46,7 +42,7 @@ func main() {
4642
os.Exit(1)
4743
}
4844

49-
// Hostname is used for SNI
45+
// Hostname is used for SNI by default
5046
hostname := parsedUrl.Hostname()
5147
// Server is used for the underlying connection
5248
server := hostname
@@ -55,9 +51,9 @@ func main() {
5551
port = "443"
5652
}
5753

58-
// Did the user provide a different hostname to use for SNI?
59-
if len(os.Args) > 2 {
60-
hostname = os.Args[2]
54+
// Did the user provide a different server to use for SNI?
55+
if sni != nil && *sni != "" {
56+
hostname = *sni
6157
}
6258

6359
// Resolve the IP of the server

0 commit comments

Comments
 (0)