-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
63 lines (53 loc) · 1.46 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
package main
import (
"errors"
"flag"
"fmt"
"net/http"
"os"
)
var (
errFailedToFetchOCSPResponse = errors.New("failed to fetch OCSP response")
errFailedToGetResource = errors.New("failed to get resource")
errFailedToReadCertificate = errors.New("failed to read certificate")
errFailedToReadResponseBody = errors.New("failed to response body")
errNoCertificate = errors.New("no certificate")
errNoIssuerCertificate = errors.New("no issuer certificate")
errNoOCSPServersFound = errors.New("no OCSP servers found")
errNoCRLDistributionPointsFound = errors.New("no CRL distribution points found")
)
// HTTPClient is an interface for fetching HTTP responses.
type HTTPClient interface {
Get(string) (*http.Response, error)
Do(req *http.Request) (*http.Response, error)
}
func main() {
flag.Usage = func() {
fmt.Printf("usage: %s <command> <pem>\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
//nolint:gomnd
if flag.NArg() < 2 {
flag.Usage()
os.Exit(1)
}
// TODO: move to method that returns both cert + issuer?
path := os.Args[2]
cert, err := readCertificate(path)
if err != nil {
fmt.Fprintf(os.Stderr, "[error] %v\n", err)
os.Exit(1)
}
httpClient := &http.Client{}
client := NewClient(httpClient, os.Stdout)
switch os.Args[1] {
case "ocsp":
client.CheckCertificateStatusOCSP(cert)
case "crl":
client.CheckCertificateStatusCRL(cert)
default:
flag.PrintDefaults()
os.Exit(1)
}
}