Allow certificates with preamble before BEGIN CERTIFICATE (dcpomatic #774).
authorCarl Hetherington <cth@carlh.net>
Fri, 11 Dec 2015 14:48:37 +0000 (14:48 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 11 Dec 2015 14:48:37 +0000 (14:48 +0000)
src/certificate.cc
test/certificates_test.cc

index be0433101a4a5ecdc4fd8bcf5d94a3aaba47ce6a..36aef7f9c375c78ba83111cf65d85781be94ccbc 100644 (file)
@@ -90,8 +90,11 @@ Certificate::read_string (string cert)
        string line;
 
        /* BEGIN */
-       getline (s, line);
-       boost::algorithm::trim (line);
+       do {
+               getline (s, line);
+               boost::algorithm::trim (line);
+       } while (s.good() && line != begin_certificate);
+
        if (line != begin_certificate) {
                throw MiscError ("missing BEGIN line in certificate");
        }
index a78c88d6dcc17af84937127483e7b8ed09e62359..9592ae2f6e5f919521926eccf1d234602772aaaf 100644 (file)
@@ -91,9 +91,17 @@ BOOST_AUTO_TEST_CASE (certificates1)
 /** Check some more certificate-from-strings */
 BOOST_AUTO_TEST_CASE (certificates2)
 {
-       dcp::Certificate c (dcp::file_to_string (private_test / "CA.GDC-TECH.COM_SA2100_A14903.crt.crt"));
-       BOOST_CHECK_EQUAL (c.certificate(true), dcp::file_to_string (private_test / "CA.GDC-TECH.COM_SA2100_A14903.crt.crt.reformatted"));
+       {
+               dcp::Certificate c (dcp::file_to_string (private_test / "CA.GDC-TECH.COM_SA2100_A14903.crt.crt"));
+               BOOST_CHECK_EQUAL (c.certificate(true), dcp::file_to_string (private_test / "CA.GDC-TECH.COM_SA2100_A14903.crt.crt.reformatted"));
+       }
 
+       {
+               dcp::Certificate c (dcp::file_to_string (private_test / "usl-cert.pem"));
+               BOOST_CHECK_EQUAL (c.certificate(true), dcp::file_to_string (private_test / "usl-cert.pem.trimmed"));
+       }
+
+       BOOST_CHECK_THROW (dcp::Certificate (dcp::file_to_string (private_test / "no-begin.pem")), dcp::MiscError);
        BOOST_CHECK_THROW (dcp::Certificate ("foo"), dcp::MiscError);
 }