2 Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
35 #include "mono_picture_frame.h"
37 #include "decrypted_kdm.h"
38 #include "encrypted_kdm.h"
39 #include "mono_picture_asset.h"
40 #include "mono_picture_asset_reader.h"
41 #include "reel_picture_asset.h"
44 #include "openjpeg_image.h"
46 #include "colour_conversion.h"
47 #include "stream_operators.h"
48 #include <boost/test/unit_test.hpp>
49 #include <boost/scoped_array.hpp>
53 using std::dynamic_pointer_cast;
54 using std::shared_ptr;
55 using boost::scoped_array;
57 pair<uint8_t*, dcp::Size>
58 get_frame (dcp::DCP const & dcp)
60 shared_ptr<const dcp::Reel> reel = dcp.cpls().front()->reels().front ();
61 shared_ptr<dcp::PictureAsset> picture = reel->main_picture()->asset ();
62 BOOST_CHECK (picture);
64 shared_ptr<const dcp::MonoPictureAsset> mono_picture = dynamic_pointer_cast<const dcp::MonoPictureAsset> (picture);
65 shared_ptr<const dcp::MonoPictureAssetReader> reader = mono_picture->start_read ();
66 shared_ptr<const dcp::MonoPictureFrame> j2k_frame = reader->get_frame (0);
67 shared_ptr<dcp::OpenJPEGImage> xyz = j2k_frame->xyz_image();
69 uint8_t* argb = new uint8_t[xyz->size().width * xyz->size().height * 4];
70 dcp::xyz_to_rgba (j2k_frame->xyz_image(), dcp::ColourConversion::srgb_to_xyz(), argb, xyz->size().width * 4);
71 return make_pair (argb, xyz->size ());
74 /** Decrypt an encrypted test DCP and check that its first frame is the same as the unencrypted version */
75 BOOST_AUTO_TEST_CASE (decryption_test)
77 boost::filesystem::path plaintext_path = private_test;
78 plaintext_path /= "TONEPLATES-SMPTE-PLAINTEXT_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV";
79 dcp::DCP plaintext (plaintext_path.string ());
81 BOOST_CHECK_EQUAL (plaintext.any_encrypted(), false);
83 boost::filesystem::path encrypted_path = private_test;
84 encrypted_path /= "TONEPLATES-SMPTE-ENCRYPTED_TST_F_XX-XX_ITL-TD_51-XX_2K_WOE_20111001_WOE_OV";
85 dcp::DCP encrypted (encrypted_path.string ());
87 BOOST_CHECK_EQUAL (encrypted.any_encrypted(), true);
89 dcp::DecryptedKDM kdm (
91 dcp::file_to_string ("test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml")
93 dcp::file_to_string ("test/data/private.key")
98 pair<uint8_t *, dcp::Size> plaintext_frame = get_frame (plaintext);
99 pair<uint8_t *, dcp::Size> encrypted_frame = get_frame (encrypted);
101 /* Check that plaintext and encrypted are the same */
103 BOOST_CHECK_EQUAL (plaintext_frame.second, encrypted_frame.second);
107 plaintext_frame.first,
108 encrypted_frame.first,
109 plaintext_frame.second.width * plaintext_frame.second.height * 4
114 delete[] plaintext_frame.first;
115 delete[] encrypted_frame.first;
118 /** Load in a KDM that didn't work at first */
119 BOOST_AUTO_TEST_CASE (failing_kdm_test)
121 dcp::DecryptedKDM kdm (
122 dcp::EncryptedKDM (dcp::file_to_string ("test/data/target.pem.crt.de5d4eba-e683-41ca-bdda-aa4ad96af3f4.kdm.xml")),
123 dcp::file_to_string ("test/data/private.key")