Skip to content

Commit 834df7c

Browse files
authored
Merge pull request #2 from jibsonline/Option_to_specify_SSL_Ciphers
Option to specify ssl ciphers
2 parents 36512f2 + 59f9cf4 commit 834df7c

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

bmcldap.yml.sample

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ ClientCaCert: "/etc/openldap/cacerts/cacert.pem"
33
RemoteServerName: "ldaps.example.com"
44
RemoteServerPortTLS: 636
55
MinTLSVersion: "1.2"
6+
CipherSuites:
7+
- "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
8+
- "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"
9+
- "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
10+
- "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"
11+
- "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"
12+
- "TLS_RSA_WITH_AES_128_GCM_SHA256"
13+
- "TLS_RSA_WITH_AES_256_GCM_SHA384"
14+
- "TLS_RSA_WITH_AES_128_CBC_SHA"
15+
- "TLS_RSA_WITH_AES_256_CBC_SHA"
616
Debug: true
717
PortTLS: 443
818
PortInsecure: 386

cmd/serve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func serve() {
4646
RemoteServerPortTLS: viper.GetInt("RemoteServerPortTLS"),
4747
Debug: viper.GetBool("Debug"),
4848
MinTLSVersion: viper.GetString("MinTLSVersion"),
49+
CipherSuites: viper.GetStringSlice("CipherSuites"),
4950
PortTLS: viper.GetInt("PortTLS"),
5051
PortInsecure: viper.GetInt("PortInsecure"),
5152
Cert: viper.GetString("Cert"),

pkg/backend_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func setup() (*Config, *logrus.Logger) {
2121
RemoteServerPortTLS: 636,
2222
Debug: true,
2323
MinTLSVersion: "1.2",
24+
CipherSuites: []string{"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"},
2425
PortTLS: 443,
2526
PortInsecure: 386,
2627
Cert: "/etc/bmcldap/server.pem",

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Config struct {
2121
BaseDN string
2222
Config string
2323
MinTLSVersion string
24+
CipherSuites []string
2425
RemoteServerName string
2526
RemoteServerPortTLS int
2627
CaCert string

pkg/server.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,35 @@ func (bmcLdap *BmcLdap) LoadTlsConfig(c *config.Config) *tls.Config {
8686
}).Warning("Using TLS 1.1, ignoring unsupported version " + c.MinTLSVersion)
8787
}
8888

89+
// Please Note: TLSv1.3 Ciphers cannot be defined as of today
90+
var cipherSuitesTLS []uint16
91+
92+
if len(c.CipherSuites) > 0 {
93+
// Including Both Secure and Insecure Ciphers, in-case anyone wants to use Insecure ones for compatibility reasons
94+
allCipherSuites := append(tls.CipherSuites(), tls.InsecureCipherSuites()...)
95+
// Check if the Cipher Keys Belong to Ciphers supported by Go TLS module
96+
for _, secureCipher := range allCipherSuites {
97+
if sliceContains(c.CipherSuites, secureCipher.Name) {
98+
cipherSuitesTLS = append(cipherSuitesTLS, secureCipher.ID)
99+
}
100+
}
101+
102+
}
89103
return &tls.Config{
90104
Certificates: []tls.Certificate{cert},
91105
InsecureSkipVerify: true,
92106
MinVersion: uint16(minVersion),
107+
CipherSuites: cipherSuitesTLS,
93108
}
94109
}
110+
111+
// A function to check if a slice contains a string
112+
func sliceContains(s []string, str string) bool {
113+
for _, v := range s {
114+
if v == str {
115+
return true
116+
}
117+
}
118+
119+
return false
120+
}

0 commit comments

Comments
 (0)