diff options
| author | Carl Hetherington <cth@carlh.net> | 2016-02-28 23:27:23 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2016-02-28 23:27:23 +0000 |
| commit | 6db8817ab5c9387dc6528f88d1f1a88c3da0fea5 (patch) | |
| tree | 03303b686665dfdf2780332b899e59ee26979ccc /src | |
| parent | c9717810952874f38c58b526abf4875abf38534c (diff) | |
Use a HMAC context to write HMAC stuff to encrypted MXFs.
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_writer.cc | 17 | ||||
| -rw-r--r-- | src/asset_writer.h | 5 | ||||
| -rw-r--r-- | src/mono_picture_asset_writer.cc | 2 | ||||
| -rw-r--r-- | src/picture_asset_writer.cc | 2 | ||||
| -rw-r--r-- | src/sound_asset_writer.cc | 4 | ||||
| -rw-r--r-- | src/stereo_picture_asset_writer.cc | 2 |
6 files changed, 25 insertions, 7 deletions
diff --git a/src/asset_writer.cc b/src/asset_writer.cc index 13adc50e..7a3e9882 100644 --- a/src/asset_writer.cc +++ b/src/asset_writer.cc @@ -33,13 +33,14 @@ using namespace dcp; * @param mxf MXF that we are writing. * @param file File to write to. */ -AssetWriter::AssetWriter (MXF* mxf, boost::filesystem::path file) +AssetWriter::AssetWriter (MXF* mxf, boost::filesystem::path file, Standard standard) : _mxf (mxf) , _file (file) , _frames_written (0) , _finalized (false) , _started (false) , _encryption_context (0) + , _hmac_context (0) { if (mxf->key ()) { _encryption_context = new ASDCP::AESEncContext; @@ -53,12 +54,26 @@ AssetWriter::AssetWriter (MXF* mxf, boost::filesystem::path file) 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 */ diff --git a/src/asset_writer.h b/src/asset_writer.h index 4266c719..183619d2 100644 --- a/src/asset_writer.h +++ b/src/asset_writer.h @@ -24,10 +24,12 @@ #ifndef LIBDCP_ASSET_WRITER_H #define LIBDCP_ASSET_WRITER_H +#include "types.h" #include <boost/filesystem.hpp> namespace ASDCP { class AESEncContext; + class HMACContext; } namespace dcp { @@ -51,7 +53,7 @@ public: } protected: - AssetWriter (MXF* mxf, boost::filesystem::path file); + AssetWriter (MXF* mxf, boost::filesystem::path file, Standard standard); /** MXF that we are writing */ MXF* _mxf; @@ -66,6 +68,7 @@ protected: /** true if something has been written to this asset */ bool _started; ASDCP::AESEncContext* _encryption_context; + ASDCP::HMACContext* _hmac_context; }; } diff --git a/src/mono_picture_asset_writer.cc b/src/mono_picture_asset_writer.cc index 564a5ea1..54339ed5 100644 --- a/src/mono_picture_asset_writer.cc +++ b/src/mono_picture_asset_writer.cc @@ -74,7 +74,7 @@ MonoPictureAssetWriter::write (uint8_t* data, int size) 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, 0, &hash); + ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context, _hmac_context, &hash); if (ASDCP_FAILURE (r)) { boost::throw_exception (MXFFileError ("error in writing video MXF", _file.string(), r)); } diff --git a/src/picture_asset_writer.cc b/src/picture_asset_writer.cc index 3bb6a597..24e925f8 100644 --- a/src/picture_asset_writer.cc +++ b/src/picture_asset_writer.cc @@ -32,7 +32,7 @@ using boost::shared_ptr; using namespace dcp; PictureAssetWriter::PictureAssetWriter (PictureAsset* asset, boost::filesystem::path file, Standard standard, bool overwrite) - : AssetWriter (asset, file) + : AssetWriter (asset, file, standard) , _picture_asset (asset) , _standard (standard) , _overwrite (overwrite) diff --git a/src/sound_asset_writer.cc b/src/sound_asset_writer.cc index f1e17615..a716b654 100644 --- a/src/sound_asset_writer.cc +++ b/src/sound_asset_writer.cc @@ -37,7 +37,7 @@ struct SoundAssetWriter::ASDCPState }; SoundAssetWriter::SoundAssetWriter (SoundAsset* asset, boost::filesystem::path file, Standard standard) - : AssetWriter (asset, file) + : AssetWriter (asset, file, standard) , _state (new SoundAssetWriter::ASDCPState) , _sound_asset (asset) , _frame_buffer_offset (0) @@ -105,7 +105,7 @@ SoundAssetWriter::write (float const * const * data, int frames) void SoundAssetWriter::write_current_frame () { - ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context, 0); + ASDCP::Result_t const r = _state->mxf_writer.WriteFrame (_state->frame_buffer, _encryption_context, _hmac_context); if (ASDCP_FAILURE (r)) { boost::throw_exception (MiscError (String::compose ("could not write audio MXF frame (%1)", int (r)))); } diff --git a/src/stereo_picture_asset_writer.cc b/src/stereo_picture_asset_writer.cc index 322c7b00..aaa82b2a 100644 --- a/src/stereo_picture_asset_writer.cc +++ b/src/stereo_picture_asset_writer.cc @@ -76,7 +76,7 @@ StereoPictureAssetWriter::write (uint8_t* data, int size) _state->frame_buffer, _next_eye == EYE_LEFT ? ASDCP::JP2K::SP_LEFT : ASDCP::JP2K::SP_RIGHT, _encryption_context, - 0, + _hmac_context, &hash ); |
