Warn/error on making KDMs using recipient certs whose validity periods
[dcpomatic.git] / src / lib / screen.cc
1 /*
2     Copyright (C) 2013-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 #include "cinema.h"
23 #include "film.h"
24 #include "kdm_util.h"
25 #include "kdm_with_metadata.h"
26 #include "screen.h"
27 #include <libxml++/libxml++.h>
28 #include <boost/algorithm/string.hpp>
29 #include <boost/date_time/posix_time/posix_time.hpp>
30
31
32 using std::list;
33 using std::make_shared;
34 using std::shared_ptr;
35 using std::string;
36 using std::vector;
37 using boost::optional;
38 using namespace dcpomatic;
39
40
41 Screen::Screen (cxml::ConstNodePtr node)
42         : KDMRecipient (node)
43 {
44         for (auto i: node->node_children ("TrustedDevice")) {
45                 if (boost::algorithm::starts_with(i->content(), "-----BEGIN CERTIFICATE-----")) {
46                         trusted_devices.push_back (TrustedDevice(dcp::Certificate(i->content())));
47                 } else {
48                         trusted_devices.push_back (TrustedDevice(i->content()));
49                 }
50         }
51 }
52
53
54 void
55 Screen::as_xml (xmlpp::Element* parent) const
56 {
57         KDMRecipient::as_xml (parent);
58         for (auto i: trusted_devices) {
59                 parent->add_child("TrustedDevice")->add_child_text(i.as_string());
60         }
61 }
62
63
64 vector<string>
65 Screen::trusted_device_thumbprints () const
66 {
67         vector<string> t;
68         for (auto i: trusted_devices) {
69                 t.push_back (i.thumbprint());
70         }
71         return t;
72 }
73
74
75 KDMWithMetadataPtr
76 kdm_for_screen (
77         shared_ptr<const Film> film,
78         boost::filesystem::path cpl,
79         shared_ptr<const dcpomatic::Screen> screen,
80         boost::posix_time::ptime valid_from,
81         boost::posix_time::ptime valid_to,
82         dcp::Formulation formulation,
83         bool disable_forensic_marking_picture,
84         optional<int> disable_forensic_marking_audio,
85         vector<KDMCertificatePeriod>& period_checks
86         )
87 {
88         if (!screen->recipient) {
89                 return {};
90         }
91
92         auto cinema = screen->cinema;
93         dcp::LocalTime const begin(valid_from, dcp::UTCOffset(cinema ? cinema->utc_offset_hour() : 0, cinema ? cinema->utc_offset_minute() : 0));
94         dcp::LocalTime const end  (valid_to,   dcp::UTCOffset(cinema ? cinema->utc_offset_hour() : 0, cinema ? cinema->utc_offset_minute() : 0));
95
96         period_checks.push_back(check_kdm_and_certificate_validity_periods(screen->recipient.get(), begin, end));
97
98         auto const kdm = film->make_kdm (
99                         screen->recipient.get(),
100                         screen->trusted_device_thumbprints(),
101                         cpl,
102                         begin,
103                         end,
104                         formulation,
105                         disable_forensic_marking_picture,
106                         disable_forensic_marking_audio
107                         );
108
109         dcp::NameFormat::Map name_values;
110         if (cinema) {
111                 name_values['c'] = cinema->name;
112         } else {
113                 name_values['c'] = "";
114         }
115         name_values['s'] = screen->name;
116         name_values['f'] = kdm.content_title_text();
117         name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
118         name_values['e'] = end.date() + " " + end.time_of_day(true, false);
119         name_values['i'] = kdm.cpl_id();
120
121         return make_shared<KDMWithMetadata>(name_values, cinema.get(), cinema ? cinema->emails : list<string>(), kdm);
122 }
123