2 Copyright (C) 2013-2020 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/>.
22 #include "kdm_with_metadata.h"
25 #include <libxml++/libxml++.h>
26 #include <boost/foreach.hpp>
27 #include <boost/algorithm/string.hpp>
28 #include <boost/date_time/posix_time/posix_time.hpp>
32 using boost::shared_ptr;
33 using boost::optional;
34 using namespace dcpomatic;
36 Screen::Screen (cxml::ConstNodePtr node)
37 : name (node->string_child("Name"))
38 , notes (node->optional_string_child("Notes").get_value_or (""))
40 if (node->optional_string_child ("Certificate")) {
41 recipient = dcp::Certificate (node->string_child ("Certificate"));
42 } else if (node->optional_string_child ("Recipient")) {
43 recipient = dcp::Certificate (node->string_child ("Recipient"));
46 BOOST_FOREACH (cxml::ConstNodePtr i, node->node_children ("TrustedDevice")) {
47 if (boost::algorithm::starts_with(i->content(), "-----BEGIN CERTIFICATE-----")) {
48 trusted_devices.push_back (TrustedDevice(dcp::Certificate(i->content())));
50 trusted_devices.push_back (TrustedDevice(i->content()));
56 Screen::as_xml (xmlpp::Element* parent) const
58 parent->add_child("Name")->add_child_text (name);
60 parent->add_child("Recipient")->add_child_text (recipient->certificate (true));
63 parent->add_child("Notes")->add_child_text (notes);
65 BOOST_FOREACH (TrustedDevice i, trusted_devices) {
66 parent->add_child("TrustedDevice")->add_child_text(i.as_string());
71 Screen::trusted_device_thumbprints () const
74 BOOST_FOREACH (TrustedDevice i, trusted_devices) {
75 t.push_back (i.thumbprint());
80 TrustedDevice::TrustedDevice (string thumbprint)
81 : _thumbprint (thumbprint)
86 TrustedDevice::TrustedDevice (dcp::Certificate certificate)
87 : _certificate (certificate)
93 TrustedDevice::as_string () const
96 return _certificate->certificate(true);
103 TrustedDevice::thumbprint () const
106 return _certificate->thumbprint ();
115 shared_ptr<const Film> film,
116 boost::filesystem::path cpl,
117 shared_ptr<const dcpomatic::Screen> screen,
118 boost::posix_time::ptime valid_from,
119 boost::posix_time::ptime valid_to,
120 dcp::Formulation formulation,
121 bool disable_forensic_marking_picture,
122 optional<int> disable_forensic_marking_audio
125 if (!screen->recipient) {
126 return KDMWithMetadataPtr();
129 shared_ptr<const Cinema> cinema = screen->cinema;
130 dcp::LocalTime const begin(valid_from, cinema ? cinema->utc_offset_hour() : 0, cinema ? cinema->utc_offset_minute() : 0);
131 dcp::LocalTime const end (valid_to, cinema ? cinema->utc_offset_hour() : 0, cinema ? cinema->utc_offset_minute() : 0);
133 dcp::EncryptedKDM const kdm = film->make_kdm (
134 screen->recipient.get(),
135 screen->trusted_device_thumbprints(),
140 disable_forensic_marking_picture,
141 disable_forensic_marking_audio
144 dcp::NameFormat::Map name_values;
146 name_values['c'] = cinema->name;
148 name_values['s'] = screen->name;
149 name_values['f'] = film->name();
150 name_values['b'] = begin.date() + " " + begin.time_of_day(true, false);
151 name_values['e'] = end.date() + " " + end.time_of_day(true, false);
152 name_values['i'] = kdm.cpl_id();
154 return KDMWithMetadataPtr(new DCPKDMWithMetadata(name_values, cinema, kdm));