mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 08:45:22 +02:00
committed by
Adrien Ferrand
parent
f4f16605ed
commit
4b488614cf
@@ -11,6 +11,7 @@ Certbot adheres to [Semantic Versioning](https://semver.org/).
|
||||
### Changed
|
||||
|
||||
* Certbot's `config_changes` subcommand has been removed
|
||||
* `certbot.plugins.common.TLSSNI01` has been removed.
|
||||
* The functions `certbot.client.view_config_changes`,
|
||||
`certbot.main.config_changes`,
|
||||
`certbot.plugins.common.Installer.view_config_changes`, and
|
||||
|
||||
@@ -6,7 +6,6 @@ import sys
|
||||
import tempfile
|
||||
import warnings
|
||||
|
||||
import OpenSSL
|
||||
import pkg_resources
|
||||
import zope.interface
|
||||
|
||||
@@ -20,7 +19,6 @@ from certbot import crypto_util
|
||||
from certbot import errors
|
||||
from certbot import interfaces
|
||||
from certbot import reverter
|
||||
from certbot import util
|
||||
from certbot.compat import os
|
||||
from certbot.compat import filesystem
|
||||
from certbot.plugins.storage import PluginStorage
|
||||
@@ -349,63 +347,6 @@ class ChallengePerformer(object):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class TLSSNI01(ChallengePerformer):
|
||||
# pylint: disable=abstract-method
|
||||
"""Abstract base for TLS-SNI-01 challenge performers"""
|
||||
|
||||
def __init__(self, configurator):
|
||||
super(TLSSNI01, self).__init__(configurator)
|
||||
self.challenge_conf = os.path.join(
|
||||
configurator.config.config_dir, "le_tls_sni_01_cert_challenge.conf")
|
||||
# self.completed = 0
|
||||
|
||||
def get_cert_path(self, achall):
|
||||
"""Returns standardized name for challenge certificate.
|
||||
|
||||
:param .KeyAuthorizationAnnotatedChallenge achall: Annotated
|
||||
tls-sni-01 challenge.
|
||||
|
||||
:returns: certificate file name
|
||||
:rtype: str
|
||||
|
||||
"""
|
||||
return os.path.join(self.configurator.config.work_dir,
|
||||
achall.chall.encode("token") + ".crt")
|
||||
|
||||
def get_key_path(self, achall):
|
||||
"""Get standardized path to challenge key."""
|
||||
return os.path.join(self.configurator.config.work_dir,
|
||||
achall.chall.encode("token") + '.pem')
|
||||
|
||||
def get_z_domain(self, achall):
|
||||
"""Returns z_domain (SNI) name for the challenge."""
|
||||
return achall.response(achall.account_key).z_domain.decode("utf-8")
|
||||
|
||||
def _setup_challenge_cert(self, achall, cert_key=None):
|
||||
|
||||
"""Generate and write out challenge certificate."""
|
||||
cert_path = self.get_cert_path(achall)
|
||||
key_path = self.get_key_path(achall)
|
||||
# Register the path before you write out the file
|
||||
self.configurator.reverter.register_file_creation(True, key_path)
|
||||
self.configurator.reverter.register_file_creation(True, cert_path)
|
||||
|
||||
response, (cert, key) = achall.response_and_validation(
|
||||
cert_key=cert_key)
|
||||
cert_pem = OpenSSL.crypto.dump_certificate(
|
||||
OpenSSL.crypto.FILETYPE_PEM, cert)
|
||||
key_pem = OpenSSL.crypto.dump_privatekey(
|
||||
OpenSSL.crypto.FILETYPE_PEM, key)
|
||||
|
||||
# Write out challenge cert and key
|
||||
with open(cert_path, "wb") as cert_chall_fd:
|
||||
cert_chall_fd.write(cert_pem)
|
||||
with util.safe_open(key_path, 'wb', chmod=0o400) as key_file:
|
||||
key_file.write(key_pem)
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def install_version_controlled_file(dest_path, digest_path, src_path, all_hashes):
|
||||
"""Copy a file into an active location (likely the system's config dir) if required.
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
"""Tests for certbot.plugins.common."""
|
||||
import functools
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import OpenSSL
|
||||
import josepy as jose
|
||||
import mock
|
||||
|
||||
@@ -19,16 +17,10 @@ from certbot.tests import acme_util
|
||||
from certbot.tests import util as test_util
|
||||
|
||||
AUTH_KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key.pem"))
|
||||
ACHALLS = [
|
||||
achallenges.KeyAuthorizationAnnotatedChallenge(
|
||||
challb=acme_util.chall_to_challb(
|
||||
challenges.TLSSNI01(token=b'token1'), "pending"),
|
||||
domain="encryption-example.demo", account_key=AUTH_KEY),
|
||||
achallenges.KeyAuthorizationAnnotatedChallenge(
|
||||
challb=acme_util.chall_to_challb(
|
||||
challenges.TLSSNI01(token=b'token2'), "pending"),
|
||||
domain="certbot.demo", account_key=AUTH_KEY),
|
||||
]
|
||||
ACHALL = achallenges.KeyAuthorizationAnnotatedChallenge(
|
||||
challb=acme_util.chall_to_challb(challenges.HTTP01(token=b'token1'),
|
||||
"pending"),
|
||||
domain="encryption-example.demo", account_key=AUTH_KEY)
|
||||
|
||||
class NamespaceFunctionsTest(unittest.TestCase):
|
||||
"""Tests for certbot.plugins.common.*_namespace functions."""
|
||||
@@ -276,7 +268,7 @@ class ChallengePerformerTest(unittest.TestCase):
|
||||
self.performer = ChallengePerformer(configurator)
|
||||
|
||||
def test_add_chall(self):
|
||||
self.performer.add_chall(ACHALLS[0], 0)
|
||||
self.performer.add_chall(ACHALL, 0)
|
||||
self.assertEqual(1, len(self.performer.achalls))
|
||||
self.assertEqual([0], self.performer.indices)
|
||||
|
||||
@@ -284,63 +276,6 @@ class ChallengePerformerTest(unittest.TestCase):
|
||||
self.assertRaises(NotImplementedError, self.performer.perform)
|
||||
|
||||
|
||||
class TLSSNI01Test(unittest.TestCase):
|
||||
"""Tests for certbot.plugins.common.TLSSNI01."""
|
||||
|
||||
def setUp(self):
|
||||
self.tempdir = tempfile.mkdtemp()
|
||||
configurator = mock.MagicMock()
|
||||
configurator.config.config_dir = os.path.join(self.tempdir, "config")
|
||||
configurator.config.work_dir = os.path.join(self.tempdir, "work")
|
||||
|
||||
from certbot.plugins.common import TLSSNI01
|
||||
self.sni = TLSSNI01(configurator=configurator)
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.tempdir)
|
||||
|
||||
def test_setup_challenge_cert(self):
|
||||
# This is a helper function that can be used for handling
|
||||
# open context managers more elegantly. It avoids dealing with
|
||||
# __enter__ and __exit__ calls.
|
||||
# http://www.voidspace.org.uk/python/mock/helpers.html#mock.mock_open
|
||||
mock_open, mock_safe_open = mock.mock_open(), mock.mock_open()
|
||||
|
||||
response = challenges.TLSSNI01Response()
|
||||
achall = mock.MagicMock()
|
||||
achall.chall.encode.return_value = "token"
|
||||
key = test_util.load_pyopenssl_private_key("rsa512_key.pem")
|
||||
achall.response_and_validation.return_value = (
|
||||
response, (test_util.load_cert("cert_512.pem"), key))
|
||||
|
||||
with mock.patch("certbot.plugins.common.open",
|
||||
mock_open, create=True):
|
||||
with mock.patch("certbot.plugins.common.util.safe_open",
|
||||
mock_safe_open):
|
||||
# pylint: disable=protected-access
|
||||
self.assertEqual(response, self.sni._setup_challenge_cert(
|
||||
achall, "randomS1"))
|
||||
|
||||
# pylint: disable=no-member
|
||||
mock_open.assert_called_once_with(self.sni.get_cert_path(achall), "wb")
|
||||
mock_open.return_value.write.assert_called_once_with(
|
||||
test_util.load_vector("cert_512.pem"))
|
||||
mock_safe_open.assert_called_once_with(
|
||||
self.sni.get_key_path(achall), "wb", chmod=0o400)
|
||||
mock_safe_open.return_value.write.assert_called_once_with(
|
||||
OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key))
|
||||
|
||||
def test_get_z_domain(self):
|
||||
achall = ACHALLS[0]
|
||||
self.assertEqual(self.sni.get_z_domain(achall),
|
||||
achall.response(achall.account_key).z_domain.decode("utf-8"))
|
||||
|
||||
def test_warning(self):
|
||||
with mock.patch('certbot.plugins.common.warnings.warn') as mock_warn:
|
||||
from certbot.plugins.common import TLSSNI01 # pylint: disable=unused-variable
|
||||
self.assertTrue(mock_warn.call_args[0][0].startswith('TLSSNI01'))
|
||||
|
||||
|
||||
class InstallVersionControlledFileTest(test_util.TempDirTestCase):
|
||||
"""Tests for certbot.plugins.common.install_version_controlled_file."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user