Skip to content

Commit

Permalink
advancedTLS: unset a deprecated field after copying it (#7239)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtcooke94 authored May 21, 2024
1 parent 2174ea6 commit 2d2f417
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions security/advancedtls/advancedtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ func (o *Options) clientConfig() (*tls.Config, error) {
// the setting int the right place.
if o.RootOptions.RootCACerts != nil {
o.RootOptions.RootCertificates = o.RootOptions.RootCACerts
// There are additional checks that only 1 field of `RootOptions` is
// non-nil, so set the deprecated field to nil
o.RootOptions.RootCACerts = nil
}
if o.VerificationType == SkipVerification && o.AdditionalPeerVerification == nil {
return nil, fmt.Errorf("client needs to provide custom verification mechanism if choose to skip default verification")
Expand Down Expand Up @@ -425,6 +428,9 @@ func (o *Options) serverConfig() (*tls.Config, error) {
// the setting int the right place.
if o.RootOptions.RootCACerts != nil {
o.RootOptions.RootCertificates = o.RootOptions.RootCACerts
// There are additional checks that only 1 field of `RootOptions` is
// non-nil, so set the deprecated field to nil
o.RootOptions.RootCACerts = nil
}
if o.RequireClientCert && o.VerificationType == SkipVerification && o.AdditionalPeerVerification == nil {
return nil, fmt.Errorf("server needs to provide custom verification mechanism if choose to skip default verification, but require client certificate(s)")
Expand Down
16 changes: 16 additions & 0 deletions security/advancedtls/advancedtls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ func (s) TestClientOptionsConfigSuccessCases(t *testing.T) {
MinVersion: tls.VersionTLS12,
MaxVersion: tls.VersionTLS13,
},
{
desc: "Deprecated option is set and forwarded",
clientVerificationType: CertVerification,
RootOptions: RootCertificateOptions{
RootCACerts: x509.NewCertPool(),
},
},
}
for _, test := range tests {
test := test
Expand Down Expand Up @@ -351,6 +358,15 @@ func (s) TestServerOptionsConfigSuccessCases(t *testing.T) {
MinVersion: tls.VersionTLS12,
MaxVersion: tls.VersionTLS13,
},
{
desc: "Deprecated option is set and forwarded",
IdentityOptions: IdentityCertificateOptions{
Certificates: []tls.Certificate{},
},
RootOptions: RootCertificateOptions{
RootCACerts: x509.NewCertPool(),
},
},
}
for _, test := range tests {
test := test
Expand Down

0 comments on commit 2d2f417

Please sign in to comment.