Separate out EncryptionContext class to use in SMPTESubtitleAsset::write().
#include "asset_writer.h"
#include "mxf.h"
#include "dcp_assert.h"
+#include "encryption_context.h"
#include <asdcp/AS_DCP.h>
#include <asdcp/KM_prng.h>
, _frames_written (0)
, _finalized (false)
, _started (false)
- , _encryption_context (0)
- , _hmac_context (0)
+ , _encryption_context (new EncryptionContext (mxf->key(), standard))
{
- if (mxf->key ()) {
- _encryption_context = new ASDCP::AESEncContext;
- if (ASDCP_FAILURE (_encryption_context->InitKey (mxf->key()->value ()))) {
- throw MiscError ("could not set up encryption context");
- }
- uint8_t cbc_buffer[ASDCP::CBC_BLOCK_SIZE];
-
- Kumu::FortunaRNG rng;
- if (ASDCP_FAILURE (_encryption_context->SetIVec (rng.FillRandom (cbc_buffer, ASDCP::CBC_BLOCK_SIZE)))) {
- throw MiscError ("could not set up CBC initialization vector");
- }
-
- _hmac_context = new ASDCP::HMACContext;
-
- ASDCP::LabelSet_t type;
- if (standard == INTEROP) {
- type = ASDCP::LS_MXF_INTEROP;
- } else {
- type = ASDCP::LS_MXF_SMPTE;
- }
-
- if (ASDCP_FAILURE (_hmac_context->InitKey (mxf->key()->value(), type))) {
- throw MiscError ("could not set up HMAC context");
- }
- }
-}
-
-AssetWriter::~AssetWriter ()
-{
- delete _encryption_context;
- delete _hmac_context;
}
/** @return true if anything was written by this writer */
#include "types.h"
#include <boost/filesystem.hpp>
-namespace ASDCP {
- class AESEncContext;
- class HMACContext;
-}
-
namespace dcp {
class MXF;
+class EncryptionContext;
/** @class AssetWriter
* @brief Parent class for classes which can write MXF-based assets.
class AssetWriter : public boost::noncopyable
{
public:
- virtual ~AssetWriter ();
+ virtual ~AssetWriter () {}
virtual bool finalize ();
int64_t frames_written () const {
bool _finalized;
/** true if something has been written to this asset */
bool _started;
- ASDCP::AESEncContext* _encryption_context;
- ASDCP::HMACContext* _hmac_context;
+ boost::shared_ptr<EncryptionContext> _encryption_context;
};
}
--- /dev/null
+/*
+ Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libdcp is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+#include "encryption_context.h"
+#include "exceptions.h"
+#include <asdcp/AS_DCP.h>
+#include <asdcp/KM_prng.h>
+
+using boost::optional;
+using namespace dcp;
+
+EncryptionContext::EncryptionContext (optional<Key> key, Standard standard)
+ : _encryption (0)
+ , _hmac (0)
+{
+ if (!key) {
+ return;
+ }
+
+ _encryption = new ASDCP::AESEncContext;
+ if (ASDCP_FAILURE (_encryption->InitKey (key->value ()))) {
+ throw MiscError ("could not set up encryption context");
+ }
+
+ uint8_t cbc_buffer[ASDCP::CBC_BLOCK_SIZE];
+
+ Kumu::FortunaRNG rng;
+ if (ASDCP_FAILURE (_encryption->SetIVec (rng.FillRandom (cbc_buffer, ASDCP::CBC_BLOCK_SIZE)))) {
+ throw MiscError ("could not set up CBC initialization vector");
+ }
+
+ _hmac = new ASDCP::HMACContext;
+
+ ASDCP::LabelSet_t type;
+ if (standard == INTEROP) {
+ type = ASDCP::LS_MXF_INTEROP;
+ } else {
+ type = ASDCP::LS_MXF_SMPTE;
+ }
+
+ if (ASDCP_FAILURE (_hmac->InitKey (key->value(), type))) {
+ throw MiscError ("could not set up HMAC context");
+ }
+}
+
+EncryptionContext::~EncryptionContext ()
+{
+ delete _encryption;
+ delete _hmac;
+}
--- /dev/null
+/*
+ Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+
+ This file is part of libdcp.
+
+ libdcp is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ libdcp is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libdcp. If not, see <http://www.gnu.org/licenses/>.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of portions of this program with the
+ OpenSSL library under certain conditions as described in each
+ individual source file, and distribute linked combinations
+ including the two.
+
+ You must obey the GNU General Public License in all respects
+ for all of the code used other than OpenSSL. If you modify
+ file(s) with this exception, you may extend this exception to your
+ version of the file(s), but you are not obligated to do so. If you
+ do not wish to do so, delete this exception statement from your
+ version. If you delete this exception statement from all source
+ files in the program, then also delete it here.
+*/
+
+#include "key.h"
+#include "types.h"
+#include <boost/optional.hpp>
+
+namespace ASDCP {
+ class AESEncContext;
+ class HMACContext;
+}
+
+namespace dcp {
+
+class EncryptionContext
+{
+public:
+ EncryptionContext (boost::optional<Key> key, Standard standard);
+ ~EncryptionContext ();
+
+ ASDCP::AESEncContext* encryption () const {
+ return _encryption;
+ }
+
+ ASDCP::HMACContext* hmac () const {
+ return _hmac;
+ }
+
+private:
+ ASDCP::AESEncContext* _encryption;
+ ASDCP::HMACContext* _hmac;
+};
+
+}
#include "exceptions.h"
#include "picture_asset.h"
#include "dcp_assert.h"
+#include "encryption_context.h"
#include <asdcp/AS_DCP.h>
#include <asdcp/KM_fileio.h>
uint64_t const before_offset = _state->mxf_writer.Tell ();
string hash;
- ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context, _hmac_context, &hash);
+ ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context->encryption(), _encryption_context->hmac(), &hash);
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MXFFileError ("error in writing video MXF", _file.string(), r));
}
#include "dcp_assert.h"
#include "util.h"
#include "compose.hpp"
+#include "encryption_context.h"
#include <asdcp/AS_DCP.h>
#include <asdcp/KM_util.h>
#include <libxml++/libxml++.h>
void
SMPTESubtitleAsset::write (boost::filesystem::path p) const
{
+ EncryptionContext enc (key (), SMPTE);
+
ASDCP::WriterInfo writer_info;
fill_writer_info (&writer_info, _id, SMPTE);
}
/* XXX: no encryption */
- r = writer.WriteTimedTextResource (xml_as_string ());
+ r = writer.WriteTimedTextResource (xml_as_string (), enc.encryption(), enc.hmac());
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MXFFileError ("could not write XML to timed text resource", p.string(), r));
}
ASDCP::TimedText::FrameBuffer buffer;
buffer.SetData (j->data.data().get(), j->data.size());
buffer.Size (j->data.size());
- r = writer.WriteAncillaryResource (buffer);
+ r = writer.WriteAncillaryResource (buffer, enc.encryption(), enc.hmac());
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MXFFileError ("could not write font to timed text resource", p.string(), r));
}
#include "exceptions.h"
#include "dcp_assert.h"
#include "compose.hpp"
+#include "encryption_context.h"
#include <asdcp/AS_DCP.h>
using std::min;
void
SoundAssetWriter::write_current_frame ()
{
- ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context, _hmac_context);
+ ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context->encryption(), _encryption_context->hmac());
if (ASDCP_FAILURE (r)) {
boost::throw_exception (MiscError (String::compose ("could not write audio MXF frame (%1)", int (r))));
}
#include "exceptions.h"
#include "dcp_assert.h"
#include "picture_asset.h"
+#include "encryption_context.h"
#include <asdcp/AS_DCP.h>
#include <asdcp/KM_fileio.h>
Kumu::Result_t r = _state->mxf_writer.WriteFrame (
_state->frame_buffer,
_next_eye == EYE_LEFT ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT,
- _encryption_context,
- _hmac_context,
+ _encryption_context->encryption(),
+ _encryption_context->hmac(),
&hash
);
decrypted_kdm.cc
decrypted_kdm_key.cc
encrypted_kdm.cc
+ encryption_context.cc
exceptions.cc
file.cc
font_asset.cc
decrypted_kdm.h
decrypted_kdm_key.h
encrypted_kdm.h
+ encryption_context.h
exceptions.h
font_asset.h
gamma_transfer_function.h