Skip to content

Commit 91db649

Browse files
Copilotnomeguy
andcommitted
Disable 3DES cipher suites to prevent Sweet32 attack
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
1 parent dd24929 commit 91db649

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

service/proxy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,15 @@ func Start() {
307307
Addr: fmt.Sprintf(":%d", gatewayHttpsPort),
308308
TLSConfig: &tls.Config{
309309
MinVersion: tls.VersionTLS12,
310+
CipherSuites: []uint16{
311+
// Secure cipher suites for TLS 1.2 (excluding 3DES to prevent Sweet32 attack)
312+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
313+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
314+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
315+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
316+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
317+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
318+
},
310319
},
311320
}
312321

service/tls_config_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2023 The casbin Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package service
16+
17+
import (
18+
"crypto/tls"
19+
"testing"
20+
)
21+
22+
// TestTLSConfigExcludes3DES verifies that the TLS configuration excludes
23+
// 3DES cipher suites that are vulnerable to the Sweet32 attack
24+
func TestTLSConfigExcludes3DES(t *testing.T) {
25+
// Create the TLS config as it would be in the actual server
26+
tlsConfig := &tls.Config{
27+
MinVersion: tls.VersionTLS12,
28+
CipherSuites: []uint16{
29+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
30+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
31+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
32+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
33+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
34+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
35+
},
36+
}
37+
38+
// Define vulnerable 3DES cipher suites
39+
vulnerableCiphers := []uint16{
40+
tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
41+
tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
42+
}
43+
44+
// Verify that none of the vulnerable ciphers are in the allowed list
45+
for _, vulnerableCipher := range vulnerableCiphers {
46+
for _, allowedCipher := range tlsConfig.CipherSuites {
47+
if vulnerableCipher == allowedCipher {
48+
t.Errorf("Vulnerable 3DES cipher suite 0x%04X found in allowed cipher suites (Sweet32 vulnerability)", vulnerableCipher)
49+
}
50+
}
51+
}
52+
53+
// Verify minimum TLS version is set to 1.2 or higher
54+
if tlsConfig.MinVersion < tls.VersionTLS12 {
55+
t.Errorf("Minimum TLS version should be 1.2 or higher, got: %d", tlsConfig.MinVersion)
56+
}
57+
58+
// Verify that we have at least some secure cipher suites configured
59+
if len(tlsConfig.CipherSuites) == 0 {
60+
t.Error("No cipher suites configured - default cipher suites may include vulnerable 3DES")
61+
}
62+
}

0 commit comments

Comments
 (0)