summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-12-11 14:48:37 +0000
committerCarl Hetherington <cth@carlh.net>2015-12-11 14:48:37 +0000
commitb9e663597463ecfe74ac0a67263425264ea49931 (patch)
treece3abb3ab9615cde48b54541c44801572ffb70fe
parent3afe04f24a99c95798718cc7dc992c4e636be508 (diff)
Allow certificates with preamble before BEGIN CERTIFICATE (dcpomatic #774).
-rw-r--r--src/certificate.cc7
-rw-r--r--test/certificates_test.cc12
2 files changed, 15 insertions, 4 deletions
diff --git a/src/certificate.cc b/src/certificate.cc
index be043310..36aef7f9 100644
--- a/src/certificate.cc
+++ b/src/certificate.cc
@@ -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");
}
diff --git a/test/certificates_test.cc b/test/certificates_test.cc
index a78c88d6..9592ae2f 100644
--- a/test/certificates_test.cc
+++ b/test/certificates_test.cc
@@ -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);
}