summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-05-28 15:31:35 +0100
committerCarl Hetherington <cth@carlh.net>2014-05-28 15:31:35 +0100
commit2ea95f432a4c12271354d2fa136c0832704e9244 (patch)
treee2f234203f4b65e40e94a303e10940e3aae1952e
parent0b3a3e461284b91e774f44c48f6f2f59b2a5832f (diff)
Modify KDM code to take a CPL disk file instead of a whole CPL object.
-rw-r--r--src/kdm.cc63
-rw-r--r--src/kdm.h5
-rw-r--r--src/parse/cpl.cc2
-rw-r--r--src/parse/cpl.h2
-rw-r--r--test/encryption_test.cc5
-rw-r--r--test/round_trip_test.cc7
6 files changed, 63 insertions, 21 deletions
diff --git a/src/kdm.cc b/src/kdm.cc
index 70109936..4a03b33f 100644
--- a/src/kdm.cc
+++ b/src/kdm.cc
@@ -34,6 +34,7 @@
#include "cpl.h"
#include "mxf_asset.h"
#include "xml/kdm_smpte.h"
+#include "parse/cpl.h"
using std::list;
using std::string;
@@ -90,12 +91,20 @@ KDM::KDM (boost::filesystem::path kdm, boost::filesystem::path private_key)
* @param not_valid_after KDM not-valid-after time in local time.
*/
KDM::KDM (
- shared_ptr<const CPL> cpl, shared_ptr<const Signer> signer, shared_ptr<const Certificate> recipient_cert,
+ boost::filesystem::path cpl_file, shared_ptr<const Signer> signer, shared_ptr<const Certificate> recipient_cert, Key key,
boost::posix_time::ptime not_valid_before, boost::posix_time::ptime not_valid_after,
string annotation_text, string issue_date
)
: _xml_kdm (new xml::DCinemaSecurityMessage)
{
+ /* This is all a bit of a hack, and should hopefully be nicer in libdcp1.
+ We load in the CPL file using our parser here, and extract everything
+ we need. This is much better than needing the whole DCP and going through
+ the dance of setting the MXF's keys and so on.
+ */
+
+ parse::CPL cpl (cpl_file);
+
xml::AuthenticatedPublic& apu = _xml_kdm->authenticated_public;
/* AuthenticatedPublic */
@@ -109,9 +118,9 @@ KDM::KDM (
apu.recipient.x509_issuer_serial.x509_issuer_name = recipient_cert->issuer ();
apu.recipient.x509_issuer_serial.x509_serial_number = recipient_cert->serial ();
apu.recipient.x509_subject_name = recipient_cert->subject ();
- apu.composition_playlist_id = "urn:uuid:" + cpl->id ();
+ apu.composition_playlist_id = cpl.id;
// apu.content_authenticator = signer->certificates().leaf()->thumbprint ();
- apu.content_title_text = cpl->name ();
+ apu.content_title_text = cpl.annotation_text;
apu.content_keys_not_valid_before = ptime_to_string (not_valid_before);
apu.content_keys_not_valid_after = ptime_to_string (not_valid_after);
apu.authorized_device_info.device_list_identifier = "urn:uuid:" + make_uuid ();
@@ -127,12 +136,16 @@ KDM::KDM (
*/
apu.authorized_device_info.device_list.push_back ("2jmj7l5rSw0yVb/vlWAYkK/YBwk=");
- list<shared_ptr<const Asset> > assets = cpl->assets ();
- for (list<shared_ptr<const Asset> >::iterator i = assets.begin(); i != assets.end(); ++i) {
- /* XXX: non-MXF assets? */
- shared_ptr<const MXFAsset> mxf = boost::dynamic_pointer_cast<const MXFAsset> (*i);
- if (mxf) {
- apu.key_id_list.push_back (xml::TypedKeyId (mxf->key_type(), "urn:uuid:" + mxf->key_id()));
+ for (list<shared_ptr<parse::Reel> >::const_iterator i = cpl.reels.begin(); i != cpl.reels.end(); ++i) {
+ /* XXX: subtitle assets? */
+ if ((*i)->asset_list->main_picture) {
+ apu.key_id_list.push_back (xml::TypedKeyId ("MDIK", (*i)->asset_list->main_picture->key_id));
+ }
+ if ((*i)->asset_list->main_stereoscopic_picture) {
+ apu.key_id_list.push_back (xml::TypedKeyId ("MDIK", (*i)->asset_list->main_stereoscopic_picture->key_id));
+ }
+ if ((*i)->asset_list->main_sound) {
+ apu.key_id_list.push_back (xml::TypedKeyId ("MDAK", (*i)->asset_list->main_sound->key_id));
}
}
@@ -141,18 +154,38 @@ KDM::KDM (
/* AuthenticatedPrivate */
- for (list<shared_ptr<const Asset> >::iterator i = assets.begin(); i != assets.end(); ++i) {
- /* XXX: non-MXF assets? */
- shared_ptr<const MXFAsset> mxf = boost::dynamic_pointer_cast<const MXFAsset> (*i);
- if (mxf) {
+ for (list<shared_ptr<parse::Reel> >::iterator i = cpl.reels.begin(); i != cpl.reels.end(); ++i) {
+ /* XXX: subtitle assets? */
+
+ if ((*i)->asset_list->main_picture) {
+ KDMKey kkey (
+ signer, cpl.id.substr (9), "MDIK", (*i)->asset_list->main_picture->key_id.substr (9),
+ not_valid_before, not_valid_after, key
+ );
+
+ _keys.push_back (kkey);
+ _xml_kdm->authenticated_private.encrypted_keys.push_back (kkey.encrypted_base64 (recipient_cert));
+ }
+
+ if ((*i)->asset_list->main_stereoscopic_picture) {
KDMKey kkey (
- signer, cpl->id (), mxf->key_type (), mxf->key_id (),
- not_valid_before, not_valid_after, mxf->key().get()
+ signer, cpl.id.substr (9), "MDIK", (*i)->asset_list->main_stereoscopic_picture->key_id.substr (9),
+ not_valid_before, not_valid_after, key
);
_keys.push_back (kkey);
_xml_kdm->authenticated_private.encrypted_keys.push_back (kkey.encrypted_base64 (recipient_cert));
}
+
+ if ((*i)->asset_list->main_sound) {
+ KDMKey kkey (
+ signer, cpl.id.substr (9), "MDAK", (*i)->asset_list->main_sound->key_id.substr (9),
+ not_valid_before, not_valid_after, key
+ );
+
+ _keys.push_back (kkey);
+ _xml_kdm->authenticated_private.encrypted_keys.push_back (kkey.encrypted_base64 (recipient_cert));
+ }
}
/* Signature */
diff --git a/src/kdm.h b/src/kdm.h
index 4e897ca8..c6a03fb1 100644
--- a/src/kdm.h
+++ b/src/kdm.h
@@ -156,16 +156,17 @@ public:
KDM (boost::filesystem::path kdm, boost::filesystem::path private_key);
/** Create a new KDM.
- * @param cpl CPL that the KDM is for.
+ * @param cpl CPL file that the KDM is for.
* @param signer Certificate chain to sign the KDM with.
* @param recipient_cert Certificate of the projector that this KDM is targeted at.
+ * @param key Key used to encrypt all MXF data.
* @param not_valid_before Start of validity period.
* @param not_valid_after End of validity period.
* @param annotation_text Text for the <AnnotationText> node.
* @param issue_date Text for the <IssueDate> node.
*/
KDM (
- boost::shared_ptr<const CPL> cpl, boost::shared_ptr<const Signer> signer, boost::shared_ptr<const Certificate> recipient_cert,
+ boost::filesystem::path cpl, boost::shared_ptr<const Signer> signer, boost::shared_ptr<const Certificate> recipient_cert, Key key,
boost::posix_time::ptime not_valid_before, boost::posix_time::ptime not_valid_after,
std::string annotation_text, std::string issue_date
);
diff --git a/src/parse/cpl.cc b/src/parse/cpl.cc
index f6ce434c..8184c57b 100644
--- a/src/parse/cpl.cc
+++ b/src/parse/cpl.cc
@@ -31,7 +31,7 @@ using std::bad_cast;
using boost::shared_ptr;
using namespace libdcp::parse;
-CPL::CPL (string file)
+CPL::CPL (boost::filesystem::path file)
{
cxml::Document f ("CompositionPlaylist");
f.read_file (file);
diff --git a/src/parse/cpl.h b/src/parse/cpl.h
index 04bf9351..4e798e37 100644
--- a/src/parse/cpl.h
+++ b/src/parse/cpl.h
@@ -145,7 +145,7 @@ class CPL
{
public:
/** Parse a CPL XML file into our member variables */
- CPL (std::string file);
+ CPL (boost::filesystem::path file);
std::string id;
std::string annotation_text;
diff --git a/test/encryption_test.cc b/test/encryption_test.cc
index f08d4827..35e828b9 100644
--- a/test/encryption_test.cc
+++ b/test/encryption_test.cc
@@ -100,10 +100,13 @@ BOOST_AUTO_TEST_CASE (encryption)
d.write_xml (false, xml_metadata, signer);
+ boost::filesystem::path cpl_path = boost::filesystem::path ("build/test/DCP/bar") / (cpl->id() + "_cpl.xml");
+
libdcp::KDM kdm (
- cpl,
+ cpl_path,
signer,
signer->certificates().leaf(),
+ key,
boost::posix_time::time_from_string ("2013-01-01 00:00:00"),
boost::posix_time::time_from_string ("2013-01-08 00:00:00"),
"libdcp",
diff --git a/test/round_trip_test.cc b/test/round_trip_test.cc
index a6ee2097..e5a22f60 100644
--- a/test/round_trip_test.cc
+++ b/test/round_trip_test.cc
@@ -68,12 +68,17 @@ BOOST_AUTO_TEST_CASE (round_trip_test)
shared_ptr<libdcp::CPL> cpl (new libdcp::CPL (work_dir, "A Test DCP", libdcp::FEATURE, 24, 24));
cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (asset_A, shared_ptr<libdcp::SoundAsset> (), shared_ptr<libdcp::SubtitleAsset> ())));
+ libdcp::XMLMetadata metadata;
+ cpl->write_xml (true, metadata, signer);
+
+ boost::filesystem::path cpl_path = work_dir / (cpl->id() + "_cpl.xml");
/* A KDM using our certificate chain's leaf key pair */
libdcp::KDM kdm_A (
- cpl,
+ cpl_path,
signer,
signer->certificates().leaf(),
+ key,
boost::posix_time::time_from_string ("2013-01-01 00:00:00"),
boost::posix_time::time_from_string ("2013-01-08 00:00:00"),
"libdcp",