-
Notifications
You must be signed in to change notification settings - Fork 326
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
Add TLS support to http server #332
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,10 @@ var ( | |
logger *zap.SugaredLogger | ||
fastlog *zap.Logger | ||
help = flag.Bool("help", false, "show usage") | ||
scheme = map[bool]string{ | ||
false: "http", | ||
true: "https", | ||
} | ||
// doProfile = flag.Bool("profile", false, "run profiler at /debug/pprof") | ||
) | ||
|
||
|
@@ -112,6 +116,7 @@ func main() { | |
configure() | ||
var listen = cfg.Cfg.Listen + ":" + strconv.Itoa(cfg.Cfg.Port) | ||
checkTCPPortAvailable(listen) | ||
tls := (cfg.Cfg.TLS.Cert != "" && cfg.Cfg.TLS.Key != "") | ||
|
||
logger.Infow("starting "+cfg.Branding.FullName, | ||
// "semver": semver, | ||
|
@@ -120,7 +125,8 @@ func main() { | |
"buildhost", host, | ||
"branch", branch, | ||
"semver", semver, | ||
"listen", listen, | ||
"listen", scheme[tls]+"://"+listen, | ||
"tls", tls, | ||
"oauth.provider", cfg.GenOAuth.Provider) | ||
|
||
muxR := mux.NewRouter() | ||
|
@@ -166,7 +172,12 @@ func main() { | |
ErrorLog: log.New(&fwdToZapWriter{fastlog}, "", 0), | ||
} | ||
|
||
logger.Fatal(srv.ListenAndServe()) | ||
if tls { | ||
srv.TLSConfig = cfg.TLSConfig(cfg.Cfg.TLS.Profile) | ||
logger.Fatal(srv.ListenAndServeTLS(cfg.Cfg.TLS.Cert, cfg.Cfg.TLS.Key)) | ||
} else { | ||
logger.Fatal(srv.ListenAndServe()) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. althought There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ |
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
|
||
Copyright 2020 The Vouch Proxy Authors. | ||
Use of this source code is governed by The MIT License (MIT) that | ||
can be found in the LICENSE file. Software distributed under The | ||
MIT License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
OR CONDITIONS OF ANY KIND, either express or implied. | ||
|
||
*/ | ||
|
||
package cfg | ||
|
||
import ( | ||
"crypto/tls" | ||
) | ||
|
||
// TLSConfig config returns a *tls.Config with the specified profile (modern, intermediate, old, default) configuration. | ||
func TLSConfig(profile string) *tls.Config { | ||
c := &tls.Config{} | ||
|
||
// Source: https://ssl-config.mozilla.org/#server=go&version=1.14&config=modern&hsts=false&guideline=5.6 | ||
switch profile { | ||
case "modern": | ||
c = &tls.Config{ | ||
MinVersion: tls.VersionTLS13, | ||
} | ||
case "intermediate": | ||
c = &tls.Config{ | ||
MinVersion: tls.VersionTLS12, | ||
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256}, | ||
PreferServerCipherSuites: true, | ||
CipherSuites: []uint16{ | ||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | ||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | ||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | ||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | ||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, | ||
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, | ||
}, | ||
} | ||
case "old": | ||
c = &tls.Config{ | ||
MinVersion: tls.VersionTLS10, | ||
PreferServerCipherSuites: true, | ||
CipherSuites: []uint16{ | ||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | ||
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | ||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | ||
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | ||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, | ||
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, | ||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, | ||
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, | ||
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, | ||
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, | ||
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, | ||
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, | ||
tls.TLS_RSA_WITH_AES_128_GCM_SHA256, | ||
tls.TLS_RSA_WITH_AES_256_GCM_SHA384, | ||
tls.TLS_RSA_WITH_AES_128_CBC_SHA256, | ||
tls.TLS_RSA_WITH_AES_128_CBC_SHA, | ||
tls.TLS_RSA_WITH_AES_256_CBC_SHA, | ||
tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, | ||
}, | ||
} | ||
} | ||
|
||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
|
||
Copyright 2020 The Vouch Proxy Authors. | ||
Use of this source code is governed by The MIT License (MIT) that | ||
can be found in the LICENSE file. Software distributed under The | ||
MIT License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
OR CONDITIONS OF ANY KIND, either express or implied. | ||
|
||
*/ | ||
|
||
package cfg | ||
|
||
import ( | ||
"crypto/tls" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTLSConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
profile string | ||
wantTLSMinVersion uint16 | ||
}{ | ||
{"TLSDefaultProfile", "", 0}, | ||
{"TLSModernProfile", "modern", tls.VersionTLS13}, | ||
{"TLSIntermediateProfile", "intermediate", tls.VersionTLS12}, | ||
{"TLSOldProfile", "old", tls.VersionTLS10}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tlsConfig := TLSConfig(tt.profile) | ||
assert.Equal(t, tt.wantTLSMinVersion, tlsConfig.MinVersion) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include the the env var names in the documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅