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 dcp::make_signer_chain ("build/test/signer", "openssl");
45 Kumu::libdcp_test = true;
47 dcp::MXFMetadata mxf_metadata;
48 mxf_metadata.company_name = "OpenDCP";
49 mxf_metadata.product_name = "OpenDCP";
50 mxf_metadata.product_version = "0.0.25";
52 dcp::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 dcp::DCP d ("build/test/DCP/bar");
61 dcp::CertificateChain chain;
62 chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("build/test/signer/ca.self-signed.pem"))));
63 chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("build/test/signer/intermediate.signed.pem"))));
64 chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("build/test/signer/leaf.signed.pem"))));
66 shared_ptr<dcp::Signer> signer (
69 "build/test/signer/leaf.key"
73 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("build/test/DCP/bar", "A Test DCP", dcp::FEATURE, 24, 24));
77 shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset ("build/test/DCP/bar", "video.mxf"));
78 mp->set_progress (&d.Progress);
79 mp->set_edit_rate (24);
80 mp->set_intrinsic_duration (24);
81 mp->set_duration (24);
82 mp->set_size (dcp::Size (32, 32));
83 mp->set_metadata (mxf_metadata);
87 shared_ptr<dcp::SoundAsset> ms (new dcp::SoundAsset ("build/test/DCP/bar", "audio.mxf"));
88 ms->set_progress (&d.Progress);
89 ms->set_edit_rate (24);
90 ms->set_intrinsic_duration (24);
91 mp->set_duration (24);
93 ms->set_metadata (mxf_metadata);
97 cpl->add_reel (shared_ptr<dcp::Reel> (new dcp::Reel (mp, ms, shared_ptr<dcp::SubtitleAsset> ())));
100 d.write_xml (false, xml_metadata, signer);
105 signer->certificates().leaf(),
106 boost::posix_time::time_from_string ("2013-01-01 00:00:00"),
107 boost::posix_time::time_from_string ("2013-01-08 00:00:00"),
109 "2012-07-17T04:45:18+00:00"
112 kdm.as_xml ("build/test/bar.kdm.xml");
113 system ("xmllint --path schema --nonet --noout --schema schema/SMPTE-430-1-2006-Amd-1-2009-KDM.xsd build/test/bar.kdm.xml");
114 system ("xmlsec1 verify "
115 "--pubkey-cert-pem build/test/signer/leaf.signed.pem "
116 "--trusted-pem build/test/signer/intermediate.signed.pem "
117 "--trusted-pem build/test/signer/ca.self-signed.pem "
118 "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPublic "
119 "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPrivate "
120 "build/test/bar.kdm.xml");