Change thing used for authorized device list description; set up _keys when loading...
authorCarl Hetherington <cth@carlh.net>
Sun, 29 Sep 2013 08:13:37 +0000 (09:13 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 29 Sep 2013 08:13:37 +0000 (09:13 +0100)
src/kdm.cc
src/kdm.h
src/wscript

index fc0aaa757600664aa0970ecef554d87d04b77c2c..79dc57e1a2c4e4e6c08f9463a6ac446f59391df5 100644 (file)
@@ -46,7 +46,7 @@ using boost::shared_ptr;
 using namespace libdcp;
 
 KDM::KDM (boost::filesystem::path kdm, boost::filesystem::path private_key)
-       : xml_kdm (new xml::DCinemaSecurityMessage (kdm))
+       : _xml_kdm (new xml::DCinemaSecurityMessage (kdm))
 {
        /* Read the private key */
           
@@ -63,7 +63,7 @@ KDM::KDM (boost::filesystem::path kdm, boost::filesystem::path private_key)
 
        /* Use it to decrypt the keys */
 
-       list<string> encrypted_keys = xml_kdm->authenticated_private.encrypted_keys;
+       list<string> encrypted_keys = _xml_kdm->authenticated_private.encrypted_keys;
 
        for (list<string>::iterator i = encrypted_keys.begin(); i != encrypted_keys.end(); ++i) {
 
@@ -91,9 +91,9 @@ KDM::KDM (
        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)
+       : _xml_kdm (new xml::DCinemaSecurityMessage)
 {
-       xml::AuthenticatedPublic& apu = xml_kdm->authenticated_public;
+       xml::AuthenticatedPublic& apu = _xml_kdm->authenticated_public;
 
        /* AuthenticatedPublic */
 
@@ -107,13 +107,18 @@ KDM::KDM (
        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.content_authenticator = signer->certificates().leaf()->thumbprint ();
        apu.content_title_text = cpl->name ();
        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 ();
-       apu.authorized_device_info.device_list_description = recipient_cert->subject ();
+       string n = recipient_cert->common_name ();
+       if (n.find (".") != string::npos) {
+               n = n.substr (n.find (".") + 1);
+       }
+       apu.authorized_device_info.device_list_description = n;
        apu.authorized_device_info.device_list.push_back (recipient_cert->thumbprint ());
-       
+
        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? */
@@ -132,35 +137,57 @@ KDM::KDM (
                /* XXX: non-MXF assets? */
                shared_ptr<const MXFAsset> mxf = boost::dynamic_pointer_cast<const MXFAsset> (*i);
                if (mxf) {
-                       xml_kdm->authenticated_private.encrypted_keys.push_back (
-                               KDMKey (
+                       KDMKey kkey (
                                        signer, cpl->id (), mxf->key_type (), mxf->key_id (),
                                        not_valid_before, not_valid_after, mxf->key().get()
-                                       ).encrypted_base64 (recipient_cert)
                                );
+
+                       _keys.push_back (kkey);
+                       _xml_kdm->authenticated_private.encrypted_keys.push_back (kkey.encrypted_base64 (recipient_cert));
                }
        }
 
        /* Signature */
 
-       shared_ptr<xmlpp::Document> doc = xml_kdm->as_xml ();
+       shared_ptr<xmlpp::Document> doc = _xml_kdm->as_xml ();
        shared_ptr<cxml::Node> root (new cxml::Node (doc->get_root_node ()));
        xmlpp::Node* signature = root->node_child("Signature")->node();
        signer->add_signature_value (signature, "ds");
-       xml_kdm->signature = xml::Signature (shared_ptr<cxml::Node> (new cxml::Node (signature)));
+       doc->write_to_file_formatted ("/home/carl/foo.xml", "UTF-8");
+       _xml_kdm->signature = xml::Signature (shared_ptr<cxml::Node> (new cxml::Node (signature)));
 }
 
+KDM::KDM (KDM const & other)
+       : _keys (other._keys)
+       , _xml_kdm (new xml::DCinemaSecurityMessage (*other._xml_kdm.get()))
+{
+
+}
+
+KDM &
+KDM::operator= (KDM const & other)
+{
+       if (this == &other) {
+               return *this;
+       }
+
+       _keys = other._keys;
+       _xml_kdm.reset (new xml::DCinemaSecurityMessage (*other._xml_kdm.get ()));
+
+       return *this;
+}
+     
 void
 KDM::as_xml (boost::filesystem::path path) const
 {
-       shared_ptr<xmlpp::Document> doc = xml_kdm->as_xml ();
+       shared_ptr<xmlpp::Document> doc = _xml_kdm->as_xml ();
        doc->write_to_file_formatted (path.string(), "UTF-8");
 }
 
 string
 KDM::as_xml () const
 {
-       shared_ptr<xmlpp::Document> doc = xml_kdm->as_xml ();
+       shared_ptr<xmlpp::Document> doc = _xml_kdm->as_xml ();
        return doc->write_to_string_formatted ("UTF-8");
 }
 
@@ -225,7 +252,7 @@ KDMKey::operator= (KDMKey const & other)
        if (&other == this) {
                return *this;
        }
-       
+
        _cpl_id = other._cpl_id;
        _key_type = other._key_type;
        _key_id = other._key_id;
@@ -269,7 +296,17 @@ KDMKey::encrypted_base64 (shared_ptr<const Certificate> recipient_cert) const
 
        /* Lazy overallocation */
        char out[encrypted_len * 2];
-       return Kumu::base64encode (encrypted, encrypted_len, out, encrypted_len * 2);
+       Kumu::base64encode (encrypted, encrypted_len, out, encrypted_len * 2);
+       int const N = strlen (out);
+       stringstream lines;
+       for (int i = 0; i < N; ++i) {
+               if (i > 0 && (i % 64) == 0) {
+                       lines << "\n";
+               }
+               lines << out[i];
+       }
+
+       return lines.str ();
 }
 
 string
@@ -329,8 +366,25 @@ KDMKey::put_uuid (uint8_t ** d, string id) const
                stringstream s;
                s << id[i] << id[i + 1];
                int h;
-               s >> h;
+               s >> hex >> h;
                **d = h;
                (*d)++;
        }
 }
+
+bool
+libdcp::operator== (libdcp::KDMKey const & a, libdcp::KDMKey const & b)
+{
+       if (memcmp (a._signer_thumbprint, b._signer_thumbprint, 20) != 0) {
+               return false;
+       }
+
+       return (
+               a._cpl_id == b._cpl_id &&
+               a._key_type == b._key_type &&
+               a._key_id == b._key_id &&
+               a._not_valid_before == b._not_valid_before &&
+               a._not_valid_after == b._not_valid_after &&
+               a._key == b._key
+               );
+}
index 597088ed2fd4c79105c6814621e01dc94653a8af..4e897ca81c0f03015ebe953b45a7b0f8c692a037 100644 (file)
--- a/src/kdm.h
+++ b/src/kdm.h
@@ -30,6 +30,8 @@
 #include "key.h"
 #include "metadata.h"
 
+class kdm_key_test;
+
 namespace libdcp {
 
 namespace xml {
@@ -114,12 +116,16 @@ public:
        std::string encrypted_base64 (boost::shared_ptr<const Certificate> cert) const;
        
 private:
+       friend class ::kdm_key_test;
+       
        void get (uint8_t *, uint8_t const **, int) const;
        std::string get (uint8_t const **, int) const;
        std::string get_uuid (uint8_t const **) const;
        void put (uint8_t **, uint8_t const *, int) const;
        void put (uint8_t **, std::string) const;
        void put_uuid (uint8_t **, std::string) const;
+
+       friend bool operator== (KDMKey const &, KDMKey const &);
        
        uint8_t _signer_thumbprint[20];
        std::string _cpl_id;
@@ -164,6 +170,9 @@ public:
                std::string annotation_text, std::string issue_date
                );
 
+       KDM (KDM const &);
+       KDM & operator= (KDM const &);
+
        /** @return The unencrypted content keys from this KDM */
        std::list<KDMKey> keys () const {
                return _keys;
@@ -184,7 +193,7 @@ private:
        std::list<KDMKey> _keys;
 
        /** The KDM's contents, mapped 1:1-ish to the XML */
-       boost::shared_ptr<xml::DCinemaSecurityMessage> xml_kdm;
+       boost::shared_ptr<xml::DCinemaSecurityMessage> _xml_kdm;
 };
 
 
index d7e118c794f22099e52805f5b6b18a68493795fb..1d694ec3f84ae21fae0f6c5e8546bb3dab1e9714 100644 (file)
@@ -67,6 +67,7 @@ def build(bld):
               lut.h
               lut_cache.h
               metadata.h
+              mono_picture_asset.h
               mono_picture_frame.h
               mxf_asset.h
               picture_asset.h
@@ -80,6 +81,7 @@ def build(bld):
               sound_asset.h
               sound_frame.h
               srgb_linearised_gamma_lut.h
+              stereo_picture_asset.h
               stereo_picture_frame.h
               subtitle_asset.h
               types.h