Skip to content

Commit a2399ef

Browse files
committed
Don't override the minimum TLS version for a tls.Config. Use map literals for CSE prose test 11.
1 parent b7a77c8 commit a2399ef

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

internal/integration/client_side_encryption_prose_test.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,46 +1517,52 @@ func TestClientSideEncryptionProse(t *testing.T) {
15171517
SetKeyVaultNamespace(kvNamespace)
15181518

15191519
// make TLS opts containing client certificate and CA file
1520-
tlsConfig := make(map[string]*tls.Config)
15211520
clientAndCATlsMap := map[string]interface{}{
15221521
"tlsCertificateKeyFile": tlsClientCertificateKeyFileKMIP,
15231522
"tlsCAFile": tlsCAFileKMIP,
15241523
}
1525-
certConfig, err := options.BuildTLSConfig(clientAndCATlsMap)
1524+
clientAndCATLSConfig, err := options.BuildTLSConfig(clientAndCATlsMap)
15261525
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
1527-
tlsConfig["aws"] = certConfig
1528-
tlsConfig["azure"] = certConfig
1529-
tlsConfig["gcp"] = certConfig
1530-
tlsConfig["kmip"] = certConfig
15311526

15321527
// create valid Client Encryption options and set valid TLS options
15331528
validClientEncryptionOptionsWithTLS := options.ClientEncryption().
15341529
SetKmsProviders(validKmsProviders).
15351530
SetKeyVaultNamespace(kvNamespace).
1536-
SetTLSConfig(tlsConfig)
1531+
SetTLSConfig(map[string]*tls.Config{
1532+
"aws": clientAndCATLSConfig,
1533+
"azure": clientAndCATLSConfig,
1534+
"gcp": clientAndCATLSConfig,
1535+
"kmip": clientAndCATLSConfig,
1536+
})
15371537

15381538
// make TLS opts containing only CA file
1539-
caTlsMap := map[string]interface{}{
1539+
caTlSMap := map[string]interface{}{
15401540
"tlsCAFile": tlsCAFileKMIP,
15411541
}
1542-
certConfig, err = options.BuildTLSConfig(caTlsMap)
1542+
caTLSConfig, err := options.BuildTLSConfig(caTlSMap)
15431543
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
1544-
tlsConfig["aws"] = certConfig
1545-
tlsConfig["azure"] = certConfig
1546-
tlsConfig["gcp"] = certConfig
1547-
tlsConfig["kmip"] = certConfig
15481544

15491545
// create invalid Client Encryption options with expired credentials
15501546
expiredClientEncryptionOptions := options.ClientEncryption().
15511547
SetKmsProviders(expiredKmsProviders).
15521548
SetKeyVaultNamespace(kvNamespace).
1553-
SetTLSConfig(tlsConfig)
1549+
SetTLSConfig(map[string]*tls.Config{
1550+
"aws": caTLSConfig,
1551+
"azure": caTLSConfig,
1552+
"gcp": caTLSConfig,
1553+
"kmip": caTLSConfig,
1554+
})
15541555

15551556
// create invalid Client Encryption options with invalid hostnames
15561557
invalidHostnameClientEncryptionOptions := options.ClientEncryption().
15571558
SetKmsProviders(invalidKmsProviders).
15581559
SetKeyVaultNamespace(kvNamespace).
1559-
SetTLSConfig(tlsConfig)
1560+
SetTLSConfig(map[string]*tls.Config{
1561+
"aws": caTLSConfig,
1562+
"azure": caTLSConfig,
1563+
"gcp": caTLSConfig,
1564+
"kmip": caTLSConfig,
1565+
})
15601566

15611567
awsMasterKeyNoClientCert := map[string]interface{}{
15621568
"region": "us-east-1",

mongo/options/autoencryptionoptions.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,9 @@ func (a *AutoEncryptionOptionsBuilder) SetExtraOptions(extraOpts map[string]inte
184184
// to the KMS provider.
185185
//
186186
// This should only be used to set custom TLS configurations. By default, the connection will use an empty tls.Config{} with MinVersion set to tls.VersionTLS12.
187-
func (a *AutoEncryptionOptionsBuilder) SetTLSConfig(tlsOpts map[string]*tls.Config) *AutoEncryptionOptionsBuilder {
188-
tlsConfigs := make(map[string]*tls.Config)
189-
for provider, config := range tlsOpts {
190-
// Use TLS min version 1.2 to enforce more secure hash algorithms and
191-
// advanced cipher suites.
192-
if config.MinVersion == 0 {
193-
config.MinVersion = tls.VersionTLS12
194-
}
195-
tlsConfigs[provider] = config
196-
}
197-
187+
func (a *AutoEncryptionOptionsBuilder) SetTLSConfig(cfg map[string]*tls.Config) *AutoEncryptionOptionsBuilder {
198188
a.Opts = append(a.Opts, func(args *AutoEncryptionOptions) error {
199-
args.TLSConfig = tlsConfigs
189+
args.TLSConfig = cfg
200190

201191
return nil
202192
})

mongo/options/clientencryptionoptions.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,9 @@ func (c *ClientEncryptionOptionsBuilder) SetKmsProviders(providers map[string]ma
7070
// to the KMS provider.
7171
//
7272
// This should only be used to set custom TLS configurations. By default, the connection will use an empty tls.Config{} with MinVersion set to tls.VersionTLS12.
73-
func (c *ClientEncryptionOptionsBuilder) SetTLSConfig(tlsOpts map[string]*tls.Config) *ClientEncryptionOptionsBuilder {
74-
tlsConfigs := make(map[string]*tls.Config)
75-
for provider, config := range tlsOpts {
76-
// Use TLS min version 1.2 to enforce more secure hash algorithms and
77-
// advanced cipher suites.
78-
if config.MinVersion == 0 {
79-
config.MinVersion = tls.VersionTLS12
80-
}
81-
tlsConfigs[provider] = config
82-
}
83-
73+
func (c *ClientEncryptionOptionsBuilder) SetTLSConfig(cfg map[string]*tls.Config) *ClientEncryptionOptionsBuilder {
8474
c.Opts = append(c.Opts, func(opts *ClientEncryptionOptions) error {
85-
opts.TLSConfig = tlsConfigs
75+
opts.TLSConfig = cfg
8676

8777
return nil
8878
})

0 commit comments

Comments
 (0)