Try to fix comparison of encrypted sound assets.
[libdcp.git] / src / encrypted_kdm.cc
index 207dff67bc8efb449634f458853b4c101c977e17..8ed0c3159c7ec8c955af77a430c5befdde93c4df 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -33,6 +33,7 @@ using std::string;
 using std::map;
 using std::pair;
 using boost::shared_ptr;
+using boost::optional;
 using namespace dcp;
 
 namespace dcp {
@@ -202,9 +203,13 @@ public:
 
                for (list<string>::const_iterator i = encrypted_key.begin(); i != encrypted_key.end(); ++i) {
                        xmlpp::Element* encrypted_key = node->add_child ("EncryptedKey", "enc");
+                       /* XXX: hack for testing with Dolby */
+                       encrypted_key->set_namespace_declaration ("http://www.w3.org/2001/04/xmlenc#", "enc");
                        xmlpp::Element* encryption_method = encrypted_key->add_child ("EncryptionMethod", "enc");
                        encryption_method->set_attribute ("Algorithm", "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
                        xmlpp::Element* digest_method = encryption_method->add_child ("DigestMethod", "ds");
+                       /* XXX: hack for testing with Dolby */
+                       digest_method->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "ds");
                        digest_method->set_attribute ("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1");
                        xmlpp::Element* cipher_data = encrypted_key->add_child ("CipherData", "enc");
                        cipher_data->add_child("CipherValue", "enc")->add_child_text (*i);
@@ -221,7 +226,7 @@ public:
 
        TypedKeyId (shared_ptr<const cxml::Node> node)
                : key_type (node->string_child ("KeyType"))
-               , key_id (node->string_child ("KeyId").substr (9))
+               , key_id (remove_urn_uuid (node->string_child ("KeyId")))
        {
 
        }
@@ -275,7 +280,7 @@ public:
        AuthorizedDeviceInfo () {}
 
        AuthorizedDeviceInfo (shared_ptr<const cxml::Node> node)
-               : device_list_identifier (node->string_child ("DeviceListIdentifier").substr (9))
+               : device_list_identifier (remove_urn_uuid (node->string_child ("DeviceListIdentifier")))
                , device_list_description (node->optional_string_child ("DeviceListDescription"))
        {
                BOOST_FOREACH (cxml::ConstNodePtr i, node->node_child("DeviceList")->node_children("CertificateThumbprint")) {
@@ -352,7 +357,7 @@ public:
 
        KDMRequiredExtensions (shared_ptr<const cxml::Node> node)
                : recipient (node->node_child ("Recipient"))
-               , composition_playlist_id (node->string_child ("CompositionPlaylistId").substr (9))
+               , composition_playlist_id (remove_urn_uuid (node->string_child ("CompositionPlaylistId")))
                , content_title_text (node->string_child ("ContentTitleText"))
                , not_valid_before (node->string_child ("ContentKeysNotValidBefore"))
                , not_valid_after (node->string_child ("ContentKeysNotValidAfter"))
@@ -416,12 +421,14 @@ class AuthenticatedPublic
 public:
        AuthenticatedPublic ()
                : message_id (make_uuid ())
+                 /* XXX: hack for Dolby to see if there must be a not-empty annotation text */
+               , annotation_text ("none")
                , issue_date (LocalTime().as_string ())
        {}
 
        AuthenticatedPublic (shared_ptr<const cxml::Node> node)
-               : message_id (node->string_child ("MessageId").substr (9))
-               , annotation_text (node->string_child ("AnnotationText"))
+               : message_id (remove_urn_uuid (node->string_child ("MessageId")))
+               , annotation_text (node->optional_string_child ("AnnotationText"))
                , issue_date (node->string_child ("IssueDate"))
                , signer (node->node_child ("Signer"))
                , required_extensions (node->node_child ("RequiredExtensions"))
@@ -435,7 +442,9 @@ public:
 
                node->add_child("MessageId")->add_child_text ("urn:uuid:" + message_id);
                node->add_child("MessageType")->add_child_text ("http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type");
-               node->add_child("AnnotationText")->add_child_text (annotation_text);
+               if (annotation_text) {
+                       node->add_child("AnnotationText")->add_child_text (annotation_text.get ());
+               }
                node->add_child("IssueDate")->add_child_text (issue_date);
 
                signer.as_xml (node->add_child ("Signer"));
@@ -445,7 +454,7 @@ public:
        }
 
        string message_id;
-       string annotation_text;
+       optional<string> annotation_text;
        string issue_date;
        Signer signer;
        RequiredExtensions required_extensions;
@@ -613,11 +622,6 @@ EncryptedKDM::as_xml (boost::filesystem::path path) const
 string
 EncryptedKDM::as_xml () const
 {
-       xmlpp::Document document;
-       xmlpp::Element* root = document.create_root_node ("DCinemaSecurityMessage", "http://www.smpte-ra.org/schemas/430-3/2006/ETM");
-       root->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "ds");
-       root->set_namespace_declaration ("http://www.w3.org/2001/04/xmlenc#", "enc");
-
        return _data->as_xml()->write_to_string ("UTF-8");
 }
 
@@ -627,7 +631,7 @@ EncryptedKDM::keys () const
        return _data->authenticated_private.encrypted_key;
 }
 
-string
+optional<string>
 EncryptedKDM::annotation_text () const
 {
        return _data->authenticated_public.annotation_text;
@@ -639,6 +643,12 @@ EncryptedKDM::content_title_text () const
        return _data->authenticated_public.required_extensions.kdm_required_extensions.content_title_text;
 }
 
+string
+EncryptedKDM::cpl_id () const
+{
+       return _data->authenticated_public.required_extensions.kdm_required_extensions.composition_playlist_id;
+}
+
 string
 EncryptedKDM::issue_date () const
 {