From: Carl Hetherington Date: Mon, 13 May 2019 16:20:01 +0000 (+0100) Subject: swaroop: add name to ECinema KDMs and add DKDM wrapper for ECinema. X-Git-Tag: v2.15.4~4 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=6cde6bcc0b604c1a157a4ccbdce29e91f4d45a91 swaroop: add name to ECinema KDMs and add DKDM wrapper for ECinema. --- diff --git a/src/lib/decrypted_ecinema_kdm.cc b/src/lib/decrypted_ecinema_kdm.cc index a03004e43..14843185f 100644 --- a/src/lib/decrypted_ecinema_kdm.cc +++ b/src/lib/decrypted_ecinema_kdm.cc @@ -34,8 +34,9 @@ using std::string; using std::runtime_error; using dcp::Certificate; -DecryptedECinemaKDM::DecryptedECinemaKDM (string id, dcp::Key content_key) +DecryptedECinemaKDM::DecryptedECinemaKDM (string id, string name, dcp::Key content_key) : _id (id) + , _name (name) , _content_key (content_key) { @@ -43,6 +44,7 @@ DecryptedECinemaKDM::DecryptedECinemaKDM (string id, dcp::Key content_key) DecryptedECinemaKDM::DecryptedECinemaKDM (EncryptedECinemaKDM kdm, string private_key) : _id (kdm.id()) + , _name (kdm.name()) { /* Read the private key */ @@ -68,7 +70,7 @@ DecryptedECinemaKDM::DecryptedECinemaKDM (EncryptedECinemaKDM kdm, string privat EncryptedECinemaKDM DecryptedECinemaKDM::encrypt (Certificate recipient) { - return EncryptedECinemaKDM (_id, _content_key, recipient); + return EncryptedECinemaKDM (_id, _name, _content_key, recipient); } #endif diff --git a/src/lib/decrypted_ecinema_kdm.h b/src/lib/decrypted_ecinema_kdm.h index f61402b7b..0ddc25615 100644 --- a/src/lib/decrypted_ecinema_kdm.h +++ b/src/lib/decrypted_ecinema_kdm.h @@ -28,7 +28,7 @@ class DecryptedECinemaKDM { public: - DecryptedECinemaKDM (std::string id, dcp::Key content_key); + DecryptedECinemaKDM (std::string id, std::string name, dcp::Key content_key); DecryptedECinemaKDM (EncryptedECinemaKDM kdm, std::string private_key); EncryptedECinemaKDM encrypt (dcp::Certificate recipient); @@ -37,12 +37,17 @@ public: return _id; } + std::string name () const { + return _name; + } + dcp::Key key () const { return _content_key; } private: std::string _id; + std::string _name; /** unenecrypted content key */ dcp::Key _content_key; }; diff --git a/src/lib/dkdm_wrapper.cc b/src/lib/dkdm_wrapper.cc index 76f9217aa..0dd37b464 100644 --- a/src/lib/dkdm_wrapper.cc +++ b/src/lib/dkdm_wrapper.cc @@ -34,6 +34,10 @@ DKDMBase::read (cxml::ConstNodePtr node) { if (node->name() == "DKDM") { return shared_ptr (new DKDM (dcp::EncryptedKDM (node->content ()))); +#ifdef DCPOMATIC_VARIANT_SWAROOP + } else if (node->name() == "ECinemaDKDM") { + return shared_ptr (new ECinemaDKDM(EncryptedECinemaKDM(node->content()))); +#endif } else if (node->name() == "DKDMGroup") { shared_ptr group (new DKDMGroup (node->string_attribute ("Name"))); BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children()) { @@ -60,6 +64,20 @@ DKDM::as_xml (xmlpp::Element* node) const node->add_child("DKDM")->add_child_text (_dkdm.as_xml ()); } +#ifdef DCPOMATIC_VARIANT_SWAROOP +string +ECinemaDKDM::name () const +{ + return String::compose ("%1 (%2)", _dkdm.name(), _dkdm.id()); +} + +void +ECinemaDKDM::as_xml (xmlpp::Element* node) const +{ + node->add_child("ECinemaDKDM")->add_child_text (_dkdm.as_xml()); +} +#endif + void DKDMGroup::as_xml (xmlpp::Element* node) const { diff --git a/src/lib/dkdm_wrapper.h b/src/lib/dkdm_wrapper.h index 09e9d25c4..d828ffac2 100644 --- a/src/lib/dkdm_wrapper.h +++ b/src/lib/dkdm_wrapper.h @@ -18,6 +18,9 @@ */ +#ifdef DCPOMATIC_VARIANT_SWAROOP +#include "encrypted_ecinema_kdm.h" +#endif #include #include #include @@ -67,6 +70,26 @@ private: dcp::EncryptedKDM _dkdm; }; +#ifdef DCPOMATIC_VARIANT_SWAROOP +class ECinemaDKDM : public DKDMBase +{ +public: + explicit ECinemaDKDM (EncryptedECinemaKDM k) + : _dkdm (k) + {} + + std::string name () const; + void as_xml (xmlpp::Element *) const; + + EncryptedECinemaKDM dkdm () const { + return _dkdm; + } + +private: + EncryptedECinemaKDM _dkdm; +}; +#endif + class DKDMGroup : public DKDMBase { public: diff --git a/src/lib/encrypted_ecinema_kdm.cc b/src/lib/encrypted_ecinema_kdm.cc index ab9e15e85..e4e19d7fb 100644 --- a/src/lib/encrypted_ecinema_kdm.cc +++ b/src/lib/encrypted_ecinema_kdm.cc @@ -21,12 +21,14 @@ #ifdef DCPOMATIC_VARIANT_SWAROOP #include "encrypted_ecinema_kdm.h" +#include "exceptions.h" #include #include #include #include #include #include +#include #include using std::cout; @@ -34,12 +36,17 @@ using std::string; using boost::shared_ptr; using dcp::Certificate; -EncryptedECinemaKDM::EncryptedECinemaKDM (string id, dcp::Key content_key, Certificate recipient) +EncryptedECinemaKDM::EncryptedECinemaKDM (string id, string name, dcp::Key content_key, Certificate recipient) : _id (id) + , _name (name) { RSA* rsa = recipient.public_key (); _content_key = dcp::Data (RSA_size(rsa)); int const N = RSA_public_encrypt (content_key.length(), content_key.value(), _content_key.data().get(), rsa, RSA_PKCS1_OAEP_PADDING); + if (N == -1) { + throw KDMError ("Could not encrypt ECinema KDM", ERR_error_string(ERR_get_error(), 0)); + } + } EncryptedECinemaKDM::EncryptedECinemaKDM (string xml) @@ -47,6 +54,7 @@ EncryptedECinemaKDM::EncryptedECinemaKDM (string xml) cxml::Document doc ("ECinemaSecurityMessage"); doc.read_string (xml); _id = doc.string_child ("Id"); + _name = doc.string_child ("Name"); _content_key = dcp::Data (256); int const len = dcp::base64_decode (doc.string_child("Key"), _content_key.data().get(), _content_key.size()); _content_key.set_size (len); @@ -72,6 +80,7 @@ EncryptedECinemaKDM::as_xml () const xmlpp::Document document; xmlpp::Element* root = document.create_root_node ("ECinemaSecurityMessage"); root->add_child("Id")->add_child_text(_id); + root->add_child("Name")->add_child_text(_name); root->add_child("Key")->add_child_text(lines); return document.write_to_string ("UTF-8"); } diff --git a/src/lib/encrypted_ecinema_kdm.h b/src/lib/encrypted_ecinema_kdm.h index ece1e3161..0bcbc4117 100644 --- a/src/lib/encrypted_ecinema_kdm.h +++ b/src/lib/encrypted_ecinema_kdm.h @@ -40,6 +40,10 @@ public: return _id; } + std::string name () const { + return _name; + } + dcp::Data key () const { return _content_key; } @@ -47,9 +51,10 @@ public: private: friend class DecryptedECinemaKDM; - EncryptedECinemaKDM (std::string id, dcp::Key key, dcp::Certificate recipient); + EncryptedECinemaKDM (std::string id, std::string name, dcp::Key key, dcp::Certificate recipient); std::string _id; + std::string _name; /** encrypted content key */ dcp::Data _content_key; }; diff --git a/src/lib/wscript b/src/lib/wscript index c5a270f65..37b942400 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -77,6 +77,7 @@ sources = """ digester.cc dkdm_wrapper.cc dolby_cp750.cc + ecinema_screen_kdm.cc edid.cc emailer.cc empty.cc diff --git a/src/tools/dcpomatic_ecinema.cc b/src/tools/dcpomatic_ecinema.cc index 6c4b2a8c7..a0324f281 100644 --- a/src/tools/dcpomatic_ecinema.cc +++ b/src/tools/dcpomatic_ecinema.cc @@ -190,7 +190,7 @@ main (int argc, char* argv[]) avformat_free_context (input_fc); avformat_free_context (output_fc); - DecryptedECinemaKDM decrypted_kdm (id, key); + DecryptedECinemaKDM decrypted_kdm (id, output_mp4.filename().string(), key); EncryptedECinemaKDM encrypted_kdm = decrypted_kdm.encrypt (Config::instance()->decryption_chain()->leaf()); cout << encrypted_kdm.as_xml() << "\n"; }