Supporters update.
[dcpomatic.git] / test / vf_kdm_test.cc
1 /*
2     Copyright (C) 2017-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic 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.
10
11     DCP-o-matic 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.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 /** @file  test/vf_kdm_test.cc
23  *  @brief Test encrypted VF creation and import
24  *  @ingroup feature
25  */
26
27
28 #include "test.h"
29 #include "lib/config.h"
30 #include "lib/constants.h"
31 #include "lib/cross.h"
32 #include "lib/dcp_content.h"
33 #include "lib/dcp_content_type.h"
34 #include "lib/dcp_subtitle_content.h"
35 #include "lib/ffmpeg_content.h"
36 #include "lib/film.h"
37 #include "lib/ratio.h"
38 #include "lib/screen.h"
39 #include <dcp/cpl.h>
40 #include <boost/test/unit_test.hpp>
41
42
43 using std::make_shared;
44 using std::string;
45 using std::vector;
46
47
48 BOOST_AUTO_TEST_CASE (vf_kdm_test)
49 {
50         ConfigRestorer cr;
51
52         /* Make an encrypted DCP from test.mp4 */
53
54         auto A = new_test_film ("vf_kdm_test_ov");
55         A->set_container (Ratio::from_id ("185"));
56         A->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
57         A->set_name ("frobozz");
58         A->set_interop (true);
59
60         auto c = make_shared<FFmpegContent>("test/data/test.mp4");
61         A->examine_and_add_content (c);
62         A->set_encrypted (true);
63         BOOST_REQUIRE (!wait_for_jobs());
64         make_and_verify_dcp (A, {dcp::VerificationNote::Code::INVALID_STANDARD});
65
66         dcp::DCP A_dcp ("build/test/vf_kdm_test_ov/" + A->dcp_name());
67         A_dcp.read ();
68
69         Config::instance()->set_decryption_chain (make_shared<dcp::CertificateChain>(openssl_path(), CERTIFICATE_VALIDITY_PERIOD));
70
71         auto signer = Config::instance()->signer_chain();
72         BOOST_REQUIRE(signer->valid());
73
74         auto const A_decrypted_kdm = A->make_kdm(A_dcp.cpls().front()->file().get(), dcp::LocalTime("2030-07-21T00:00:00+00:00"), dcp::LocalTime("2031-07-21T00:00:00+00:00"));
75         auto const A_kdm = A_decrypted_kdm.encrypt(signer, Config::instance()->decryption_chain()->leaf(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, true, 0);
76
77         /* Import A into a new project, with the required KDM, and make a VF that refers to it */
78
79         auto B = new_test_film ("vf_kdm_test_vf");
80         B->set_container (Ratio::from_id("185"));
81         B->set_dcp_content_type (DCPContentType::from_isdcf_name("TLR"));
82         B->set_name ("frobozz");
83         B->set_interop (true);
84
85         auto d = make_shared<DCPContent>("build/test/vf_kdm_test_ov/" + A->dcp_name());
86         d->add_kdm (A_kdm);
87         d->set_reference_video (true);
88         B->examine_and_add_content (d);
89         B->set_encrypted (true);
90         BOOST_REQUIRE (!wait_for_jobs());
91         make_and_verify_dcp (B, {dcp::VerificationNote::Code::INVALID_STANDARD, dcp::VerificationNote::Code::EXTERNAL_ASSET});
92
93         dcp::DCP B_dcp ("build/test/vf_kdm_test_vf/" + B->dcp_name());
94         B_dcp.read ();
95
96         auto const B_decrypted_kdm = B->make_kdm(B_dcp.cpls().front()->file().get(), dcp::LocalTime ("2030-07-21T00:00:00+00:00"), dcp::LocalTime ("2031-07-21T00:00:00+00:00"));
97         auto const B_kdm = B_decrypted_kdm.encrypt(signer, Config::instance()->decryption_chain()->leaf(), {}, dcp::Formulation::MODIFIED_TRANSITIONAL_1, true, 0);
98
99         /* Import the OV and VF into a new project with the KDM that was created for the VF.
100            This KDM should decrypt assets from the OV too.
101         */
102
103         auto C = new_test_film ("vf_kdm_test_check");
104         C->set_container (Ratio::from_id ("185"));
105         C->set_dcp_content_type (DCPContentType::from_isdcf_name ("TLR"));
106         C->set_name ("frobozz");
107         C->set_interop (true);
108
109         auto e = make_shared<DCPContent>("build/test/vf_kdm_test_vf/" + B->dcp_name());
110         e->add_kdm (B_kdm);
111         e->add_ov ("build/test/vf_kdm_test_ov/" + A->dcp_name());
112         C->examine_and_add_content (e);
113         C->set_audio_channels(6);
114         BOOST_REQUIRE (!wait_for_jobs());
115         make_and_verify_dcp (C, {dcp::VerificationNote::Code::INVALID_STANDARD});
116
117         /* Should be 1s red, 1s green, 1s blue */
118         check_dcp ("test/data/vf_kdm_test_check", "build/test/vf_kdm_test_check/" + C->dcp_name());
119 }