Skip to content

Commit ed5e3c2

Browse files
authored
fix: validate tls version in config (#287)
TLSVersion validate method is never called when validating the config causing min supported version to not be enforced bump tls version in tests to 1.2 to avoid failing in fips mode
1 parent 79c26b4 commit ed5e3c2

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

transport/tlscommon/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ func LoadTLSConfig(config *Config) (*TLSConfig, error) {
9292
// Validate values the TLSConfig struct making sure certificate sure we have both a certificate and
9393
// a key.
9494
func (c *Config) Validate() error {
95+
for _, v := range c.Versions {
96+
if err := v.Validate(); err != nil {
97+
return err
98+
}
99+
100+
}
95101
return c.Certificate.Validate()
96102
}
97103

transport/tlscommon/tls_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestValuesSet(t *testing.T) {
7676
cipher_suites:
7777
- ECDHE-ECDSA-AES-256-CBC-SHA
7878
- ECDHE-ECDSA-AES-256-GCM-SHA384
79-
supported_protocols: [TLSv1.1, TLSv1.2]
79+
supported_protocols: [TLSv1.3]
8080
curve_types:
8181
- P-521
8282
renegotiation: freely
@@ -92,7 +92,7 @@ func TestValuesSet(t *testing.T) {
9292
assert.Equal(t, VerifyNone, cfg.VerificationMode)
9393
assert.Len(t, cfg.CipherSuites, 2)
9494
assert.Equal(t,
95-
[]TLSVersion{TLSVersion11, TLSVersion12},
95+
[]TLSVersion{TLSVersion13},
9696
cfg.Versions)
9797
assert.Len(t, cfg.CurveTypes, 1)
9898
assert.Equal(t,

transport/tlscommon/types_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,33 @@ func TestLoadWithEmptyStringVerificationMode(t *testing.T) {
5050
certificate: mycert.pem
5151
key: mycert.key
5252
verification_mode: ""
53-
supported_protocols: [TLSv1.1, TLSv1.2]
53+
supported_protocols: [TLSv1.2, TLSv1.3]
5454
renegotiation: freely
5555
`)
5656

5757
assert.NoError(t, err)
5858
assert.Equal(t, cfg.VerificationMode, VerifyFull)
5959
}
6060

61+
func TestLoadUnsupportedProtocols(t *testing.T) {
62+
cfg, err := load(`
63+
enabled: true
64+
certificate: mycert.pem
65+
key: mycert.key
66+
verification_mode: ""
67+
supported_protocols: [TLSv1.0, TLSv1.2]
68+
renegotiation: freely
69+
`)
70+
71+
assert.ErrorContains(t, err, "unsupported tls version")
72+
assert.Nil(t, cfg)
73+
}
74+
6175
func TestLoadWithEmptyVerificationMode(t *testing.T) {
6276
cfg, err := load(`
6377
enabled: true
6478
verification_mode:
65-
supported_protocols: [TLSv1.1, TLSv1.2]
79+
supported_protocols: [TLSv1.2, TLSv1.3]
6680
curve_types:
6781
- P-521
6882
renegotiation: freely
@@ -76,7 +90,7 @@ func TestRepackConfig(t *testing.T) {
7690
cfg, err := load(`
7791
enabled: true
7892
verification_mode: certificate
79-
supported_protocols: [TLSv1.1, TLSv1.2]
93+
supported_protocols: [TLSv1.2, TLSv1.3]
8094
cipher_suites:
8195
- RSA-AES-256-CBC-SHA
8296
certificate_authorities:
@@ -106,7 +120,7 @@ func TestRepackConfigFromJSON(t *testing.T) {
106120
cfg, err := loadJSON(`{
107121
"enabled": true,
108122
"verification_mode": "certificate",
109-
"supported_protocols": ["TLSv1.1", "TLSv1.2"],
123+
"supported_protocols": ["TLSv1.2", "TLSv1.3"],
110124
"cipher_suites": ["RSA-AES-256-CBC-SHA"],
111125
"certificate_authorities": ["/path/to/ca.crt"],
112126
"certificate": "/path/to/cert.crt",

0 commit comments

Comments
 (0)