From 5d11691de77d117b58f722857d79a04e2f1e278d Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Tue, 27 Oct 2015 22:19:21 +0000 Subject: [PATCH] Standalone verifies ports for suported challenges only (fixes #1149). --- letsencrypt/plugins/standalone.py | 12 ++++++++++-- letsencrypt/plugins/standalone_test.py | 13 +++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/letsencrypt/plugins/standalone.py b/letsencrypt/plugins/standalone.py index d4dddc7f6..5d2dafc7d 100644 --- a/letsencrypt/plugins/standalone.py +++ b/letsencrypt/plugins/standalone.py @@ -181,6 +181,15 @@ class Authenticator(common.Plugin): return set(challenges.Challenge.TYPES[name] for name in self.conf("supported-challenges").split(",")) + @property + def _necessary_ports(self): + necessary_ports = set() + if challenges.SimpleHTTP in self.supported_challenges: + necessary_ports.add(self.config.simple_http_port) + if challenges.DVSNI in self.supported_challenges: + necessary_ports.add(self.config.dvsni_port) + return necessary_ports + def more_info(self): # pylint: disable=missing-docstring return self.__doc__ @@ -194,8 +203,7 @@ class Authenticator(common.Plugin): return chall_pref def perform(self, achalls): # pylint: disable=missing-docstring - if any(util.already_listening(port) for port in - (self.config.dvsni_port, self.config.simple_http_port)): + if any(util.already_listening(port) for port in self._necessary_ports): raise errors.MisconfigurationError( "At least one of the (possibly) required ports is " "already taken.") diff --git a/letsencrypt/plugins/standalone_test.py b/letsencrypt/plugins/standalone_test.py index 0ccdccb1f..3a6941be8 100644 --- a/letsencrypt/plugins/standalone_test.py +++ b/letsencrypt/plugins/standalone_test.py @@ -107,10 +107,15 @@ class AuthenticatorTest(unittest.TestCase): set([challenges.DVSNI, challenges.SimpleHTTP])) @mock.patch("letsencrypt.plugins.standalone.util") - def test_perform_misconfiguration(self, mock_util): - mock_util.already_listening.return_value = True - self.assertRaises(errors.MisconfigurationError, self.auth.perform, []) - mock_util.already_listening.assert_called_once_with(1234) + def test_perform_alredy_listening(self, mock_util): + for chall, port in ((challenges.DVSNI.typ, 1234), + (challenges.SimpleHTTP.typ, 4321)): + mock_util.already_listening.return_value = True + self.config.standalone_supported_challenges = chall + self.assertRaises( + errors.MisconfigurationError, self.auth.perform, []) + mock_util.already_listening.assert_called_once_with(port) + mock_util.already_listening.reset_mock() @mock.patch("letsencrypt.plugins.standalone.zope.component.getUtility") def test_perform(self, unused_mock_get_utility):