Skip to content

Commit 6ade819

Browse files
committed
GODRIVER-3321 Fix CSE SetTLSConfig option.
1 parent 4f4f715 commit 6ade819

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

internal/integration/client_side_encryption_prose_test.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,10 @@ func TestClientSideEncryptionProse(t *testing.T) {
14441444
if os.Getenv("KMS_MOCK_SERVERS_RUNNING") == "" {
14451445
mt.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")
14461446
}
1447+
if tlsCAFileKMIP == "" || tlsClientCertificateKeyFileKMIP == "" {
1448+
mt.Fatal("Env vars CSFLE_TLS_CA_FILE and CSFLE_TLS_CLIENT_CERT_FILE must be set")
1449+
}
1450+
14471451
validKmsProviders := map[string]map[string]interface{}{
14481452
"aws": {
14491453
"accessKeyId": awsAccessKeyID,
@@ -1514,37 +1518,33 @@ func TestClientSideEncryptionProse(t *testing.T) {
15141518

15151519
// make TLS opts containing client certificate and CA file
15161520
tlsConfig := make(map[string]*tls.Config)
1517-
if tlsCAFileKMIP != "" && tlsClientCertificateKeyFileKMIP != "" {
1518-
clientAndCATlsMap := map[string]interface{}{
1519-
"tlsCertificateKeyFile": tlsClientCertificateKeyFileKMIP,
1520-
"tlsCAFile": tlsCAFileKMIP,
1521-
}
1522-
certConfig, err := options.BuildTLSConfig(clientAndCATlsMap)
1523-
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
1524-
tlsConfig["aws"] = certConfig
1525-
tlsConfig["azure"] = certConfig
1526-
tlsConfig["gcp"] = certConfig
1527-
tlsConfig["kmip"] = certConfig
1521+
clientAndCATlsMap := map[string]interface{}{
1522+
"tlsCertificateKeyFile": tlsClientCertificateKeyFileKMIP,
1523+
"tlsCAFile": tlsCAFileKMIP,
15281524
}
1525+
certConfig, err := options.BuildTLSConfig(clientAndCATlsMap)
1526+
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
1527+
tlsConfig["aws"] = certConfig
1528+
tlsConfig["azure"] = certConfig
1529+
tlsConfig["gcp"] = certConfig
1530+
tlsConfig["kmip"] = certConfig
15291531

15301532
// create valid Client Encryption options and set valid TLS options
15311533
validClientEncryptionOptionsWithTLS := options.ClientEncryption().
15321534
SetKmsProviders(validKmsProviders).
15331535
SetKeyVaultNamespace(kvNamespace).
15341536
SetTLSConfig(tlsConfig)
15351537

1536-
// make TLS opts containing only CA file
1537-
if tlsCAFileKMIP != "" {
1538-
caTlsMap := map[string]interface{}{
1539-
"tlsCAFile": tlsCAFileKMIP,
1540-
}
1541-
certConfig, err := options.BuildTLSConfig(caTlsMap)
1542-
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
1543-
tlsConfig["aws"] = certConfig
1544-
tlsConfig["azure"] = certConfig
1545-
tlsConfig["gcp"] = certConfig
1546-
tlsConfig["kmip"] = certConfig
1538+
// make TLS opts containing only CA file
1539+
caTlsMap := map[string]interface{}{
1540+
"tlsCAFile": tlsCAFileKMIP,
15471541
}
1542+
certConfig, err = options.BuildTLSConfig(caTlsMap)
1543+
assert.Nil(mt, err, "BuildTLSConfig error: %v", err)
1544+
tlsConfig["aws"] = certConfig
1545+
tlsConfig["azure"] = certConfig
1546+
tlsConfig["gcp"] = certConfig
1547+
tlsConfig["kmip"] = certConfig
15481548

15491549
// create invalid Client Encryption options with expired credentials
15501550
expiredClientEncryptionOptions := options.ClientEncryption().
@@ -1622,7 +1622,8 @@ func TestClientSideEncryptionProse(t *testing.T) {
16221622

16231623
possibleErrors := []string{
16241624
"x509: certificate signed by unknown authority", // Windows
1625-
"x509: “valid.testing.golang.invalid” certificate is not trusted", // MacOS
1625+
"x509: “valid.testing.golang.invalid” certificate is not trusted", // macOS
1626+
"x509: “server” certificate is not standards compliant", // macOS
16261627
"x509: certificate is not authorized to sign other certificates", // All others
16271628
}
16281629

mongo/options/autoencryptionoptions.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,17 @@ func (a *AutoEncryptionOptionsBuilder) SetExtraOptions(extraOpts map[string]inte
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.
187187
func (a *AutoEncryptionOptionsBuilder) SetTLSConfig(tlsOpts map[string]*tls.Config) *AutoEncryptionOptionsBuilder {
188-
a.Opts = append(a.Opts, func(args *AutoEncryptionOptions) error {
189-
tlsConfigs := make(map[string]*tls.Config)
190-
for provider, config := range tlsOpts {
191-
// use TLS min version 1.2 to enforce more secure hash algorithms and advanced cipher suites
192-
if config.MinVersion == 0 {
193-
config.MinVersion = tls.VersionTLS12
194-
}
195-
tlsConfigs[provider] = config
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
196194
}
195+
tlsConfigs[provider] = config
196+
}
197+
198+
a.Opts = append(a.Opts, func(args *AutoEncryptionOptions) error {
197199
args.TLSConfig = tlsConfigs
198200

199201
return nil

mongo/options/clientencryptionoptions.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@ func (c *ClientEncryptionOptionsBuilder) SetKmsProviders(providers map[string]ma
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.
7373
func (c *ClientEncryptionOptionsBuilder) SetTLSConfig(tlsOpts map[string]*tls.Config) *ClientEncryptionOptionsBuilder {
74-
c.Opts = append(c.Opts, func(opts *ClientEncryptionOptions) error {
75-
tlsConfigs := make(map[string]*tls.Config)
76-
for provider, config := range tlsOpts {
77-
// use TLS min version 1.2 to enforce more secure hash algorithms and advanced cipher suites
78-
if config.MinVersion == 0 {
79-
config.MinVersion = tls.VersionTLS12
80-
}
81-
tlsConfigs[provider] = config
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
8280
}
81+
tlsConfigs[provider] = config
82+
}
83+
84+
c.Opts = append(c.Opts, func(opts *ClientEncryptionOptions) error {
8385
opts.TLSConfig = tlsConfigs
86+
8487
return nil
8588
})
89+
8690
return c
8791
}
8892

0 commit comments

Comments
 (0)