Skip to content

Commit 034952a

Browse files
authored
feat(fips): restrict supported tls curve types in fips mode (#294)
* feat(fips): restrict supported tls curve types in fips mode match NIST SP 800-52r2 approved list * Update types_test.go * Update tls_test.go * Update server_config_test.go
1 parent f003159 commit 034952a

File tree

8 files changed

+49
-10
lines changed

8 files changed

+49
-10
lines changed

transport/tlscommon/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ func (c *Config) Validate() error {
103103
return err
104104
}
105105
}
106+
for _, ct := range c.CurveTypes {
107+
if err := ct.Validate(); err != nil {
108+
return err
109+
}
110+
}
106111
return c.Certificate.Validate()
107112
}
108113

transport/tlscommon/server_config_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func Test_ServerConfig_Repack(t *testing.T) {
113113
certificate: /path/to/cert.cry
114114
key: /path/to/key/crt
115115
curve_types:
116-
- P-521
116+
- P-384
117117
client_authentication: optional
118118
ca_sha256:
119119
- example`,
@@ -131,7 +131,7 @@ func Test_ServerConfig_Repack(t *testing.T) {
131131
certificate: /path/to/cert.cry
132132
key: /path/to/key/crt
133133
curve_types:
134-
- P-521
134+
- P-384
135135
ca_sha256:
136136
- example`,
137137
auth: &required,
@@ -146,7 +146,7 @@ func Test_ServerConfig_Repack(t *testing.T) {
146146
certificate: /path/to/cert.cry
147147
key: /path/to/key/crt
148148
curve_types:
149-
- P-521
149+
- P-384
150150
ca_sha256:
151151
- example`,
152152
auth: nil,
@@ -190,7 +190,7 @@ func Test_ServerConfig_RepackJSON(t *testing.T) {
190190
"certificate_authorities": ["/path/to/ca.crt"],
191191
"certificate": "/path/to/cert.crt",
192192
"key": "/path/to/key.crt",
193-
"curve_types": "P-521",
193+
"curve_types": "P-384",
194194
"renegotiation": "freely",
195195
"ca_sha256": ["example"],
196196
"ca_trusted_fingerprint": "fingerprint",
@@ -207,7 +207,7 @@ func Test_ServerConfig_RepackJSON(t *testing.T) {
207207
"certificate_authorities": ["/path/to/ca.crt"],
208208
"certificate": "/path/to/cert.crt",
209209
"key": "/path/to/key.crt",
210-
"curve_types": "P-521",
210+
"curve_types": "P-384",
211211
"renegotiation": "freely",
212212
"ca_sha256": ["example"],
213213
"ca_trusted_fingerprint": "fingerprint"
@@ -222,7 +222,7 @@ func Test_ServerConfig_RepackJSON(t *testing.T) {
222222
"cipher_suites": ["RSA-AES-256-CBC-SHA"],
223223
"certificate": "/path/to/cert.crt",
224224
"key": "/path/to/key.crt",
225-
"curve_types": "P-521",
225+
"curve_types": "P-384",
226226
"renegotiation": "freely",
227227
"ca_sha256": ["example"]
228228
}`,

transport/tlscommon/tls_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestValuesSet(t *testing.T) {
7878
- ECDHE-ECDSA-AES-256-GCM-SHA384
7979
supported_protocols: [TLSv1.3]
8080
curve_types:
81-
- P-521
81+
- P-384
8282
renegotiation: freely
8383
`)
8484

transport/tlscommon/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func init() {
9696
}
9797
}
9898

99+
var supportedCurveTypes = make(map[tlsCurveType]string, len(tlsCurveTypes))
99100
var tlsCurveTypes = map[string]tlsCurveType{
100101
"P-256": tlsCurveType(tls.CurveP256),
101102
"P-384": tlsCurveType(tls.CurveP384),
@@ -292,6 +293,13 @@ func (ct *tlsCurveType) Unpack(i interface{}) error {
292293
return nil
293294
}
294295

296+
func (ct *tlsCurveType) Validate() error {
297+
if _, ok := supportedCurveTypes[*ct]; !ok {
298+
return fmt.Errorf("unsupported curve type: %s", tls.CurveID(*ct).String())
299+
}
300+
return nil
301+
}
302+
295303
type TLSRenegotiationSupport tls.RenegotiationSupport
296304

297305
func (r TLSRenegotiationSupport) String() string {

transport/tlscommon/types_fips.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ func init() {
3737
supportedCipherSuites[i] = cipherName
3838
}
3939
}
40+
// only allow P256, P384.
41+
for name, curveType := range tlsCurveTypes {
42+
switch tls.CurveID(curveType) {
43+
case tls.CurveP256, tls.CurveP384:
44+
supportedCurveTypes[curveType] = name
45+
}
46+
}
4047
}

transport/tlscommon/types_fips_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,19 @@ func TestLoadUnsupportedCiphers(t *testing.T) {
5353
assert.ErrorContains(t, err, "unsupported tls cipher suite: TLS_RSA_WITH_AES_256_CBC_SHA")
5454
assert.Nil(t, cfg)
5555
}
56+
57+
func TestLoadUnsupportedCurveTypes(t *testing.T) {
58+
cfg, err := load(`
59+
enabled: true
60+
certificate: mycert.pem
61+
key: mycert.key
62+
verification_mode: ""
63+
supported_protocols: [TLSv1.2, TLSv1.3]
64+
curve_types:
65+
- X25519
66+
renegotiation: freely
67+
`)
68+
69+
assert.ErrorContains(t, err, "unsupported curve type: X25519")
70+
assert.Nil(t, cfg)
71+
}

transport/tlscommon/types_nofips.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ func init() {
2424
for cipherName, i := range tlsCipherSuites {
2525
supportedCipherSuites[i] = cipherName
2626
}
27+
for name, curveType := range tlsCurveTypes {
28+
supportedCurveTypes[curveType] = name
29+
}
2730
}

transport/tlscommon/types_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestLoadWithEmptyVerificationMode(t *testing.T) {
7878
verification_mode:
7979
supported_protocols: [TLSv1.2, TLSv1.3]
8080
curve_types:
81-
- P-521
81+
- P-384
8282
renegotiation: freely
8383
`)
8484

@@ -98,7 +98,7 @@ func TestRepackConfig(t *testing.T) {
9898
certificate: /path/to/cert.crt
9999
key: /path/to/key.crt
100100
curve_types:
101-
- P-521
101+
- P-384
102102
renegotiation: freely
103103
ca_sha256:
104104
- example
@@ -125,7 +125,7 @@ func TestRepackConfigFromJSON(t *testing.T) {
125125
"certificate_authorities": ["/path/to/ca.crt"],
126126
"certificate": "/path/to/cert.crt",
127127
"key": "/path/to/key.crt",
128-
"curve_types": "P-521",
128+
"curve_types": "P-384",
129129
"renegotiation": "freely",
130130
"ca_sha256": ["example"],
131131
"ca_trusted_fingerprint": "fingerprint"

0 commit comments

Comments
 (0)