Remove remaining "DVSNI" wording, changing it to reference TLS-SNI-01, which it changed into. Close #1417.

Also make _get_addrs() private, since it's called only internally.
This commit is contained in:
Erik Rose
2015-11-19 13:23:07 -05:00
parent c3e1f1cf65
commit 9205b9c987
13 changed files with 98 additions and 93 deletions
-5
View File
@@ -1,5 +0,0 @@
:mod:`letsencrypt_apache.dvsni`
-------------------------------
.. automodule:: letsencrypt_apache.dvsni
:members:
@@ -0,0 +1,5 @@
:mod:`letsencrypt_apache.tls_sni_01`
-------------------------------
.. automodule:: letsencrypt_apache.tls_sni_01
:members:
@@ -22,7 +22,7 @@ from letsencrypt.plugins import common
from letsencrypt_apache import augeas_configurator from letsencrypt_apache import augeas_configurator
from letsencrypt_apache import constants from letsencrypt_apache import constants
from letsencrypt_apache import display_ops from letsencrypt_apache import display_ops
from letsencrypt_apache import dvsni from letsencrypt_apache import tls_sni_01
from letsencrypt_apache import obj from letsencrypt_apache import obj
from letsencrypt_apache import parser from letsencrypt_apache import parser
@@ -1152,15 +1152,15 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
""" """
self._chall_out.update(achalls) self._chall_out.update(achalls)
responses = [None] * len(achalls) responses = [None] * len(achalls)
apache_dvsni = dvsni.ApacheDvsni(self) authenticator = tls_sni_01.ApacheTlsSni01(self)
for i, achall in enumerate(achalls): for i, achall in enumerate(achalls):
# Currently also have dvsni hold associated index # Currently also have authenticator hold associated index
# of the challenge. This helps to put all of the responses back # of the challenge. This helps to put all of the responses back
# together when they are all complete. # together when they are all complete.
apache_dvsni.add_chall(achall, i) authenticator.add_chall(achall, i)
sni_response = apache_dvsni.perform() sni_response = authenticator.perform()
if sni_response: if sni_response:
# Must restart in order to activate the challenges. # Must restart in order to activate the challenges.
# Handled here because we may be able to load up other challenge # Handled here because we may be able to load up other challenge
@@ -1171,7 +1171,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
# place in the responses return value. All responses must be in the # place in the responses return value. All responses must be in the
# same order as the original challenges. # same order as the original challenges.
for i, resp in enumerate(sni_response): for i, resp in enumerate(sni_response):
responses[apache_dvsni.indices[i]] = resp responses[authenticator.indices[i]] = resp
return responses return responses
@@ -380,23 +380,23 @@ class TwoVhost80Test(util.ApacheTest):
self.config._add_name_vhost_if_necessary(self.vh_truth[0]) self.config._add_name_vhost_if_necessary(self.vh_truth[0])
self.assertTrue(self.config.save.called) self.assertTrue(self.config.save.called)
@mock.patch("letsencrypt_apache.configurator.dvsni.ApacheDvsni.perform") @mock.patch("letsencrypt_apache.configurator.tls_sni_01.ApacheTlsSni01.perform")
@mock.patch("letsencrypt_apache.configurator.ApacheConfigurator.restart") @mock.patch("letsencrypt_apache.configurator.ApacheConfigurator.restart")
def test_perform(self, mock_restart, mock_dvsni_perform): def test_perform(self, mock_restart, mock_perform):
# Only tests functionality specific to configurator.perform # Only tests functionality specific to configurator.perform
# Note: As more challenges are offered this will have to be expanded # Note: As more challenges are offered this will have to be expanded
account_key, achall1, achall2 = self.get_achalls() account_key, achall1, achall2 = self.get_achalls()
dvsni_ret_val = [ expected = [
achall1.response(account_key), achall1.response(account_key),
achall2.response(account_key), achall2.response(account_key),
] ]
mock_dvsni_perform.return_value = dvsni_ret_val mock_perform.return_value = expected
responses = self.config.perform([achall1, achall2]) responses = self.config.perform([achall1, achall2])
self.assertEqual(mock_dvsni_perform.call_count, 1) self.assertEqual(mock_perform.call_count, 1)
self.assertEqual(responses, dvsni_ret_val) self.assertEqual(responses, expected)
self.assertEqual(mock_restart.call_count, 1) self.assertEqual(mock_restart.call_count, 1)
@@ -1,4 +1,4 @@
"""Test for letsencrypt_apache.dvsni.""" """Test for letsencrypt_apache.tls_sni_01."""
import unittest import unittest
import shutil import shutil
@@ -10,21 +10,21 @@ from letsencrypt_apache import obj
from letsencrypt_apache.tests import util from letsencrypt_apache.tests import util
class DvsniPerformTest(util.ApacheTest): class TlsSniPerformTest(util.ApacheTest):
"""Test the ApacheDVSNI challenge.""" """Test the ApacheTlsSni01 challenge."""
auth_key = common_test.TLSSNI01Test.auth_key auth_key = common_test.TLSSNI01Test.auth_key
achalls = common_test.TLSSNI01Test.achalls achalls = common_test.TLSSNI01Test.achalls
def setUp(self): # pylint: disable=arguments-differ def setUp(self): # pylint: disable=arguments-differ
super(DvsniPerformTest, self).setUp() super(TlsSniPerformTest, self).setUp()
config = util.get_apache_configurator( config = util.get_apache_configurator(
self.config_path, self.config_dir, self.work_dir) self.config_path, self.config_dir, self.work_dir)
config.config.tls_sni_01_port = 443 config.config.tls_sni_01_port = 443
from letsencrypt_apache import dvsni from letsencrypt_apache import tls_sni_01
self.sni = dvsni.ApacheDvsni(config) self.sni = tls_sni_01.ApacheTlsSni01(config)
def tearDown(self): def tearDown(self):
shutil.rmtree(self.temp_dir) shutil.rmtree(self.temp_dir)
@@ -121,7 +121,7 @@ class DvsniPerformTest(util.ApacheTest):
names = vhost.get_names() names = vhost.get_names()
self.assertTrue(names in z_domains) self.assertTrue(names in z_domains)
def test_get_dvsni_addrs_default(self): def test_get_addrs_default(self):
self.sni.configurator.choose_vhost = mock.Mock( self.sni.configurator.choose_vhost = mock.Mock(
return_value=obj.VirtualHost( return_value=obj.VirtualHost(
"path", "aug_path", set([obj.Addr.fromstring("_default_:443")]), "path", "aug_path", set([obj.Addr.fromstring("_default_:443")]),
@@ -130,7 +130,7 @@ class DvsniPerformTest(util.ApacheTest):
self.assertEqual( self.assertEqual(
set([obj.Addr.fromstring("*:443")]), set([obj.Addr.fromstring("*:443")]),
self.sni.get_dvsni_addrs(self.achalls[0])) self.sni._get_addrs(self.achalls[0])) # pylint: disable=protected-access
if __name__ == "__main__": if __name__ == "__main__":
@@ -1,4 +1,5 @@
"""ApacheDVSNI""" """A TLS-SNI-01 authenticator for Apache"""
import os import os
from letsencrypt.plugins import common from letsencrypt.plugins import common
@@ -7,22 +8,22 @@ from letsencrypt_apache import obj
from letsencrypt_apache import parser from letsencrypt_apache import parser
class ApacheDvsni(common.TLSSNI01): class ApacheTlsSni01(common.TLSSNI01):
"""Class performs DVSNI challenges within the Apache configurator. """Class that performs TLS-SNI-01 challenges within the Apache configurator
:ivar configurator: ApacheConfigurator object :ivar configurator: ApacheConfigurator object
:type configurator: :class:`~apache.configurator.ApacheConfigurator` :type configurator: :class:`~apache.configurator.ApacheConfigurator`
:ivar list achalls: Annotated tls-sni-01 :ivar list achalls: Annotated TLS-SNI-01
(`.KeyAuthorizationAnnotatedChallenge`) challenges. (`.KeyAuthorizationAnnotatedChallenge`) challenges.
:param list indices: Meant to hold indices of challenges in a :param list indices: Meant to hold indices of challenges in a
larger array. ApacheDvsni is capable of solving many challenges larger array. ApacheTlsSni01 is capable of solving many challenges
at once which causes an indexing issue within ApacheConfigurator at once which causes an indexing issue within ApacheConfigurator
who must return all responses in order. Imagine ApacheConfigurator who must return all responses in order. Imagine ApacheConfigurator
maintaining state about where all of the http-01 Challenges, maintaining state about where all of the http-01 Challenges,
Dvsni Challenges belong in the response array. This is an optional TLS-SNI-01 Challenges belong in the response array. This is an
utility. optional utility.
:param str challenge_conf: location of the challenge config file :param str challenge_conf: location of the challenge config file
@@ -46,14 +47,14 @@ class ApacheDvsni(common.TLSSNI01):
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ApacheDvsni, self).__init__(*args, **kwargs) super(ApacheTlsSni01, self).__init__(*args, **kwargs)
self.challenge_conf = os.path.join( self.challenge_conf = os.path.join(
self.configurator.conf("server-root"), self.configurator.conf("server-root"),
"le_dvsni_cert_challenge.conf") "le_tls_sni_01_cert_challenge.conf")
def perform(self): def perform(self):
"""Perform a DVSNI challenge.""" """Perform a TLS-SNI-01 challenge."""
if not self.achalls: if not self.achalls:
return [] return []
# Save any changes to the configuration as a precaution # Save any changes to the configuration as a precaution
@@ -71,8 +72,8 @@ class ApacheDvsni(common.TLSSNI01):
responses.append(self._setup_challenge_cert(achall)) responses.append(self._setup_challenge_cert(achall))
# Setup the configuration # Setup the configuration
dvsni_addrs = self._mod_config() addrs = self._mod_config()
self.configurator.make_addrs_sni_ready(dvsni_addrs) self.configurator.make_addrs_sni_ready(addrs)
# Save reversible changes # Save reversible changes
self.configurator.save("SNI Challenge", True) self.configurator.save("SNI Challenge", True)
@@ -84,16 +85,16 @@ class ApacheDvsni(common.TLSSNI01):
Result: Apache config includes virtual servers for issued challs Result: Apache config includes virtual servers for issued challs
:returns: All DVSNI addresses used :returns: All TLS-SNI-01 addresses used
:rtype: set :rtype: set
""" """
dvsni_addrs = set() addrs = set()
config_text = "<IfModule mod_ssl.c>\n" config_text = "<IfModule mod_ssl.c>\n"
for achall in self.achalls: for achall in self.achalls:
achall_addrs = self.get_dvsni_addrs(achall) achall_addrs = self._get_addrs(achall)
dvsni_addrs.update(achall_addrs) addrs.update(achall_addrs)
config_text += self._get_config_text(achall, achall_addrs) config_text += self._get_config_text(achall, achall_addrs)
@@ -106,30 +107,30 @@ class ApacheDvsni(common.TLSSNI01):
with open(self.challenge_conf, "w") as new_conf: with open(self.challenge_conf, "w") as new_conf:
new_conf.write(config_text) new_conf.write(config_text)
return dvsni_addrs return addrs
def get_dvsni_addrs(self, achall): def _get_addrs(self, achall):
"""Return the Apache addresses needed for DVSNI.""" """Return the Apache addresses needed for TLS-SNI-01."""
vhost = self.configurator.choose_vhost(achall.domain) vhost = self.configurator.choose_vhost(achall.domain)
# TODO: Checkout _default_ rules. # TODO: Checkout _default_ rules.
dvsni_addrs = set() addrs = set()
default_addr = obj.Addr(("*", str( default_addr = obj.Addr(("*", str(
self.configurator.config.tls_sni_01_port))) self.configurator.config.tls_sni_01_port)))
for addr in vhost.addrs: for addr in vhost.addrs:
if "_default_" == addr.get_addr(): if "_default_" == addr.get_addr():
dvsni_addrs.add(default_addr) addrs.add(default_addr)
else: else:
dvsni_addrs.add( addrs.add(
addr.get_sni_addr(self.configurator.config.tls_sni_01_port)) addr.get_sni_addr(self.configurator.config.tls_sni_01_port))
return dvsni_addrs return addrs
def _conf_include_check(self, main_config): def _conf_include_check(self, main_config):
"""Adds DVSNI challenge conf file into configuration. """Add TLS-SNI-01 challenge conf file into configuration.
Adds DVSNI challenge include file if it does not already exist Adds TLS-SNI-01 challenge include file if it does not already exist
within mainConfig within mainConfig
:param str main_config: file path to main user apache config file :param str main_config: file path to main user apache config file
@@ -146,7 +147,7 @@ class ApacheDvsni(common.TLSSNI01):
"""Chocolate virtual server configuration text """Chocolate virtual server configuration text
:param .KeyAuthorizationAnnotatedChallenge achall: Annotated :param .KeyAuthorizationAnnotatedChallenge achall: Annotated
DVSNI challenge. TLS-SNI-01 challenge.
:param list ip_addrs: addresses of challenged domain :param list ip_addrs: addresses of challenged domain
:class:`list` of type `~.obj.Addr` :class:`list` of type `~.obj.Addr`
@@ -157,7 +158,7 @@ class ApacheDvsni(common.TLSSNI01):
""" """
ips = " ".join(str(i) for i in ip_addrs) ips = " ".join(str(i) for i in ip_addrs)
document_root = os.path.join( document_root = os.path.join(
self.configurator.config.work_dir, "dvsni_page/") self.configurator.config.work_dir, "tls_sni_01_page/")
# TODO: Python docs is not clear how mutliline string literal # TODO: Python docs is not clear how mutliline string literal
# newlines are parsed on different platforms. At least on # newlines are parsed on different platforms. At least on
# Linux (Debian sid), when source file uses CRLF, Python still # Linux (Debian sid), when source file uses CRLF, Python still
-5
View File
@@ -1,5 +0,0 @@
:mod:`letsencrypt_nginx.dvsni`
------------------------------
.. automodule:: letsencrypt_nginx.dvsni
:members:
@@ -0,0 +1,5 @@
:mod:`letsencrypt_nginx.tls_sni_01`
------------------------------
.. automodule:: letsencrypt_nginx.tls_sni_01
:members:
@@ -24,7 +24,7 @@ from letsencrypt import reverter
from letsencrypt.plugins import common from letsencrypt.plugins import common
from letsencrypt_nginx import constants from letsencrypt_nginx import constants
from letsencrypt_nginx import dvsni from letsencrypt_nginx import tls_sni_01
from letsencrypt_nginx import obj from letsencrypt_nginx import obj
from letsencrypt_nginx import parser from letsencrypt_nginx import parser
@@ -573,15 +573,15 @@ class NginxConfigurator(common.Plugin):
""" """
self._chall_out += len(achalls) self._chall_out += len(achalls)
responses = [None] * len(achalls) responses = [None] * len(achalls)
nginx_dvsni = dvsni.NginxDvsni(self) authenticator = tls_sni_01.NginxTlsSni01(self)
for i, achall in enumerate(achalls): for i, achall in enumerate(achalls):
# Currently also have dvsni hold associated index # Currently also have authenticator hold associated index
# of the challenge. This helps to put all of the responses back # of the challenge. This helps to put all of the responses back
# together when they are all complete. # together when they are all complete.
nginx_dvsni.add_chall(achall, i) authenticator.add_chall(achall, i)
sni_response = nginx_dvsni.perform() sni_response = authenticator.perform()
# Must restart in order to activate the challenges. # Must restart in order to activate the challenges.
# Handled here because we may be able to load up other challenge types # Handled here because we may be able to load up other challenge types
self.restart() self.restart()
@@ -590,7 +590,7 @@ class NginxConfigurator(common.Plugin):
# in the responses return value. All responses must be in the same order # in the responses return value. All responses must be in the same order
# as the original challenges. # as the original challenges.
for i, resp in enumerate(sni_response): for i, resp in enumerate(sni_response):
responses[nginx_dvsni.indices[i]] = resp responses[authenticator.indices[i]] = resp
return responses return responses
@@ -212,9 +212,9 @@ class NginxConfiguratorTest(util.NginxTest):
('/etc/nginx/fullchain.pem', '/etc/nginx/key.pem', nginx_conf), ('/etc/nginx/fullchain.pem', '/etc/nginx/key.pem', nginx_conf),
]), self.config.get_all_certs_keys()) ]), self.config.get_all_certs_keys())
@mock.patch("letsencrypt_nginx.configurator.dvsni.NginxDvsni.perform") @mock.patch("letsencrypt_nginx.configurator.tls_sni_01.NginxTlsSni01.perform")
@mock.patch("letsencrypt_nginx.configurator.NginxConfigurator.restart") @mock.patch("letsencrypt_nginx.configurator.NginxConfigurator.restart")
def test_perform(self, mock_restart, mock_dvsni_perform): def test_perform(self, mock_restart, mock_perform):
# Only tests functionality specific to configurator.perform # Only tests functionality specific to configurator.perform
# Note: As more challenges are offered this will have to be expanded # Note: As more challenges are offered this will have to be expanded
achall1 = achallenges.KeyAuthorizationAnnotatedChallenge( achall1 = achallenges.KeyAuthorizationAnnotatedChallenge(
@@ -230,16 +230,16 @@ class NginxConfiguratorTest(util.NginxTest):
status=messages.Status("pending"), status=messages.Status("pending"),
), domain="example.com", account_key=self.rsa512jwk) ), domain="example.com", account_key=self.rsa512jwk)
dvsni_ret_val = [ expected = [
achall1.response(self.rsa512jwk), achall1.response(self.rsa512jwk),
achall2.response(self.rsa512jwk), achall2.response(self.rsa512jwk),
] ]
mock_dvsni_perform.return_value = dvsni_ret_val mock_perform.return_value = expected
responses = self.config.perform([achall1, achall2]) responses = self.config.perform([achall1, achall2])
self.assertEqual(mock_dvsni_perform.call_count, 1) self.assertEqual(mock_perform.call_count, 1)
self.assertEqual(responses, dvsni_ret_val) self.assertEqual(responses, expected)
self.assertEqual(mock_restart.call_count, 1) self.assertEqual(mock_restart.call_count, 1)
@mock.patch("letsencrypt_nginx.configurator.subprocess.Popen") @mock.patch("letsencrypt_nginx.configurator.subprocess.Popen")
@@ -1,4 +1,4 @@
"""Test for letsencrypt_nginx.dvsni.""" """Tests for letsencrypt_nginx.tls_sni_01"""
import unittest import unittest
import shutil import shutil
@@ -16,8 +16,8 @@ from letsencrypt_nginx import obj
from letsencrypt_nginx.tests import util from letsencrypt_nginx.tests import util
class DvsniPerformTest(util.NginxTest): class TlsSniPerformTest(util.NginxTest):
"""Test the NginxDVSNI challenge.""" """Test the NginxTlsSni01 challenge."""
account_key = common_test.TLSSNI01Test.auth_key account_key = common_test.TLSSNI01Test.auth_key
achalls = [ achalls = [
@@ -42,13 +42,13 @@ class DvsniPerformTest(util.NginxTest):
] ]
def setUp(self): def setUp(self):
super(DvsniPerformTest, self).setUp() super(TlsSniPerformTest, self).setUp()
config = util.get_nginx_configurator( config = util.get_nginx_configurator(
self.config_path, self.config_dir, self.work_dir) self.config_path, self.config_dir, self.work_dir)
from letsencrypt_nginx import dvsni from letsencrypt_nginx import tls_sni_01
self.sni = dvsni.NginxDvsni(config) self.sni = tls_sni_01.NginxTlsSni01(config)
def tearDown(self): def tearDown(self):
shutil.rmtree(self.temp_dir) shutil.rmtree(self.temp_dir)
@@ -1,4 +1,5 @@
"""NginxDVSNI""" """A TLS-SNI-01 authenticator for Nginx"""
import itertools import itertools
import logging import logging
import os import os
@@ -13,31 +14,32 @@ from letsencrypt_nginx import nginxparser
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class NginxDvsni(common.TLSSNI01): class NginxTlsSni01(common.TLSSNI01):
"""Class performs DVSNI challenges within the Nginx configurator. """TLS-SNI-01 authenticator for Nginx
:ivar configurator: NginxConfigurator object :ivar configurator: NginxConfigurator object
:type configurator: :class:`~nginx.configurator.NginxConfigurator` :type configurator: :class:`~nginx.configurator.NginxConfigurator`
:ivar list achalls: Annotated :class:`~letsencrypt.achallenges.DVSNI` :ivar list achalls: Annotated
challenges. class:`~letsencrypt.achallenges.KeyAuthorizationAnnotatedChallenge`
challenges
:param list indices: Meant to hold indices of challenges in a :param list indices: Meant to hold indices of challenges in a
larger array. NginxDvsni is capable of solving many challenges larger array. NginxTlsSni01 is capable of solving many challenges
at once which causes an indexing issue within NginxConfigurator at once which causes an indexing issue within NginxConfigurator
who must return all responses in order. Imagine NginxConfigurator who must return all responses in order. Imagine NginxConfigurator
maintaining state about where all of the http-01 Challenges, maintaining state about where all of the http-01 Challenges,
Dvsni Challenges belong in the response array. This is an optional TLS-SNI-01 Challenges belong in the response array. This is an
utility. optional utility.
:param str challenge_conf: location of the challenge config file :param str challenge_conf: location of the challenge config file
""" """
def perform(self): def perform(self):
"""Perform a DVSNI challenge on Nginx. """Perform a challenge on Nginx.
:returns: list of :class:`letsencrypt.acme.challenges.DVSNIResponse` :returns: list of :class:`letsencrypt.acme.challenges.TLSSNI01Response`
:rtype: list :rtype: list
""" """
@@ -84,7 +86,8 @@ class NginxDvsni(common.TLSSNI01):
:class:`letsencrypt_nginx.obj.Addr` to apply :class:`letsencrypt_nginx.obj.Addr` to apply
:raises .MisconfigurationError: :raises .MisconfigurationError:
Unable to find a suitable HTTP block to include DVSNI hosts. Unable to find a suitable HTTP block in which to include
authenticator hosts.
""" """
# Add the 'include' statement for the challenges if it doesn't exist # Add the 'include' statement for the challenges if it doesn't exist
@@ -110,8 +113,8 @@ class NginxDvsni(common.TLSSNI01):
break break
if not included: if not included:
raise errors.MisconfigurationError( raise errors.MisconfigurationError(
'LetsEncrypt could not find an HTTP block to include DVSNI ' 'LetsEncrypt could not find an HTTP block to include '
'challenges in %s.' % root) 'TLS-SNI-01 challenges in %s.' % root)
config = [self._make_server_block(pair[0], pair[1]) config = [self._make_server_block(pair[0], pair[1])
for pair in itertools.izip(self.achalls, ll_addrs)] for pair in itertools.izip(self.achalls, ll_addrs)]
@@ -123,10 +126,11 @@ class NginxDvsni(common.TLSSNI01):
nginxparser.dump(config, new_conf) nginxparser.dump(config, new_conf)
def _make_server_block(self, achall, addrs): def _make_server_block(self, achall, addrs):
"""Creates a server block for a DVSNI challenge. """Creates a server block for a challenge.
:param achall: Annotated DVSNI challenge. :param achall: Annotated TLS-SNI-01 challenge
:type achall: :class:`letsencrypt.achallenges.DVSNI` :type achall:
:class:`letsencrypt.achallenges.KeyAuthorizationAnnotatedChallenge`
:param list addrs: addresses of challenged domain :param list addrs: addresses of challenged domain
:class:`list` of type :class:`~nginx.obj.Addr` :class:`list` of type :class:`~nginx.obj.Addr`
@@ -136,7 +140,7 @@ class NginxDvsni(common.TLSSNI01):
""" """
document_root = os.path.join( document_root = os.path.join(
self.configurator.config.work_dir, "dvsni_page") self.configurator.config.work_dir, "tls_sni_01_page")
block = [['listen', str(addr)] for addr in addrs] block = [['listen', str(addr)] for addr in addrs]
+1 -1
View File
@@ -136,7 +136,7 @@ class Addr(object):
class TLSSNI01(object): class TLSSNI01(object):
"""Class that performs tls-sni-01 challenges.""" """Abstract base for TLS-SNI-01 authenticators"""
def __init__(self, configurator): def __init__(self, configurator):
self.configurator = configurator self.configurator = configurator