From f5a6bb389ec5a2fb1806e15a0a365133282f6cb8 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Wed, 25 Mar 2015 10:21:01 +0000 Subject: [PATCH] Fix #316 --- letsencrypt/client/apache/dvsni.py | 40 +++++++++++++------ letsencrypt/client/tests/apache/dvsni_test.py | 2 +- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/letsencrypt/client/apache/dvsni.py b/letsencrypt/client/apache/dvsni.py index 033bcde20..29ae57308 100644 --- a/letsencrypt/client/apache/dvsni.py +++ b/letsencrypt/client/apache/dvsni.py @@ -26,6 +26,23 @@ class ApacheDvsni(object): :param str challenge_conf: location of the challenge config file """ + + VHOST_TEMPLATE = """\ + + ServerName {server_name} + UseCanonicalName on + SSLStrictSNIVHostCheck on + + LimitRequestBody 1048576 + + Include {ssl_options_conf_path} + SSLCertificateFile {cert_path} + SSLCertificateKeyFile {key_path} + + DocumentRoot {document_root} + + +""" def __init__(self, configurator): self.configurator = configurator self.achalls = [] @@ -160,19 +177,16 @@ class ApacheDvsni(object): ips = " ".join(str(i) for i in ip_addrs) document_root = os.path.join( self.configurator.config.config_dir, "dvsni_page/") - return ("{0}" - "ServerName " + achall.nonce_domain + "{0}" - "UseCanonicalName on{0}" - "SSLStrictSNIVHostCheck on{0}" - "{0}" - "LimitRequestBody 1048576{0}" - "{0}" - "Include " + self.configurator.parser.loc["ssl_options"] + "{0}" - "SSLCertificateFile " + self.get_cert_file(achall) + "{0}" - "SSLCertificateKeyFile " + achall.key.file + "{0}" - "{0}" - "DocumentRoot " + document_root + "{0}" - "{0}{0}".format(os.linesep)) + # TODO: Python docs is not clear how mutliline string literal + # newlines are parsed on different platforms. At least on + # Linux (Debian sid), when source file uses CLRF, Python still + # parses it as '\n'... c.f.: + # https://docs.python.org/2.7/reference/lexical_analysis.html + return self.VHOST_TEMPLATE.format( + vhost=ips, server_name=achall.nonce_domain, + ssl_options_conf_path=self.configurator.parser.loc["ssl_options"], + cert_path=self.get_cert_file(achall), key_path=achall.key.file, + document_root=document_root).replace('\n', os.linesep) def get_cert_file(self, achall): """Returns standardized name for challenge certificate. diff --git a/letsencrypt/client/tests/apache/dvsni_test.py b/letsencrypt/client/tests/apache/dvsni_test.py index 384e426bb..110916e94 100644 --- a/letsencrypt/client/tests/apache/dvsni_test.py +++ b/letsencrypt/client/tests/apache/dvsni_test.py @@ -60,7 +60,7 @@ class DvsniPerformTest(util.ApacheTest): def test_perform0(self): resp = self.sni.perform() - self.assertTrue(resp is None) + self.assertTrue(len(resp) == 0) def test_setup_challenge_cert(self): # This is a helper function that can be used for handling