Skip to content

Commit

Permalink
Mandate TLS 1.2 or higher in fabhttp package
Browse files Browse the repository at this point in the history
This commit ensures that the HTTP server that is spawned by the fabhttp package
only accepts TLS handshakes from clients that attempt to use TLS 1.2 or higher.

Change-Id: Ia25482d9c96f68506724a58258451311b3d63208
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm authored and sykesm committed Jun 21, 2021
1 parent b5a4fe9 commit 16259ed
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
6 changes: 5 additions & 1 deletion common/fabhttp/fabhttp_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func generateCertificates(tempDir string) {
Expect(err).NotTo(HaveOccurred())
}

func newHTTPClient(tlsDir string, withClientCert bool) *http.Client {
func newHTTPClient(tlsDir string, withClientCert bool, tlsOpts ...func(config *tls.Config)) *http.Client {
clientCertPool := x509.NewCertPool()
caCert, err := ioutil.ReadFile(filepath.Join(tlsDir, "server-ca.pem"))
Expect(err).NotTo(HaveOccurred())
Expand All @@ -66,6 +66,10 @@ func newHTTPClient(tlsDir string, withClientCert bool) *http.Client {
tlsClientConfig.Certificates = []tls.Certificate{clientCert}
}

for _, opt := range tlsOpts {
opt(tlsClientConfig)
}

return &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsClientConfig,
Expand Down
22 changes: 22 additions & 0 deletions common/fabhttp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package fabhttp_test

import (
"crypto/tls"
"fmt"
"io/ioutil"
"net"
Expand Down Expand Up @@ -67,6 +68,27 @@ var _ = Describe("Server", func() {
}
})

When("trying to connect with an old TLS version", func() {
BeforeEach(func() {
tlsOpts := []func(config *tls.Config){func(config *tls.Config) {
config.MaxVersion = tls.VersionTLS11
config.ClientAuth = tls.RequireAndVerifyClientCert
}}

client = newHTTPClient(tempDir, true, tlsOpts...)
})

It("does not answer clients using an older TLS version than 1.2", func() {
server.RegisterHandler(AdditionalTestApiPath, &fakes.Handler{Code: http.StatusOK, Text: "secure"}, options.TLS.Enabled)
err := server.Start()
Expect(err).NotTo(HaveOccurred())

addApiURL := fmt.Sprintf("https://%s%s", server.Addr(), AdditionalTestApiPath)
_, err = client.Get(addApiURL)
Expect(err.Error()).To(ContainSubstring("tls: protocol version not supported"))
})
})

It("does not host a secure endpoint for additional APIs by default", func() {
err := server.Start()
Expect(err).NotTo(HaveOccurred())
Expand Down
1 change: 1 addition & 0 deletions common/fabhttp/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (t TLS) Config() (*tls.Config, error) {
caCertPool.AppendCertsFromPEM(caPem)
}
tlsConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{cert},
CipherSuites: comm.DefaultTLSCipherSuites,
ClientCAs: caCertPool,
Expand Down
1 change: 1 addition & 0 deletions common/fabhttp/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var _ = Describe("TLS", func() {
tlsConfig.ClientCAs = nil

Expect(tlsConfig).To(Equal(&tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{cert},
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Expand Down

0 comments on commit 16259ed

Please sign in to comment.