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

Use implicit settings for lighttpd ≥1.4.68 #189

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/js/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module.exports = {
},
lighttpd: {
highlighter: 'nginx',
latestVersion: '1.4.67',
latestVersion: '1.4.76',
name: 'lighttpd',
tls13: '1.4.48'
},
Expand Down
102 changes: 75 additions & 27 deletions src/templates/partials/lighttpd.hbs
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
# {{output.header}}
# {{{output.link}}}
#server.modules += ("mod_redirect")
#server.modules += ("mod_setenv")
#server.modules += ("mod_openssl")
#server.port = 80
$SERVER["socket"] == "[::]:80" { }

{{#if form.hsts}}
$HTTP["scheme"] == "http" {
{{#if (minver "1.4.50" form.serverVersion)}}
url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
{{else}}
$HTTP["host"] =~ ".*" {
url.redirect = (".*" => "https://%0$0")
}
{{/if}}
}

$HTTP["scheme"] == "https" {
# HTTP Strict Transport Security ({{output.hstsMaxAge}} seconds)
setenv.add-response-header = (
"Strict-Transport-Security" => "max-age={{output.hstsMaxAge}}"
)
}
{{/if}}

{{#if (minver "1.4.56" form.serverVersion)}}
# select one TLS module: "mod_openssl" "mod_mbedtls" "mod_gnutls" "mod_wolfssl" "mod_nss"
#server.modules += ("mod_openssl")
server.modules += ("mod_openssl")

# lighttpd 1.4.56 and later will inherit ssl.* from the global scope if
# $SERVER["socket"] contains ssl.engine = "enable" and no other ssl.* options
Expand All @@ -38,19 +16,54 @@ ssl.privkey = "/path/to/private_key"
ssl.pemfile = "/path/to/signed_cert_followed_by_intermediates"
{{#if (minver "1.0.2" form.opensslVersion)}}
{{#if (minver "1.1.0" form.opensslVersion)}}
ssl.openssl.ssl-conf-cmd = ("MinProtocol" => {{#if (includes "TLSv1" output.protocols)}}"TLSv1"{{else if (includes "TLSv1.1" output.protocols)}}"TLSv1.1"{{else if (includes "TLSv1.2" output.protocols)}}"TLSv1.2"{{else}}"TLSv1.3"{{/if}})
{{#if (includes "TLSv1" output.protocols)}}
ssl.openssl.ssl-conf-cmd = ("MinProtocol" => "TLSv1")
{{else if (includes "TLSv1.1" output.protocols)}}
ssl.openssl.ssl-conf-cmd = ("MinProtocol" => "TLSv1.1")
{{else if (includes "TLSv1.2" output.protocols)}}
{{#if (minver "1.4.78" form.serverVersion)}}
ssl.openssl.ssl-conf-cmd = ("MinProtocol" => "TLSv1.2")
{{else}}
{{#unless (minver "1.4.56" form.serverVersion)}}
ssl.openssl.ssl-conf-cmd = ("MinProtocol" => "TLSv1.2")
{{/unless}}
{{/if}}
{{else if (includes "TLSv1.3" output.protocols)}}
{{#unless (minver "1.4.78" form.serverVersion)}}
ssl.openssl.ssl-conf-cmd = ("MinProtocol" => "TLSv1.3")
{{/unless}}
{{/if}}
{{else}}
ssl.openssl.ssl-conf-cmd = ("Protocol" => "ALL, -SSLv2, -SSLv3{{#unless (includes "TLSv1" output.protocols)}}, -TLSv1{{/unless}}{{#unless (includes "TLSv1.1" output.protocols)}}, -TLSv1.1{{/unless}}{{#unless (includes "TLSv1.2" output.protocols)}}, -TLSv1.2{{/unless}}")
{{/if}}
{{#if (minver "1.4.68" form.serverVersion)}}
{{#if output.serverPreferredOrder}}
ssl.openssl.ssl-conf-cmd += ("Options" => "+ServerPreference")
{{/if}}
{{else}}
ssl.openssl.ssl-conf-cmd += ("Options" => "{{#if output.serverPreferredOrder}}+{{else}}-{{/if}}ServerPreference")
{{/if}}
Comment on lines +39 to +45
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it worth differentiating? The JSON specs say either set preference, or don't set preference. Is it better to just omit it and leave to server default?

Copy link
Collaborator

Choose a reason for hiding this comment

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

(I mean, the original +/- satisfied the specs exactly. Is there a reason starting ≥v1.4.68 for not setting -ServerPreference explicitly?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@janbrasna the commit message cut-n-paste into the original description of this PR submission explains that it is best to use the lighttpd TLS defaults. You're welcome to disagree and I am happy to discuss further. However, I do not see how repeating that text a third time in this PR would be useful when I think that text already answers your question.

Is it better to just omit it and leave to server default?

Yes. I am a lighttpd developer and answer user questions on lighttpd forums. Yes, it is better to use lighttpd defaults.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah gotcha, so adding the complexity to the template logic this way makes the output configs actually simpler for newer versions, where you positively know you provide the same result. OK. It's not exactly readable from the partial, but if the end result is the same…

(SImilar issue was with certbot on httpd where locally overriding values explicitly set to defaults here was tricky.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@gstrauss I sure read it… and expected the defaults to be unnecessary old protocols and such, not completely omitting @mozilla/server-side-tls's intermediate cipher suites ;D that's why I raised the additional questions if I read it correctly and the resulting output is really meant that way and not a mistake.

{{#if output.ciphers.length}}
{{#if (minver "1.4.68" form.serverVersion)}}
{{#if (includes "old" form.config)}}
ssl.openssl.ssl-conf-cmd += ("CipherString" => "{{{join output.ciphers ":"}}}")
{{else}}

# lighttpd TLS defaults are widely supported by clients and should be preferred
# See https://wiki.lighttpd.net/Docs_SSL
# Uncomment to better match the *less secure* Mozilla {{form.config}} spec.
#ssl.openssl.ssl-conf-cmd += ("CipherString" => "{{{join output.ciphers ":"}}}")
{{/if}}
{{else}}
# TLS modules besides mod_openssl might name ciphers differently
# See https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_SSL
# See https://wiki.lighttpd.net/Docs_SSL
ssl.openssl.ssl-conf-cmd += ("CipherString" => "{{{join output.ciphers ":"}}}")
{{/if}}
{{/if}}
{{#if form.ocsp}}
# OCSP stapling (input file must be maintained by external script)
# https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_SSL#OCSP-Stapling

# OCSP stapling (input file must be maintained by external script, e.g. cert-staple.sh)
# https://wiki.lighttpd.net/Docs_SSL#OCSP-Stapling
ssl.stapling-file = "/path/to/cert-staple.der"
{{/if}}
{{else}}
Expand All @@ -62,6 +75,9 @@ ssl.cipher-list = "{{{join output.ciphers ":"}}}"
{{/if}}
{{/if}}
{{else}}
{{#if (minver "1.4.46" form.serverVersion)}}
server.modules += ("mod_openssl")
{{/if}}
$SERVER["socket"] == ":443" {
ssl.engine = "enable"

Expand Down Expand Up @@ -103,3 +119,35 @@ $SERVER["socket"] == ":443" {
}
#$SERVER["socket"] == "[::]:443" { ... } # repeat entire $SERVER["socket"] == ":443" { ... } config above for IPv6
{{/if}}

{{#if form.hsts}}
{{#if (minver "1.4.56" form.serverVersion)}}
server.modules += ("mod_redirect")
server.modules += ("mod_setenv")
{{else}}
#server.modules += ("mod_redirect")
#server.modules += ("mod_setenv")
{{/if}}
$HTTP["scheme"] == "https" {
# HTTP Strict Transport Security ({{output.hstsMaxAge}} seconds)
setenv.add-response-header = (
"Strict-Transport-Security" => "max-age={{output.hstsMaxAge}}"
)
}
else $HTTP["scheme"] == "http" {
{{#unless (includes "old" form.config)}}
{{#unless (minver "1.4.75" form.serverVersion)}}
{{#if (minver "1.4.31" form.serverVersion)}}
url.redirect-code = 308
{{/if}}
{{/unless}}
{{/unless}}
{{#if (minver "1.4.50" form.serverVersion)}}
url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
{{else}}
$HTTP["host"] =~ ".*" {
url.redirect = (".*" => "https://%0$0")
}
{{/if}}
}
{{/if}}