certbot/certbot-apache/certbot_apache/constants.py

278 lines
9.3 KiB
Python
Raw Permalink Normal View History

"""Apache plugin constants."""
import pkg_resources
from certbot import util
from certbot.plugins import common
from certbot_apache import override_centos
2017-10-20 13:11:38 -04:00
from certbot_apache import override_debian
2016-07-30 03:44:46 -04:00
CLI_DEFAULTS_DEFAULT = dict(
server_root="/etc/apache2",
vhost_root="/etc/apache2/sites-available",
vhost_files="*",
2016-08-21 14:50:14 -04:00
logs_root="/var/log/apache2",
2016-07-30 03:44:46 -04:00
version_cmd=['apache2ctl', '-v'],
define_cmd=['apache2ctl', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apache2ctl', 'graceful'],
conftest_cmd=['apache2ctl', 'configtest'],
enmod=None,
dismod=None,
2016-07-30 03:44:46 -04:00
le_vhost_ext="-le-ssl.conf",
handle_mods=False,
handle_sites=False,
challenge_location="/etc/apache2",
override_class=None,
2016-07-30 03:44:46 -04:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
)
2015-12-03 07:14:02 -05:00
CLI_DEFAULTS_DEBIAN = dict(
2015-05-08 17:32:13 -04:00
server_root="/etc/apache2",
vhost_root="/etc/apache2/sites-available",
vhost_files="*",
2016-08-21 14:50:14 -04:00
logs_root="/var/log/apache2",
version_cmd=['apache2ctl', '-v'],
define_cmd=['apache2ctl', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apache2ctl', 'graceful'],
conftest_cmd=['apache2ctl', 'configtest'],
2015-05-08 17:32:13 -04:00
enmod="a2enmod",
2015-07-30 02:40:07 -04:00
dismod="a2dismod",
le_vhost_ext="-le-ssl.conf",
handle_mods=True,
handle_sites=True,
challenge_location="/etc/apache2",
override_class=override_debian.Override,
2016-01-26 13:39:54 -05:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
2015-05-08 17:32:13 -04:00
)
2015-12-03 07:14:02 -05:00
CLI_DEFAULTS_CENTOS = dict(
server_root="/etc/httpd",
vhost_root="/etc/httpd/conf.d",
vhost_files="*.conf",
2016-08-21 14:50:14 -04:00
logs_root="/var/log/httpd",
version_cmd=['apachectl', '-v'],
define_cmd=['apachectl', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apachectl', 'graceful'],
conftest_cmd=['apachectl', 'configtest'],
2015-12-03 07:14:02 -05:00
enmod=None,
dismod=None,
le_vhost_ext="-le-ssl.conf",
handle_mods=False,
handle_sites=False,
challenge_location="/etc/httpd/conf.d",
override_class=override_centos.Override,
2016-01-26 13:39:54 -05:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "centos-options-ssl-apache.conf")
2015-12-03 07:14:02 -05:00
)
CLI_DEFAULTS_GENTOO = dict(
server_root="/etc/apache2",
vhost_root="/etc/apache2/vhosts.d",
vhost_files="*.conf",
2016-08-21 14:50:14 -04:00
logs_root="/var/log/apache2",
version_cmd=['/usr/sbin/apache2', '-v'],
2016-03-23 12:12:07 -04:00
define_cmd=['apache2ctl', 'virtualhosts'],
restart_cmd=['apache2ctl', 'graceful'],
conftest_cmd=['apache2ctl', 'configtest'],
enmod=None,
dismod=None,
le_vhost_ext="-le-ssl.conf",
handle_mods=False,
handle_sites=False,
challenge_location="/etc/apache2/vhosts.d",
override_class=None,
2016-01-26 13:39:54 -05:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
)
CLI_DEFAULTS_DARWIN = dict(
server_root="/etc/apache2",
vhost_root="/etc/apache2/other",
vhost_files="*.conf",
2016-08-21 14:50:14 -04:00
logs_root="/var/log/apache2",
version_cmd=['/usr/sbin/httpd', '-v'],
define_cmd=['/usr/sbin/httpd', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apachectl', 'graceful'],
conftest_cmd=['apachectl', 'configtest'],
enmod=None,
dismod=None,
le_vhost_ext="-le-ssl.conf",
handle_mods=False,
handle_sites=False,
challenge_location="/etc/apache2/other",
override_class=None,
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
)
2016-07-30 18:10:28 -04:00
CLI_DEFAULTS_SUSE = dict(
server_root="/etc/apache2",
vhost_root="/etc/apache2/vhosts.d",
vhost_files="*.conf",
2016-08-21 14:50:14 -04:00
logs_root="/var/log/apache2",
2016-07-30 18:10:28 -04:00
version_cmd=['apache2ctl', '-v'],
define_cmd=['apache2ctl', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apache2ctl', 'graceful'],
conftest_cmd=['apache2ctl', 'configtest'],
enmod="a2enmod",
dismod="a2dismod",
le_vhost_ext="-le-ssl.conf",
2016-08-02 02:57:34 -04:00
handle_mods=False,
2016-07-30 18:10:28 -04:00
handle_sites=False,
challenge_location="/etc/apache2/vhosts.d",
override_class=None,
2016-07-30 18:10:28 -04:00
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
)
CLI_DEFAULTS_ARCH = dict(
server_root="/etc/httpd",
vhost_root="/etc/httpd/conf",
vhost_files="*.conf",
logs_root="/var/log/httpd",
version_cmd=['apachectl', '-v'],
define_cmd=['apachectl', '-t', '-D', 'DUMP_RUN_CFG'],
restart_cmd=['apachectl', 'graceful'],
conftest_cmd=['apachectl', 'configtest'],
enmod=None,
dismod=None,
le_vhost_ext="-le-ssl.conf",
handle_mods=False,
handle_sites=False,
challenge_location="/etc/httpd/conf",
override_class=None,
MOD_SSL_CONF_SRC=pkg_resources.resource_filename(
"certbot_apache", "options-ssl-apache.conf")
)
2015-12-03 07:14:02 -05:00
CLI_DEFAULTS = {
2016-07-30 03:44:46 -04:00
"default": CLI_DEFAULTS_DEFAULT,
2015-12-03 07:14:02 -05:00
"debian": CLI_DEFAULTS_DEBIAN,
"ubuntu": CLI_DEFAULTS_DEBIAN,
"centos": CLI_DEFAULTS_CENTOS,
2015-12-07 07:22:56 -05:00
"centos linux": CLI_DEFAULTS_CENTOS,
"fedora": CLI_DEFAULTS_CENTOS,
2015-12-21 15:52:32 -05:00
"red hat enterprise linux server": CLI_DEFAULTS_CENTOS,
2016-04-12 11:59:27 -04:00
"rhel": CLI_DEFAULTS_CENTOS,
"amazon": CLI_DEFAULTS_CENTOS,
"gentoo": CLI_DEFAULTS_GENTOO,
"gentoo base system": CLI_DEFAULTS_GENTOO,
"darwin": CLI_DEFAULTS_DARWIN,
2016-07-30 18:10:28 -04:00
"opensuse": CLI_DEFAULTS_SUSE,
"suse": CLI_DEFAULTS_SUSE,
"arch": CLI_DEFAULTS_ARCH,
2015-12-03 07:14:02 -05:00
}
2015-05-08 17:32:13 -04:00
"""CLI defaults."""
MOD_SSL_CONF_DEST = "options-ssl-apache.conf"
"""Name of the mod_ssl config file as saved in `IConfig.config_dir`."""
UPDATED_MOD_SSL_CONF_DIGEST = ".updated-options-ssl-apache-conf-digest.txt"
"""Name of the hash of the updated or informed mod_ssl_conf as saved in `IConfig.config_dir`."""
ALL_SSL_OPTIONS_HASHES = [
'2086bca02db48daf93468332543c60ac6acdb6f0b58c7bfdf578a5d47092f82a',
'4844d36c9a0f587172d9fa10f4f1c9518e3bcfa1947379f155e16a70a728c21a',
'5a922826719981c0a234b1fbcd495f3213e49d2519e845ea0748ba513044b65b',
'4066b90268c03c9ba0201068eaa39abbc02acf9558bb45a788b630eb85dadf27',
'f175e2e7c673bd88d0aff8220735f385f916142c44aa83b09f1df88dd4767a88',
'cfdd7c18d2025836ea3307399f509cfb1ebf2612c87dd600a65da2a8e2f2797b',
]
"""SHA256 hashes of the contents of previous versions of all versions of MOD_SSL_CONF_SRC"""
2015-11-04 15:12:39 -05:00
AUGEAS_LENS_DIR = pkg_resources.resource_filename(
"certbot_apache", "augeas_lens")
2015-11-04 15:12:39 -05:00
"""Path to the Augeas lens directory"""
REWRITE_HTTPS_ARGS = [
"^", "https://%{SERVER_NAME}%{REQUEST_URI}", "[L,NE,R=permanent]"]
2016-01-14 06:25:15 -05:00
"""Apache version<2.3.9 rewrite rule arguments used for redirections to
https vhost"""
2015-11-06 17:31:30 -05:00
REWRITE_HTTPS_ARGS_WITH_END = [
"^", "https://%{SERVER_NAME}%{REQUEST_URI}", "[END,NE,R=permanent]"]
2015-12-01 19:16:13 -05:00
"""Apache version >= 2.3.9 rewrite rule arguments used for redirections to
https vhost"""
2015-11-07 23:37:57 -05:00
OLD_REWRITE_HTTPS_ARGS = [
["^", "https://%{SERVER_NAME}%{REQUEST_URI}", "[L,QSA,R=permanent]"],
["^", "https://%{SERVER_NAME}%{REQUEST_URI}", "[END,QSA,R=permanent]"]]
2015-11-07 23:37:57 -05:00
HSTS_ARGS = ["always", "set", "Strict-Transport-Security",
2016-01-14 06:25:15 -05:00
"\"max-age=31536000\""]
2015-11-06 17:31:30 -05:00
"""Apache header arguments for HSTS"""
2015-11-07 23:37:57 -05:00
UIR_ARGS = ["always", "set", "Content-Security-Policy",
2016-01-14 06:25:15 -05:00
"upgrade-insecure-requests"]
2015-11-07 23:37:57 -05:00
2015-11-08 10:21:36 -05:00
HEADER_ARGS = {"Strict-Transport-Security": HSTS_ARGS,
2016-01-14 06:25:15 -05:00
"Upgrade-Insecure-Requests": UIR_ARGS}
2015-11-07 23:37:57 -05:00
def install_ssl_options_conf(options_ssl, options_ssl_digest):
"""Copy Certbot's SSL options file into the system's config dir if required."""
# XXX if we ever try to enforce a local privilege boundary (eg, running
# certbot for unprivileged users via setuid), this function will need
# to be modified.
return common.install_version_controlled_file(options_ssl, options_ssl_digest,
os_constant("MOD_SSL_CONF_SRC"), ALL_SSL_OPTIONS_HASHES)
2015-12-07 06:37:58 -05:00
2015-12-03 07:14:02 -05:00
def os_constant(key):
"""
Get a constant value for operating system
2015-12-07 05:01:35 -05:00
:param key: name of cli constant
:return: value of constant for active os
"""
os_info = util.get_os_info()
2015-12-03 07:14:02 -05:00
try:
constants = CLI_DEFAULTS[os_info[0].lower()]
except KeyError:
constants = os_like_constants()
if not constants:
constants = CLI_DEFAULTS["default"]
2015-12-03 07:14:02 -05:00
return constants[key]
def os_like_constants():
"""
Try to get constants for distribution with
similar layout and configuration, indicated by
/etc/os-release variable "LIKE"
:returns: Constants dictionary
:rtype: `dict`
"""
os_like = util.get_systemd_os_like()
if os_like:
for os_name in os_like:
if os_name in CLI_DEFAULTS.keys():
return CLI_DEFAULTS[os_name]
return {}
def get_override(caller):
"""
Initialize the override class and pass the caller class to it
:param caller: `class` of caller
:return: Override class or `None` if not found
"""
override_class = os_constant("override_class")
if override_class:
return override_class(caller)
return None
def override(method):
"""Decorator for ApacheConfigurator for distribution specific method
overrides."""
def override_args(caller_class, *args, **kwargs):
"""Check if distro specific class overrides called method, return
overriding method if found, in other case, return the default"""
try:
# Try to find overriding method
caller = {"class": caller_class, "method": method}
return getattr(caller_class.os_info,
method.__name__)(caller, *args, **kwargs)
except AttributeError:
# Override not found, return the default
return method(caller_class, *args, **kwargs)
return override_args