Extract SSL context creation to helper (#15483)
* Extract SSL context creation to helper * Lint
This commit is contained in:
1 parent
dd7890c848
commit
ad4cba70a0
3 files changed
+50
-23
No files matched your search
@@ -19,6 +19,7 @@ import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.remote as rem
|
||||
import homeassistant.util as hass_util
|
||||
from homeassistant.util.logging import HideSensitiveDataFilter
|
||||
from homeassistant.util import ssl as ssl_util
|
||||
|
||||
from .auth import setup_auth
|
||||
from .ban import setup_bans
|
||||
@@ -49,21 +50,6 @@ CONF_TRUSTED_NETWORKS = 'trusted_networks'
|
||||
CONF_LOGIN_ATTEMPTS_THRESHOLD = 'login_attempts_threshold'
|
||||
CONF_IP_BAN_ENABLED = 'ip_ban_enabled'
|
||||
|
||||
# TLS configuration follows the best-practice guidelines specified here:
|
||||
# https://wiki.mozilla.org/Security/Server_Side_TLS
|
||||
# Modern guidelines are followed.
|
||||
SSL_VERSION = ssl.PROTOCOL_TLS # pylint: disable=no-member
|
||||
SSL_OPTS = ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3 | \
|
||||
ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 | \
|
||||
ssl.OP_CIPHER_SERVER_PREFERENCE
|
||||
if hasattr(ssl, 'OP_NO_COMPRESSION'):
|
||||
SSL_OPTS |= ssl.OP_NO_COMPRESSION
|
||||
CIPHERS = "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:" \
|
||||
"ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:" \
|
||||
"ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:" \
|
||||
"ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:" \
|
||||
"ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256"
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_SERVER_HOST = '0.0.0.0'
|
||||
@@ -300,9 +286,7 @@ class HomeAssistantHTTP(object):
|
||||
|
||||
if self.ssl_certificate:
|
||||
try:
|
||||
context = ssl.SSLContext(SSL_VERSION)
|
||||
context.options |= SSL_OPTS
|
||||
context.set_ciphers(CIPHERS)
|
||||
context = ssl_util.server_context()
|
||||
context.load_cert_chain(self.ssl_certificate, self.ssl_key)
|
||||
except OSError as error:
|
||||
_LOGGER.error("Could not read SSL certificate from %s: %s",
|
||||
|
||||
Reference in new issue
Block a user