2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/test/unit_test.hpp>
24 #include "certificates.h"
28 #include "mono_picture_asset.h"
29 #include "sound_asset.h"
32 #include "signer_chain.h"
34 using boost::shared_ptr;
36 /* Load a certificate chain from build/test/data/ *.pem and then build
37 an encrypted DCP and a KDM using it.
39 BOOST_AUTO_TEST_CASE (encryption)
41 boost::filesystem::remove_all ("build/test/signer");
42 boost::filesystem::create_directory ("build/test/signer");
43 libdcp::make_signer_chain ("build/test/signer", "openssl");
45 Kumu::libdcp_test = true;
47 libdcp::MXFMetadata mxf_metadata;
48 mxf_metadata.company_name = "OpenDCP";
49 mxf_metadata.product_name = "OpenDCP";
50 mxf_metadata.product_version = "0.0.25";
52 libdcp::XMLMetadata xml_metadata;
53 xml_metadata.issuer = "OpenDCP 0.0.25";
54 xml_metadata.creator = "OpenDCP 0.0.25";
55 xml_metadata.issue_date = "2012-07-17T04:45:18+00:00";
57 boost::filesystem::remove_all ("build/test/DCP/bar");
58 boost::filesystem::create_directories ("build/test/DCP/bar");
59 libdcp::DCP d ("build/test/DCP/bar");
61 /* Use test/ref/crypt so this test is repeatable */
62 libdcp::CertificateChain chain;
63 chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("test/ref/crypt/ca.self-signed.pem"))));
64 chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("test/ref/crypt/intermediate.signed.pem"))));
65 chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("test/ref/crypt/leaf.signed.pem"))));
67 shared_ptr<libdcp::Signer> signer (
70 "test/ref/crypt/leaf.key"
74 shared_ptr<libdcp::CPL> cpl (new libdcp::CPL ("build/test/DCP/bar", "A Test DCP", libdcp::FEATURE, 24, 24));
78 shared_ptr<libdcp::MonoPictureAsset> mp (new libdcp::MonoPictureAsset ("build/test/DCP/bar", "video.mxf"));
79 mp->set_progress (&d.Progress);
80 mp->set_edit_rate (24);
81 mp->set_intrinsic_duration (24);
82 mp->set_duration (24);
83 mp->set_size (libdcp::Size (32, 32));
84 mp->set_metadata (mxf_metadata);
88 shared_ptr<libdcp::SoundAsset> ms (new libdcp::SoundAsset ("build/test/DCP/bar", "audio.mxf"));
89 ms->set_progress (&d.Progress);
90 ms->set_edit_rate (24);
91 ms->set_intrinsic_duration (24);
92 mp->set_duration (24);
94 ms->set_metadata (mxf_metadata);
98 cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (mp, ms, shared_ptr<libdcp::SubtitleAsset> ())));
101 d.write_xml (false, xml_metadata, signer);
103 boost::filesystem::path cpl_path = boost::filesystem::path ("build/test/DCP/bar") / (cpl->id() + "_cpl.xml");
108 signer->certificates().leaf(),
110 boost::posix_time::time_from_string ("2013-01-01 00:00:00"),
111 boost::posix_time::time_from_string ("2013-01-08 00:00:00"),
113 "2012-07-17T04:45:18+00:00",
114 libdcp::KDM::MODIFIED_TRANSITIONAL_1
117 kdm.as_xml ("build/test/bar.kdm.xml");
120 "xmllint --path schema --nonet --noout --schema schema/SMPTE-430-1-2006-Amd-1-2009-KDM.xsd build/test/bar.kdm.xml "
121 "> build/test/xmllint.log 2>&1 < /dev/null"
124 #ifdef DCPOMATIC_POSIX
125 BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0);
127 BOOST_CHECK_EQUAL (r, 0);
130 r = system ("xmlsec1 verify "
131 "--pubkey-cert-pem test/ref/crypt/leaf.signed.pem "
132 "--trusted-pem test/ref/crypt/intermediate.signed.pem "
133 "--trusted-pem test/ref/crypt/ca.self-signed.pem "
134 "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPublic "
135 "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPrivate "
136 "build/test/bar.kdm.xml > build/test/xmlsec1.log 2>&1 < /dev/null");
138 #ifdef DCPOMATIC_POSIX
139 BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0);
141 BOOST_CHECK_EQUAL (r, 0);