Skip to content

Commit e474713

Browse files
authored
introduce probe --cert-details flag (#12)
* introduce `probe --cert-details` flag - this will hide away SANs and validity dates by default * update linter
1 parent 2c1eaec commit e474713

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: golangci-lint
2727
uses: golangci/golangci-lint-action@v6
2828
with:
29-
version: v1.60
29+
version: v1.62
3030
only-new-issues: true
3131
testing:
3232
runs-on: ubuntu-latest

.github/workflows/verify.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: golangci-lint
3434
uses: golangci/golangci-lint-action@v6
3535
with:
36-
version: v1.60
36+
version: v1.62
3737
only-new-issues: true
3838

3939
cross-build-darwin:

cmd/probe.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import (
2626
)
2727

2828
type probeOptions struct {
29-
verbose bool
30-
ppv1, ppv2 bool
31-
sni string
29+
verbose bool
30+
showCertDetails bool
31+
ppv1, ppv2 bool
32+
sni string
3233
}
3334

3435
var probeOpts probeOptions
@@ -72,6 +73,9 @@ used instead of the literal endpoint host name.`,
7273
if probeOpts.sni != "" {
7374
proberOptions.ServerNameIndication = probeOpts.sni
7475
}
76+
if probeOpts.showCertDetails {
77+
proberOptions.PrintCertDetails = true
78+
}
7579
prober, err := probe.NewProber(proberOptions)
7680

7781
if err != nil {
@@ -98,6 +102,7 @@ used instead of the literal endpoint host name.`,
98102
}
99103

100104
cmd.Flags().BoolVar(&probeOpts.verbose, "verbose", false, "be verbose, output logs")
105+
cmd.Flags().BoolVar(&probeOpts.showCertDetails, "cert-details", false, "show certificate details (SANs, validity)")
101106
cmd.Flags().BoolVar(&probeOpts.ppv1, "proxy-protocol-v1", false, "send proxy protocol v1 headers")
102107
cmd.Flags().BoolVar(&probeOpts.ppv2, "proxy-protocol-v2", false, "send proxy protocol v2 headers")
103108
cmd.Flags().StringVar(&probeOpts.sni, "sni", "", "set SNI for TLS handshake (defaults to endpoint host)")

pkg/probe/probe.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type ProbeOptions struct {
4343
Endpoint string
4444
ProxyProtocolMode ProxyProtocolMode
4545
ServerNameIndication string
46+
PrintCertDetails bool
4647
}
4748

4849
type Signal struct {
@@ -61,7 +62,13 @@ type Signal struct {
6162

6263
var errTLSFailure = fmt.Errorf("TLS failure")
6364

65+
func (s Signal) DetailedString() string {
66+
return s.stringer(true)
67+
}
6468
func (s Signal) String() string {
69+
return s.stringer(false)
70+
}
71+
func (s Signal) stringer(printCertDetails bool) string {
6572
parts := []string{s.Path}
6673
if s.Error != nil {
6774
parts = append(parts, "ERROR=\""+s.Error.Error()+"\"")
@@ -81,14 +88,14 @@ func (s Signal) String() string {
8188
if s.PeerSubject != "" {
8289
parts = append(parts, "peer-subject="+s.PeerSubject)
8390
}
84-
if len(s.SANs) > 0 {
91+
if len(s.SANs) > 0 && printCertDetails {
8592
parts = append(parts, "SANs="+strings.Join(s.SANs, ","))
8693
}
8794

88-
if !s.ValidityNotBefore.IsZero() {
95+
if !s.ValidityNotBefore.IsZero() && printCertDetails {
8996
parts = append(parts, "validity-not-before="+s.ValidityNotBefore.Format(time.RFC3339))
9097
}
91-
if !s.ValidityNotAfter.IsZero() {
98+
if !s.ValidityNotAfter.IsZero() && printCertDetails {
9299
parts = append(parts, "validity-not-after="+s.ValidityNotAfter.Format(time.RFC3339))
93100
}
94101

@@ -108,13 +115,15 @@ type prober struct {
108115
proxyProtocolMode ProxyProtocolMode
109116
sni string
110117
signals chan Signal
118+
printCertDetails bool
111119
}
112120

113121
func NewProber(o ProbeOptions) (*prober, error) {
114122
p := &prober{
115123
endpoint: o.Endpoint,
116124
proxyProtocolMode: o.ProxyProtocolMode,
117125
sni: o.ServerNameIndication,
126+
printCertDetails: o.PrintCertDetails,
118127
}
119128
var err error
120129
p.fqdn, p.port, err = net.SplitHostPort(p.endpoint)
@@ -130,6 +139,7 @@ func NewProber(o ProbeOptions) (*prober, error) {
130139
}
131140

132141
func (p *prober) Probe(ctx context.Context) error {
142+
// TODO: implement Probe function which exposes the signal channel
133143
log := util.CtxLogOrPanic(ctx)
134144
defer log.Sync()
135145
p.signals = make(chan Signal)
@@ -141,9 +151,9 @@ func (p *prober) Probe(ctx context.Context) error {
141151
for signal := range signals {
142152
if signal.Error != nil {
143153
fmt.Printf("%s FAILED: %v\n", signal.Path, signal.Error)
144-
} else {
145-
fmt.Printf("%s\n", signal)
154+
continue
146155
}
156+
fmt.Printf("%s\n", signal.stringer(p.printCertDetails))
147157
}
148158
}(ctx, p.signals)
149159

0 commit comments

Comments
 (0)