Skip to content

Commit 265b64f

Browse files
authored
fix: validate tls server config fields (#295)
validate cipher suites, versions and curve types
1 parent 034952a commit 265b64f

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

transport/tlscommon/server_config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ func (c *ServerConfig) Validate() error {
131131
return ErrCertificateUnspecified
132132
}
133133
}
134+
for _, v := range c.Versions {
135+
if err := v.Validate(); err != nil {
136+
return err
137+
}
138+
139+
}
140+
for _, cs := range c.CipherSuites {
141+
if err := cs.Validate(); err != nil {
142+
return err
143+
}
144+
}
145+
for _, ct := range c.CurveTypes {
146+
if err := ct.Validate(); err != nil {
147+
return err
148+
}
149+
}
134150
return c.Certificate.Validate()
135151
}
136152

transport/tlscommon/server_config_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ func Test_ServerConfig_Repack(t *testing.T) {
105105
yaml: `
106106
enabled: true
107107
verification_mode: certificate
108-
supported_protocols: [TLSv1.1, TLSv1.2]
108+
supported_protocols: [TLSv1.2, TLSv1.3]
109109
cipher_suites:
110-
- RSA-AES-256-CBC-SHA
110+
- ECDHE-ECDSA-AES-128-GCM-SHA256
111111
certificate_authorities:
112112
- /path/to/ca.crt
113113
certificate: /path/to/cert.cry
@@ -123,9 +123,9 @@ func Test_ServerConfig_Repack(t *testing.T) {
123123
yaml: `
124124
enabled: true
125125
verification_mode: certificate
126-
supported_protocols: [TLSv1.1, TLSv1.2]
126+
supported_protocols: [TLSv1.2, TLSv1.3]
127127
cipher_suites:
128-
- RSA-AES-256-CBC-SHA
128+
- ECDHE-ECDSA-AES-128-GCM-SHA256
129129
certificate_authorities:
130130
- /path/to/ca.crt
131131
certificate: /path/to/cert.cry
@@ -140,9 +140,9 @@ func Test_ServerConfig_Repack(t *testing.T) {
140140
yaml: `
141141
enabled: true
142142
verification_mode: certificate
143-
supported_protocols: [TLSv1.1, TLSv1.2]
143+
supported_protocols: [TLSv1.2, TLSv1.3]
144144
cipher_suites:
145-
- RSA-AES-256-CBC-SHA
145+
- ECDHE-ECDSA-AES-128-GCM-SHA256
146146
certificate: /path/to/cert.cry
147147
key: /path/to/key/crt
148148
curve_types:
@@ -185,8 +185,8 @@ func Test_ServerConfig_RepackJSON(t *testing.T) {
185185
json: `{
186186
"enabled": true,
187187
"verification_mode": "certificate",
188-
"supported_protocols": ["TLSv1.1", "TLSv1.2"],
189-
"cipher_suites": ["RSA-AES-256-CBC-SHA"],
188+
"supported_protocols": ["TLSv1.2", "TLSv1.3"],
189+
"cipher_suites": ["ECDHE-ECDSA-AES-128-GCM-SHA256"],
190190
"certificate_authorities": ["/path/to/ca.crt"],
191191
"certificate": "/path/to/cert.crt",
192192
"key": "/path/to/key.crt",
@@ -202,8 +202,8 @@ func Test_ServerConfig_RepackJSON(t *testing.T) {
202202
json: `{
203203
"enabled": true,
204204
"verification_mode": "certificate",
205-
"supported_protocols": ["TLSv1.1", "TLSv1.2"],
206-
"cipher_suites": ["RSA-AES-256-CBC-SHA"],
205+
"supported_protocols": ["TLSv1.2", "TLSv1.3"],
206+
"cipher_suites": ["ECDHE-ECDSA-AES-128-GCM-SHA256"],
207207
"certificate_authorities": ["/path/to/ca.crt"],
208208
"certificate": "/path/to/cert.crt",
209209
"key": "/path/to/key.crt",
@@ -218,8 +218,8 @@ func Test_ServerConfig_RepackJSON(t *testing.T) {
218218
json: `{
219219
"enabled": true,
220220
"verification_mode": "certificate",
221-
"supported_protocols": ["TLSv1.1", "TLSv1.2"],
222-
"cipher_suites": ["RSA-AES-256-CBC-SHA"],
221+
"supported_protocols": ["TLSv1.2", "TLSv1.3"],
222+
"cipher_suites": ["ECDHE-ECDSA-AES-128-GCM-SHA256"],
223223
"certificate": "/path/to/cert.crt",
224224
"key": "/path/to/key.crt",
225225
"curve_types": "P-384",

transport/tlscommon/tls_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func TestApplyWithServerConfig(t *testing.T) {
213213
verification_mode: none
214214
client_authentication: optional
215215
cipher_suites:
216-
- "ECDHE-ECDSA-AES-256-CBC-SHA"
216+
- "ECDHE-ECDSA-AES-128-GCM-SHA256"
217217
- "ECDHE-ECDSA-AES-256-GCM-SHA384"
218218
curve_types: [P-384]
219219
`

0 commit comments

Comments
 (0)