From 56a6b3277b7acb7fcfac97ef9667467d764ea490 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 17 Aug 2020 20:28:24 +0200 Subject: Make use of HMAC optional. --- src/asset_reader.h | 4 ++-- src/asset_writer.cc | 4 ++-- src/asset_writer.h | 2 +- src/crypto_context.h | 11 ++++++----- src/mono_picture_asset.cc | 6 +++--- src/mono_picture_asset.h | 4 ++-- src/smpte_subtitle_asset.cc | 6 +++--- src/sound_asset.cc | 6 +++--- src/sound_asset.h | 4 ++-- 9 files changed, 24 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/asset_reader.h b/src/asset_reader.h index dbd2761b..380474af 100644 --- a/src/asset_reader.h +++ b/src/asset_reader.h @@ -47,8 +47,8 @@ template class AssetReader : public boost::noncopyable { public: - explicit AssetReader (Asset const * asset, boost::optional key, Standard standard) - : _crypto_context (new DecryptionContext (key, standard)) + explicit AssetReader (Asset const * asset, boost::optional key, Standard standard, bool check_hmac = true) + : _crypto_context (new DecryptionContext(key, standard, check_hmac)) { _reader = new R (); DCP_ASSERT (asset->file ()); diff --git a/src/asset_writer.cc b/src/asset_writer.cc index c4302f4a..055f2844 100644 --- a/src/asset_writer.cc +++ b/src/asset_writer.cc @@ -48,13 +48,13 @@ 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, bool write_hmac) : _mxf (mxf) , _file (file) , _frames_written (0) , _finalized (false) , _started (false) - , _crypto_context (new EncryptionContext (mxf->key(), mxf->standard())) + , _crypto_context (new EncryptionContext(mxf->key(), mxf->standard(), write_hmac)) { } diff --git a/src/asset_writer.h b/src/asset_writer.h index 2970b8d3..5f7dbd95 100644 --- a/src/asset_writer.h +++ b/src/asset_writer.h @@ -64,7 +64,7 @@ public: } protected: - AssetWriter (MXF* mxf, boost::filesystem::path file); + AssetWriter (MXF* mxf, boost::filesystem::path file, bool write_hmac = true); /** MXF that we are writing */ MXF* _mxf; diff --git a/src/crypto_context.h b/src/crypto_context.h index b01efce4..e8ed5857 100644 --- a/src/crypto_context.h +++ b/src/crypto_context.h @@ -47,7 +47,7 @@ template class CryptoContext { public: - CryptoContext (boost::optional key, Standard standard) + CryptoContext (boost::optional key, Standard standard, bool use_hmac) : _context (0) , _hmac (0) { @@ -67,8 +67,6 @@ public: 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; @@ -76,8 +74,11 @@ public: type = ASDCP::LS_MXF_SMPTE; } - if (ASDCP_FAILURE (_hmac->InitKey (key->value(), type))) { - throw MiscError ("could not set up HMAC context"); + if (use_hmac) { + _hmac = new ASDCP::HMACContext; + if (ASDCP_FAILURE(_hmac->InitKey(key->value(), type))) { + throw MiscError ("could not set up HMAC context"); + } } } diff --git a/src/mono_picture_asset.cc b/src/mono_picture_asset.cc index 47fc8f55..3797fbec 100644 --- a/src/mono_picture_asset.cc +++ b/src/mono_picture_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of libdcp. @@ -174,9 +174,9 @@ MonoPictureAsset::start_write (boost::filesystem::path file, bool overwrite) } shared_ptr -MonoPictureAsset::start_read () const +MonoPictureAsset::start_read (bool check_hmac) const { - return shared_ptr (new MonoPictureAssetReader (this, key(), standard())); + return shared_ptr (new MonoPictureAssetReader(this, key(), standard(), check_hmac)); } string diff --git a/src/mono_picture_asset.h b/src/mono_picture_asset.h index 7a1c0d0a..6f34dbe4 100644 --- a/src/mono_picture_asset.h +++ b/src/mono_picture_asset.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of libdcp. @@ -60,7 +60,7 @@ public: /** Start a progressive write to a MonoPictureAsset */ boost::shared_ptr start_write (boost::filesystem::path, bool); - boost::shared_ptr start_read () const; + boost::shared_ptr start_read (bool check_hmac = true) const; bool equals ( boost::shared_ptr other, diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 6a62bc1d..29a423a4 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -97,7 +97,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) reader->ReadTimedTextResource (_raw_xml); xml->read_string (_raw_xml); parse_xml (xml); - read_mxf_descriptor (reader, shared_ptr (new DecryptionContext (optional(), SMPTE))); + read_mxf_descriptor (reader, shared_ptr (new DecryptionContext (optional(), SMPTE, true))); } } else { /* Plain XML */ @@ -278,7 +278,7 @@ SMPTESubtitleAsset::set_key (Key key) ); } - shared_ptr dec (new DecryptionContext (key, SMPTE)); + shared_ptr dec (new DecryptionContext(key, SMPTE, true)); reader->ReadTimedTextResource (_raw_xml, dec->context(), dec->hmac()); shared_ptr xml (new cxml::Document ("SubtitleReel")); xml->read_string (_raw_xml); @@ -345,7 +345,7 @@ SMPTESubtitleAsset::xml_as_string () const void SMPTESubtitleAsset::write (boost::filesystem::path p) const { - EncryptionContext enc (key(), SMPTE); + EncryptionContext enc (key(), SMPTE, true); ASDCP::WriterInfo writer_info; fill_writer_info (&writer_info, _id); diff --git a/src/sound_asset.cc b/src/sound_asset.cc index 7f2bf5e3..2295d138 100644 --- a/src/sound_asset.cc +++ b/src/sound_asset.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of libdcp. @@ -203,9 +203,9 @@ SoundAsset::start_write (boost::filesystem::path file, bool atmos_sync) } shared_ptr -SoundAsset::start_read () const +SoundAsset::start_read (bool check_hmac) const { - return shared_ptr (new SoundAssetReader (this, key(), standard())); + return shared_ptr (new SoundAssetReader (this, key(), standard(), check_hmac)); } string diff --git a/src/sound_asset.h b/src/sound_asset.h index 9656cf90..b0bb01be 100644 --- a/src/sound_asset.h +++ b/src/sound_asset.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington + Copyright (C) 2012-2020 Carl Hetherington This file is part of libdcp. @@ -59,7 +59,7 @@ public: SoundAsset (Fraction edit_rate, int sampling_rate, int channels, Standard standard); boost::shared_ptr start_write (boost::filesystem::path file, bool atmos_sync = false); - boost::shared_ptr start_read () const; + boost::shared_ptr start_read (bool check_hmac = true) const; bool equals ( boost::shared_ptr other, -- cgit v1.2.3