swaroop: add name to ECinema KDMs and add DKDM wrapper for ECinema.
authorCarl Hetherington <cth@carlh.net>
Mon, 13 May 2019 16:20:01 +0000 (17:20 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 May 2019 16:20:01 +0000 (17:20 +0100)
src/lib/decrypted_ecinema_kdm.cc
src/lib/decrypted_ecinema_kdm.h
src/lib/dkdm_wrapper.cc
src/lib/dkdm_wrapper.h
src/lib/encrypted_ecinema_kdm.cc
src/lib/encrypted_ecinema_kdm.h
src/lib/wscript
src/tools/dcpomatic_ecinema.cc

index a03004e4378eb9c7ef9355e24e66a06e008ff842..14843185fdbba008de2a56f508d0802e6f397317 100644 (file)
@@ -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
index f61402b7bffab17f5638741197bc361f5e4436ae..0ddc256154466fe8f2f13e60d7d5c1eb101cb363 100644 (file)
@@ -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;
 };
index 76f9217aac4a64d3b6f589aa20290511a66ddad4..0dd37b464c6db6453a1bfc2d56459b48321dca9a 100644 (file)
@@ -34,6 +34,10 @@ DKDMBase::read (cxml::ConstNodePtr node)
 {
        if (node->name() == "DKDM") {
                return shared_ptr<DKDM> (new DKDM (dcp::EncryptedKDM (node->content ())));
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+       } else if (node->name() == "ECinemaDKDM") {
+               return shared_ptr<ECinemaDKDM> (new ECinemaDKDM(EncryptedECinemaKDM(node->content())));
+#endif
        } else if (node->name() == "DKDMGroup") {
                shared_ptr<DKDMGroup> 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
 {
index 09e9d25c428c3808869fc6b20429edcc9fa73876..d828ffac2536a4298563764ae58a4c390321aa03 100644 (file)
@@ -18,6 +18,9 @@
 
 */
 
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+#include "encrypted_ecinema_kdm.h"
+#endif
 #include <dcp/encrypted_kdm.h>
 #include <libcxml/cxml.h>
 #include <boost/enable_shared_from_this.hpp>
@@ -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:
index ab9e15e858d8a1bab6851c3620a6b2bff108b780..e4e19d7fb3de57426fd4707a0763b00cb2bb1864 100644 (file)
 #ifdef DCPOMATIC_VARIANT_SWAROOP
 
 #include "encrypted_ecinema_kdm.h"
+#include "exceptions.h"
 #include <dcp/key.h>
 #include <dcp/certificate.h>
 #include <dcp/util.h>
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
 #include <openssl/rsa.h>
+#include <openssl/err.h>
 #include <iostream>
 
 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");
 }
index ece1e3161b8ab003498ad3788a4c878055a3ed8e..0bcbc4117f0bbe7172b18f6a025813193161febf 100644 (file)
@@ -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;
 };
index c5a270f6536cac8972d043f362c9984f78fdc6af..37b942400ab4f0887234f660c07cc691d0707604 100644 (file)
@@ -77,6 +77,7 @@ sources = """
           digester.cc
           dkdm_wrapper.cc
           dolby_cp750.cc
+          ecinema_screen_kdm.cc
           edid.cc
           emailer.cc
           empty.cc
index 6c4b2a8c75808956209dfd05c36fc2599c7e3220..a0324f281aa033f40fa620adfba197365b3f56a9 100644 (file)
@@ -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";
 }