2 Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
26 #include "kdm_with_metadata.h"
28 #include <libxml++/libxml++.h>
29 #include <boost/algorithm/string.hpp>
30 #include <boost/date_time/posix_time/posix_time.hpp>
34 using std::make_shared;
35 using std::shared_ptr;
38 using boost::optional;
39 using namespace dcpomatic;
42 Screen::Screen (cxml::ConstNodePtr node)
45 for (auto i: node->node_children ("TrustedDevice")) {
46 if (boost::algorithm::starts_with(i->content(), "-----BEGIN CERTIFICATE-----")) {
47 trusted_devices.push_back (TrustedDevice(dcp::Certificate(i->content())));
49 trusted_devices.push_back (TrustedDevice(i->content()));
56 Screen::as_xml (xmlpp::Element* parent) const
58 KDMRecipient::as_xml (parent);
59 for (auto i: trusted_devices) {
60 parent->add_child("TrustedDevice")->add_child_text(i.as_string());
66 Screen::trusted_device_thumbprints () const
69 for (auto i: trusted_devices) {
70 t.push_back (i.thumbprint());
78 std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm,
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
88 if (!screen->recipient) {
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));
96 period_checks.push_back(check_kdm_and_certificate_validity_periods(screen->recipient.get(), begin, end));
98 auto signer = Config::instance()->signer_chain();
99 if (!signer->valid()) {
100 throw InvalidSignerError();
103 auto kdm = make_kdm(begin, end).encrypt(
104 signer, screen->recipient.get(), screen->trusted_device_thumbprints(), formulation, disable_forensic_marking_picture, disable_forensic_marking_audio
107 dcp::NameFormat::Map name_values;
109 name_values['c'] = cinema->name;
111 name_values['c'] = "";
113 name_values['s'] = screen->name;
114 name_values['f'] = kdm.content_title_text();
115 name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
116 name_values['e'] = end.date() + " " + end.time_of_day(true, false);
117 name_values['i'] = kdm.cpl_id();
119 return make_shared<KDMWithMetadata>(name_values, cinema.get(), cinema ? cinema->emails : vector<string>(), kdm);