Skip to content

Hardening: TLS >= 1.2, limit cipher suites #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -87,6 +88,30 @@ func main() {

log.Printf(green("Proxying calls from https://%s (SSL/TLS) to %s"), *fromURL, toURL)

// Configure TLS to reasonably secure defaults
tlsCfg := new(tls.Config)
tlsCfg.MinVersion = tls.VersionTLS12
// Limit cipher suites available as of go 1.13
// - List according to crypto/tls constants - in reverse order (i.e. prefer stronger over weaker ciphers)
// - Filtered out: RC4, (3)DES, CBC suites
tlsCfg.CipherSuites = []uint16{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of specifying our own can we rely on the "safe default" list chosen by the Go authors? As vulnerabilities emerge, we may need to specify our own list or upgrade Go, but at the moment upgrading seems sufficient and limits complexity on our end?

It also appears in go1.18.3 the tls1.3 cipher suites are not settable, so do they need to be included? (As an aside, I'm going to send a PR to update the repo to go1.18.3, so we are up to date with default lists)

https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/crypto/tls/common.go;l=649-654;drc=2580d0e08d5e9f979b943758d3c49877fb2324cb

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just sent #44 to update go).

If we can just go with the safe default list, we can not specify this list but we can still specify the min tls version and go from there. wdyt?

// TLS 1.3 cipher suites.
tls.TLS_CHACHA20_POLY1305_SHA256,
tls.TLS_AES_128_GCM_SHA256,
tls.TLS_AES_256_GCM_SHA384,

// TLS 1.0 - 1.2 cipher suites.
// tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, // not available as of go 1.13, activate later
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
}

// Redirect http requests on port 80 to TLS port using https
if *redirectHTTP {
// Redirect to fromURL by default, unless a domain is specified--in that case, redirect using the public facing
Expand Down Expand Up @@ -123,15 +148,25 @@ func main() {
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(*domain),
}

t := m.TLSConfig()
t.MinVersion = tlsCfg.MinVersion
t.CipherSuites = tlsCfg.CipherSuites

s := &http.Server{
Addr: *fromURL,
TLSConfig: m.TLSConfig(),
TLSConfig: t,
}
s.Handler = mux
log.Fatal(s.ListenAndServeTLS("", ""))
} else {
// Domain is not provided, serve TLS using provided/generated certificate files
log.Fatal(http.ListenAndServeTLS(*fromURL, *certFile, *keyFile, mux))
s := &http.Server{
Addr: *fromURL,
Handler: mux,
TLSConfig: tlsCfg,
}
log.Fatal(s.ListenAndServeTLS(*certFile, *keyFile))
}

}
Expand Down