2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/asset.cc
21 * @brief Parent class for assets of DCPs made up of MXF files.
24 #include "raw_convert.h"
31 #include "exceptions.h"
32 #include "dcp_assert.h"
33 #include "compose.hpp"
34 #include <libxml++/nodes/element.h>
35 #include <boost/filesystem.hpp>
41 using boost::shared_ptr;
42 using boost::dynamic_pointer_cast;
46 : _encryption_context (0)
47 , _decryption_context (0)
52 MXF::MXF (boost::filesystem::path file)
54 , _encryption_context (0)
55 , _decryption_context (0)
62 delete _encryption_context;
63 delete _decryption_context;
67 MXF::fill_writer_info (ASDCP::WriterInfo* writer_info, Standard standard)
69 writer_info->ProductVersion = _metadata.product_version;
70 writer_info->CompanyName = _metadata.company_name;
71 writer_info->ProductName = _metadata.product_name.c_str();
73 if (standard == INTEROP) {
74 writer_info->LabelSetType = ASDCP::LS_MXF_INTEROP;
76 writer_info->LabelSetType = ASDCP::LS_MXF_SMPTE;
79 Kumu::hex2bin (_id.c_str(), writer_info->AssetUUID, Kumu::UUID_Length, &c);
80 DCP_ASSERT (c == Kumu::UUID_Length);
83 Kumu::GenRandomUUID (writer_info->ContextID);
84 writer_info->EncryptedEssence = true;
87 Kumu::hex2bin (_key_id.get().c_str(), writer_info->CryptographicKeyID, Kumu::UUID_Length, &c);
88 DCP_ASSERT (c == Kumu::UUID_Length);
93 MXF::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
95 if (!Asset::equals (other, opt, note)) {
99 shared_ptr<const MXF> other_mxf = dynamic_pointer_cast<const MXF> (other);
104 if (_file.leaf() != other_mxf->file().leaf()) {
105 if (!opt.mxf_filenames_can_differ) {
106 note (DCP_ERROR, "MXF: filenames differ");
109 note (DCP_NOTE, "MXF: filenames differ");
116 /** Set the (private) key that will be used to encrypt or decrypt this MXF's content.
117 * This is the top-secret key that is distributed (itself encrypted) to cinemas
118 * via Key Delivery Messages (KDMs).
119 * @param key Key to use.
122 MXF::set_key (Key key)
127 /* No key ID so far; we now need one */
128 _key_id = make_uuid ();
131 _decryption_context = new ASDCP::AESDecContext;
132 if (ASDCP_FAILURE (_decryption_context->InitKey (_key->value ()))) {
133 throw MiscError ("could not set up decryption context");
136 _encryption_context = new ASDCP::AESEncContext;
137 if (ASDCP_FAILURE (_encryption_context->InitKey (_key->value ()))) {
138 throw MiscError ("could not set up encryption context");
141 uint8_t cbc_buffer[ASDCP::CBC_BLOCK_SIZE];
143 Kumu::FortunaRNG rng;
144 if (ASDCP_FAILURE (_encryption_context->SetIVec (rng.FillRandom (cbc_buffer, ASDCP::CBC_BLOCK_SIZE)))) {
145 throw MiscError ("could not set up CBC initialization vector");
150 MXF::read_writer_info (ASDCP::WriterInfo const & info)
153 Kumu::bin2UUIDhex (info.AssetUUID, ASDCP::UUIDlen, buffer, sizeof (buffer));