Skip to content
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

🔥 feat: Add support for configuring TLS Min Version #3248

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
)

// ListenConfig is a struct to customize startup of Fiber.
type ListenConfig struct {

Check failure on line 42 in listen.go

View workflow job for this annotation

GitHub Actions / lint

fieldalignment: struct of size 152 could be 144 (govet)
// GracefulContext is a field to shutdown Fiber by given context gracefully.
//
// Default: nil
Expand All @@ -50,6 +50,11 @@
// Default: nil
TLSConfigFunc func(tlsConfig *tls.Config) `json:"tls_config_func"`

// TLSMinVersion allows to set tls minimum version.
//
// Default: VersionTLS12
TLSMinVersion uint16 `json:"tls_min_version"`
gaby marked this conversation as resolved.
Show resolved Hide resolved

// ListenerFunc allows accessing and customizing net.Listener.
//
// Default: nil
Expand Down Expand Up @@ -128,6 +133,7 @@
func listenConfigDefault(config ...ListenConfig) ListenConfig {
if len(config) < 1 {
return ListenConfig{
TLSMinVersion: tls.VersionTLS12,
ListenerNetwork: NetworkTCP4,
OnShutdownError: func(err error) {
log.Fatalf("shutdown: %v", err) //nolint:revive // It's an option
Expand All @@ -147,6 +153,10 @@
}
}

if cfg.TLSMinVersion == 0 {
cfg.TLSMinVersion = tls.VersionTLS12
}

return cfg
}

Expand All @@ -168,8 +178,8 @@
}

tlsHandler := &TLSHandler{}
tlsConfig = &tls.Config{

Check failure on line 181 in listen.go

View workflow job for this annotation

GitHub Actions / lint

G402: TLS MinVersion too low. (gosec)
MinVersion: tls.VersionTLS12,
MinVersion: cfg.TLSMinVersion,
gaby marked this conversation as resolved.
Show resolved Hide resolved
Certificates: []tls.Certificate{
cert,
},
Expand All @@ -192,8 +202,8 @@
// Attach the tlsHandler to the config
app.SetTLSHandler(tlsHandler)
} else if cfg.AutoCertManager != nil {
tlsConfig = &tls.Config{

Check failure on line 205 in listen.go

View workflow job for this annotation

GitHub Actions / lint

G402: TLS MinVersion too low. (gosec)
MinVersion: tls.VersionTLS12,
MinVersion: cfg.TLSMinVersion,

Check warning on line 206 in listen.go

View check run for this annotation

Codecov / codecov/patch

listen.go#L206

Added line #L206 was not covered by tests
GetCertificate: cfg.AutoCertManager.GetCertificate,
NextProtos: []string{"http/1.1", "acme-tls/1"},
}
Expand Down
Loading