Skip to content

Commit 92c6a97

Browse files
author
Hridoy Roy
authored
TLS Diagnose Formatting Fixes (#11342)
* diagnose formatting fixes * diagnose formatting fixes
1 parent e9ee430 commit 92c6a97

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

vault/diagnose/tls_verification.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ func ListenerChecks(listeners []listenerutil.Listener) error {
3636
return fmt.Errorf(maxVersionError, l.TLSMaxVersion)
3737
}
3838

39-
var err error
4039
// Perform checks on the TLS Cryptographic Information.
41-
if err = TLSFileChecks(l.TLSCertFile, l.TLSKeyFile); err != nil {
40+
if err := TLSFileChecks(l.TLSCertFile, l.TLSKeyFile); err != nil {
4241
return err
4342
}
4443
}
@@ -117,15 +116,10 @@ func TLSFileChecks(certFilePath, keyFilePath string) error {
117116
// After verify passes, we need to check the values on the certificate itself.
118117
// This is a separate check beyond the certificate expiry and chain checks.
119118

120-
cert, err := tls.LoadX509KeyPair(certFilePath, keyFilePath)
119+
_, err = tls.LoadX509KeyPair(certFilePath, keyFilePath)
121120
if err != nil {
122121
return err
123122
}
124-
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
125-
if err != nil {
126-
return err
127-
}
128-
cert.Leaf = x509Cert
129123

130124
return nil
131125
}

vault/diagnose/tls_verification_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestTLSValidCert(t *testing.T) {
2828
}
2929
err := ListenerChecks(listeners)
3030
if err != nil {
31-
t.Error(err.Error())
31+
t.Fatalf(err.Error())
3232
}
3333
}
3434

@@ -50,10 +50,10 @@ func TestTLSFakeCert(t *testing.T) {
5050
}
5151
err := ListenerChecks(listeners)
5252
if err == nil {
53-
t.Error("TLS Config check on fake certificate should fail")
53+
t.Fatalf("TLS Config check on fake certificate should fail")
5454
}
5555
if !strings.Contains(err.Error(), "could not decode cert") {
56-
t.Errorf("Bad error message: %w", err)
56+
t.Fatalf("Bad error message: %s", err)
5757
}
5858
}
5959

@@ -78,10 +78,10 @@ func TestTLSTrailingData(t *testing.T) {
7878
}
7979
err := ListenerChecks(listeners)
8080
if err == nil {
81-
t.Error("TLS Config check on fake certificate should fail")
81+
t.Fatalf("TLS Config check on fake certificate should fail")
8282
}
8383
if !strings.Contains(err.Error(), "asn1: syntax error: trailing data") {
84-
t.Errorf("Bad error message: %w", err)
84+
t.Fatalf("Bad error message: %s", err)
8585
}
8686
}
8787

@@ -104,10 +104,10 @@ func TestTLSExpiredCert(t *testing.T) {
104104
}
105105
err := ListenerChecks(listeners)
106106
if err == nil {
107-
t.Error("TLS Config check on fake certificate should fail")
107+
t.Fatalf("TLS Config check on fake certificate should fail")
108108
}
109109
if !strings.Contains(err.Error(), "certificate has expired or is not yet valid") {
110-
t.Errorf("Bad error message: %w", err)
110+
t.Fatalf("Bad error message: %s", err)
111111
}
112112
}
113113

@@ -130,10 +130,10 @@ func TestTLSMismatchedCryptographicInfo(t *testing.T) {
130130
}
131131
err := ListenerChecks(listeners)
132132
if err == nil {
133-
t.Error("TLS Config check on fake certificate should fail")
133+
t.Fatalf("TLS Config check on fake certificate should fail")
134134
}
135135
if err.Error() != "tls: private key type does not match public key type" {
136-
t.Errorf("Bad error message: %w", err)
136+
t.Fatalf("Bad error message: %s", err)
137137
}
138138

139139
listeners = []listenerutil.Listener{
@@ -153,10 +153,10 @@ func TestTLSMismatchedCryptographicInfo(t *testing.T) {
153153
}
154154
err = ListenerChecks(listeners)
155155
if err == nil {
156-
t.Error("TLS Config check on fake certificate should fail")
156+
t.Fatalf("TLS Config check on fake certificate should fail")
157157
}
158158
if err.Error() != "tls: private key type does not match public key type" {
159-
t.Errorf("Bad error message: %w", err)
159+
t.Fatalf("Bad error message: %s", err)
160160
}
161161
}
162162

@@ -179,10 +179,10 @@ func TestTLSMultiKeys(t *testing.T) {
179179
}
180180
err := ListenerChecks(listeners)
181181
if err == nil {
182-
t.Error("TLS Config check on fake certificate should fail")
182+
t.Fatalf("TLS Config check on fake certificate should fail")
183183
}
184184
if !strings.Contains(err.Error(), "pem block does not parse to a certificate") {
185-
t.Errorf("Bad error message: %w", err)
185+
t.Fatalf("Bad error message: %s", err)
186186
}
187187
}
188188

@@ -204,10 +204,10 @@ func TestTLSMultiCerts(t *testing.T) {
204204
}
205205
err := ListenerChecks(listeners)
206206
if err == nil {
207-
t.Error("TLS Config check on fake certificate should fail")
207+
t.Fatalf("TLS Config check on fake certificate should fail")
208208
}
209209
if !strings.Contains(err.Error(), "found a certificate rather than a key in the PEM for the private key") {
210-
t.Errorf("Bad error message: %w", err)
210+
t.Fatalf("Bad error message: %s", err)
211211
}
212212
}
213213

@@ -231,10 +231,10 @@ func TestTLSInvalidRoot(t *testing.T) {
231231
}
232232
err := ListenerChecks(listeners)
233233
if err == nil {
234-
t.Error("TLS Config check on fake certificate should fail")
234+
t.Fatalf("TLS Config check on fake certificate should fail")
235235
}
236236
if err.Error() != "failed to verify certificate: x509: certificate signed by unknown authority" {
237-
t.Errorf("Bad error message: %w", err)
237+
t.Fatalf("Bad error message: %s", err)
238238
}
239239
}
240240

@@ -258,7 +258,7 @@ func TestTLSNoRoot(t *testing.T) {
258258
}
259259
err := ListenerChecks(listeners)
260260
if err != nil {
261-
t.Error("Server certificate without root certificate is insecure, but still valid.")
261+
t.Fatalf("Server certificate without root certificate is insecure, but still valid.")
262262
}
263263
}
264264

@@ -282,10 +282,10 @@ func TestTLSInvalidMinVersion(t *testing.T) {
282282
}
283283
err := ListenerChecks(listeners)
284284
if err == nil {
285-
t.Error("TLS Config check on fake certificate should fail")
285+
t.Fatalf("TLS Config check on fake certificate should fail")
286286
}
287287
if err.Error() != fmt.Errorf(minVersionError, "0").Error() {
288-
t.Errorf("Bad error message: %w", err)
288+
t.Fatalf("Bad error message: %s", err)
289289
}
290290
}
291291

@@ -309,7 +309,7 @@ func TestTLSInvalidMaxVersion(t *testing.T) {
309309
}
310310
err := ListenerChecks(listeners)
311311
if err == nil {
312-
t.Error("TLS Config check on fake certificate should fail")
312+
t.Fatalf("TLS Config check on fake certificate should fail")
313313
}
314314
if err.Error() != fmt.Errorf(maxVersionError, "0").Error() {
315315
t.Errorf("Bad error message: %w", err)

0 commit comments

Comments
 (0)