2 Copyright (C) 2013-2014 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.
23 #include "certificates.h"
27 #include "mono_picture_mxf.h"
28 #include "picture_mxf_writer.h"
29 #include "sound_mxf.h"
33 #include "signer_chain.h"
34 #include "subtitle_content.h"
35 #include "reel_mono_picture_asset.h"
36 #include "reel_sound_asset.h"
37 #include <boost/test/unit_test.hpp>
38 #include <boost/shared_ptr.hpp>
40 using boost::shared_ptr;
42 /* Load a certificate chain from build/test/data/ *.pem and then build
43 an encrypted DCP and a KDM using it.
45 BOOST_AUTO_TEST_CASE (encryption_test)
47 boost::filesystem::remove_all ("build/test/signer");
48 boost::filesystem::create_directory ("build/test/signer");
49 dcp::make_signer_chain ("build/test/signer", "openssl");
51 Kumu::libdcp_test = true;
53 dcp::MXFMetadata mxf_metadata;
54 mxf_metadata.company_name = "OpenDCP";
55 mxf_metadata.product_name = "OpenDCP";
56 mxf_metadata.product_version = "0.0.25";
58 dcp::XMLMetadata xml_metadata;
59 xml_metadata.issuer = "OpenDCP 0.0.25";
60 xml_metadata.creator = "OpenDCP 0.0.25";
61 xml_metadata.issue_date = "2012-07-17T04:45:18+00:00";
63 boost::filesystem::remove_all ("build/test/DCP/bar");
64 boost::filesystem::create_directories ("build/test/DCP/bar");
65 dcp::DCP d ("build/test/DCP/bar");
67 /* Use test/ref/crypt so this test is repeatable */
68 dcp::CertificateChain chain;
69 chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("test/ref/crypt/ca.self-signed.pem"))));
70 chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("test/ref/crypt/intermediate.signed.pem"))));
71 chain.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (boost::filesystem::path ("test/ref/crypt/leaf.signed.pem"))));
73 shared_ptr<dcp::Signer> signer (
76 "test/ref/crypt/leaf.key"
80 shared_ptr<dcp::CPL> cpl (new dcp::CPL ("A Test DCP", dcp::FEATURE));
84 shared_ptr<dcp::MonoPictureMXF> mp (new dcp::MonoPictureMXF (dcp::Fraction (24, 1)));
85 mp->set_metadata (mxf_metadata);
88 shared_ptr<dcp::PictureMXFWriter> writer = mp->start_write ("build/test/DCP/bar/video.mxf", dcp::SMPTE, false);
89 dcp::File j2c ("test/data/32x32_red_square.j2c");
90 for (int i = 0; i < 24; ++i) {
91 writer->write (j2c.data (), j2c.size ());
95 cpl->add (shared_ptr<dcp::Reel> (new dcp::Reel (
96 shared_ptr<dcp::ReelMonoPictureAsset> (new dcp::ReelMonoPictureAsset (mp, 0)),
97 shared_ptr<dcp::ReelSoundAsset> (),
98 shared_ptr<dcp::ReelSubtitleAsset> ()
101 d.write_xml (dcp::SMPTE, xml_metadata, signer);
106 signer->certificates().leaf(),
107 boost::posix_time::time_from_string ("2013-01-01 00:00:00"),
108 boost::posix_time::time_from_string ("2013-01-08 00:00:00"),
110 "2012-07-17T04:45:18+00:00"
113 kdm.as_xml ("build/test/bar.kdm.xml");
116 "xmllint --path schema --nonet --noout --schema schema/SMPTE-430-1-2006-Amd-1-2009-KDM.xsd build/test/bar.kdm.xml "
117 "> build/test/xmllint.log 2>&1 < /dev/null"
120 BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0);
122 r = system ("xmlsec1 verify "
123 "--pubkey-cert-pem test/ref/crypt/leaf.signed.pem "
124 "--trusted-pem test/ref/crypt/intermediate.signed.pem "
125 "--trusted-pem test/ref/crypt/ca.self-signed.pem "
126 "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPublic "
127 "--id-attr:Id http://www.smpte-ra.org/schemas/430-3/2006/ETM:AuthenticatedPrivate "
128 "build/test/bar.kdm.xml > build/test/xmlsec1.log 2>&1 < /dev/null");
130 BOOST_CHECK_EQUAL (WEXITSTATUS (r), 0);