/*
- Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2013 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
#include "parse/asset_map.h"
#include "reel.h"
#include "metadata.h"
-#include "encryption.h"
+#include "signer.h"
#include "exceptions.h"
#include "compose.hpp"
using std::ofstream;
using std::ostream;
using std::list;
+using std::pair;
+using std::make_pair;
using boost::shared_ptr;
using boost::lexical_cast;
+using boost::optional;
using namespace libdcp;
-CPL::CPL (string directory, string name, ContentKind content_kind, int length, int frames_per_second)
+CPL::CPL (boost::filesystem::path directory, string name, ContentKind content_kind, int length, int frames_per_second)
: _directory (directory)
, _name (name)
, _content_kind (content_kind)
* @param asset_maps AssetMaps to look for assets in.
* @param require_mxfs true to throw an exception if a required MXF file does not exist.
*/
-CPL::CPL (string directory, string file, list<shared_ptr<const parse::AssetMap> > asset_maps, bool require_mxfs)
+CPL::CPL (boost::filesystem::path directory, string file, list<PathAssetMap> asset_maps, bool require_mxfs)
: _directory (directory)
, _content_kind (FEATURE)
, _length (0)
if (!(*i)->asset_list->main_stereoscopic_picture && p->edit_rate == p->frame_rate) {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+
try {
picture.reset (new MonoPictureAsset (
- _directory,
- asset_from_id (asset_maps, p->id)->chunks.front()->path
+ asset.first,
+ asset.second->chunks.front()->path
)
);
} else {
try {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, p->id);
+
picture.reset (new StereoPictureAsset (
- _directory,
- asset_from_id (asset_maps, p->id)->chunks.front()->path,
+ asset.first,
+ asset.second->chunks.front()->path,
_fps,
p->duration
)
if ((*i)->asset_list->main_sound) {
try {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_sound->id);
+
sound.reset (new SoundAsset (
- _directory,
- asset_from_id (asset_maps, (*i)->asset_list->main_sound->id)->chunks.front()->path
+ asset.first,
+ asset.second->chunks.front()->path
)
);
if ((*i)->asset_list->main_subtitle) {
+ pair<string, shared_ptr<const parse::AssetMapAsset> > asset = asset_from_id (asset_maps, (*i)->asset_list->main_subtitle->id);
+
subtitle.reset (new SubtitleAsset (
- _directory,
- asset_from_id (asset_maps, (*i)->asset_list->main_subtitle->id)->chunks.front()->path
+ asset.first,
+ asset.second->chunks.front()->path
)
);
}
void
-CPL::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<Encryption> crypt) const
+CPL::write_xml (bool interop, XMLMetadata const & metadata, shared_ptr<const Signer> signer) const
{
boost::filesystem::path p;
p /= _directory;
root = doc.create_root_node ("CompositionPlaylist", "http://www.smpte-ra.org/schemas/429-7/2006/CPL");
}
- if (crypt) {
+ if (signer) {
root->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "dsig");
}
}
root->add_child("RatingList");
- xmlpp::Node* reel_list = root->add_child ("ReelList");
+ xmlpp::Element* reel_list = root->add_child ("ReelList");
for (list<shared_ptr<Reel> >::const_iterator i = _reels.begin(); i != _reels.end(); ++i) {
(*i)->write_to_cpl (reel_list, interop);
}
- if (crypt) {
- sign (root, crypt->certificates, crypt->signer_key, interop);
+ if (signer) {
+ signer->sign (root, interop);
}
doc.write_to_file_formatted (p.string (), "UTF-8");
- _digest = make_digest (p.string ());
+ _digest = make_digest (p.string (), 0);
_length = boost::filesystem::file_size (p.string ());
}
shared_ptr<xmlpp::Document>
CPL::make_kdm (
- CertificateChain const & certificates,
- string const & signer_key,
+ shared_ptr<const Signer> signer,
shared_ptr<const Certificate> recipient_cert,
+ Key key,
boost::posix_time::ptime from,
boost::posix_time::ptime until,
bool interop,
xmlAddID (0, doc->cobj(), (const xmlChar *) "ID_AuthenticatedPublic", authenticated_public->get_attribute("Id")->cobj());
authenticated_public->add_child("MessageId")->add_child_text ("urn:uuid:" + make_uuid());
+ /* XXX: this should probably be different if interop == true */
authenticated_public->add_child("MessageType")->add_child_text ("http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type");
authenticated_public->add_child("AnnotationText")->add_child_text (mxf_metadata.product_name);
authenticated_public->add_child("IssueDate")->add_child_text (xml_metadata.issue_date);
{
- xmlpp::Element* signer = authenticated_public->add_child("Signer");
- signer->add_child("X509IssuerName", "ds")->add_child_text (recipient_cert->issuer());
- signer->add_child("X509SerialNumber", "ds")->add_child_text (recipient_cert->serial());
+ xmlpp::Element* xml_signer = authenticated_public->add_child("Signer");
+ xml_signer->add_child("X509IssuerName", "ds")->add_child_text (signer->certificates().leaf()->issuer());
+ xml_signer->add_child("X509SerialNumber", "ds")->add_child_text (signer->certificates().leaf()->serial());
}
{
kdm_required_extensions->add_child("CompositionPlaylistId")->add_child_text("urn:uuid:" + _id);
kdm_required_extensions->add_child("ContentTitleText")->add_child_text(_name);
- kdm_required_extensions->add_child("ContentAuthenticator")->add_child_text(certificates.leaf()->thumbprint());
- kdm_required_extensions->add_child("ContentKeysNotValidBefore")->add_child_text("XXX");
- kdm_required_extensions->add_child("ContentKeysNotValidAfter")->add_child_text("XXX");
+ kdm_required_extensions->add_child("ContentAuthenticator")->add_child_text(signer->certificates().leaf()->thumbprint());
+ kdm_required_extensions->add_child("ContentKeysNotValidBefore")->add_child_text(ptime_to_string (from));
+ kdm_required_extensions->add_child("ContentKeysNotValidAfter")->add_child_text(ptime_to_string (until));
{
xmlpp::Element* authorized_device_info = kdm_required_extensions->add_child("AuthorizedDeviceInfo");
xmlpp::Element* authenticated_private = root->add_child("AuthenticatedPrivate");
authenticated_private->set_attribute ("Id", "ID_AuthenticatedPrivate");
xmlAddID (0, doc->cobj(), (const xmlChar *) "ID_AuthenticatedPrivate", authenticated_private->get_attribute("Id")->cobj());
- {
- xmlpp::Element* encrypted_key = authenticated_private->add_child ("EncryptedKey", "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");
- encryption_method->add_child("DigestMethod", "ds")->set_attribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1");
- }
- xmlpp::Element* cipher_data = authenticated_private->add_child ("CipherData", "enc");
- cipher_data->add_child("CipherValue", "enc")->add_child_text("XXX");
- }
+ xmlpp::Element* encrypted_key = authenticated_private->add_child ("EncryptedKey", "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");
+ encryption_method->add_child("DigestMethod", "ds")->set_attribute("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1");
+ xmlpp::Element* cipher_data = authenticated_private->add_child ("CipherData", "enc");
+ cipher_data->add_child("CipherValue", "enc")->add_child_text(key.hex());
}
- /* XXX: x2 one for each mxf? */
-
{
xmlpp::Element* signature = root->add_child("Signature", "ds");
}
}
- add_signature_value (signature, certificates, signer_key, "ds");
+ signer->add_signature_value (signature, "ds");
}
return doc;
}
}
-shared_ptr<parse::AssetMapAsset>
-CPL::asset_from_id (list<shared_ptr<const parse::AssetMap> > asset_maps, string id) const
+pair<string, shared_ptr<const parse::AssetMapAsset> >
+CPL::asset_from_id (list<PathAssetMap> asset_maps, string id) const
{
- for (list<shared_ptr<const parse::AssetMap> >::const_iterator i = asset_maps.begin(); i != asset_maps.end(); ++i) {
- shared_ptr<parse::AssetMapAsset> a = (*i)->asset_from_id (id);
+ for (list<PathAssetMap>::const_iterator i = asset_maps.begin(); i != asset_maps.end(); ++i) {
+ shared_ptr<parse::AssetMapAsset> a = i->second->asset_from_id (id);
if (a) {
- return a;
+ return make_pair (i->first, a);
}
}
- return shared_ptr<parse::AssetMapAsset> ();
+ return make_pair ("", shared_ptr<const parse::AssetMapAsset> ());
}