From 541d9252f6605b4b5ce6b5782753df80a65067dd Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Mon, 13 Jul 2015 21:04:34 +0000 Subject: [PATCH] allow PEM files to have non-Unix line endings --- management/status_checks.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/management/status_checks.py b/management/status_checks.py index 8a31a2f2..7c89b30f 100755 --- a/management/status_checks.py +++ b/management/status_checks.py @@ -746,7 +746,7 @@ def check_certificate(domain, ssl_certificate, ssl_private_key, warn_if_expiring def load_cert_chain(pemfile): # A certificate .pem file may contain a chain of certificates. # Load the file and split them apart. - re_pem = rb"(-+BEGIN (?:.+)-+[\r\n](?:[A-Za-z0-9+/=]{1,64}[\r\n])+-+END (?:.+)-+[\r\n])" + re_pem = rb"(-+BEGIN (?:.+)-+[\r\n]+(?:[A-Za-z0-9+/=]{1,64}[\r\n]+)+-+END (?:.+)-+[\r\n]+)" with open(pemfile, "rb") as f: pem = f.read() + b"\n" # ensure trailing newline pemblocks = re.findall(re_pem, pem) @@ -760,7 +760,7 @@ def load_pem(pem): from cryptography.x509 import load_pem_x509_certificate from cryptography.hazmat.primitives import serialization from cryptography.hazmat.backends import default_backend - pem_type = re.match(b"-+BEGIN (.*?)-+\n", pem) + pem_type = re.match(b"-+BEGIN (.*?)-+[\r\n]", pem) if pem_type is None: raise ValueError("File is not a valid PEM-formatted file.") pem_type = pem_type.group(1)