Split tests up.
[libdcp.git] / test / encryption_test.cc
1 /*
2     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include <boost/test/unit_test.hpp>
21 #include "kdm.h"
22 #include "KM_util.h"
23 #include "metadata.h"
24 #include "certificates.h"
25 #include "dcp.h"
26 #include "signer.h"
27 #include "cpl.h"
28 #include "picture_asset.h"
29 #include "sound_asset.h"
30 #include "reel.h"
31 #include "test.h"
32
33 using boost::shared_ptr;
34
35 /* Load a certificate chain from build/test/data/ *.pem and then build
36    an encrypted DCP and a KDM using it.
37 */
38 BOOST_AUTO_TEST_CASE (encryption)
39 {
40         Kumu::libdcp_test = true;
41
42         libdcp::MXFMetadata mxf_metadata;
43         mxf_metadata.company_name = "OpenDCP";
44         mxf_metadata.product_name = "OpenDCP";
45         mxf_metadata.product_version = "0.0.25";
46
47         libdcp::XMLMetadata xml_metadata;
48         xml_metadata.issuer = "OpenDCP 0.0.25";
49         xml_metadata.creator = "OpenDCP 0.0.25";
50         xml_metadata.issue_date = "2012-07-17T04:45:18+00:00";
51         
52         boost::filesystem::remove_all ("build/test/bar");
53         boost::filesystem::create_directories ("build/test/bar");
54         libdcp::DCP d ("build/test/DCP/bar");
55
56         libdcp::CertificateChain chain;
57         chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("build/test/signer/ca.self-signed.pem"))));
58         chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("build/test/signer/intermediate.signed.pem"))));
59         chain.add (shared_ptr<libdcp::Certificate> (new libdcp::Certificate (boost::filesystem::path ("build/test/signer/leaf.signed.pem"))));
60
61         shared_ptr<libdcp::Signer> signer (
62                 new libdcp::Signer (
63                         chain,
64                         "test/data/signer.key"
65                         )
66                 );
67
68         shared_ptr<libdcp::CPL> cpl (new libdcp::CPL ("build/test/bar", "A Test DCP", libdcp::FEATURE, 24, 24));
69         
70         shared_ptr<libdcp::MonoPictureAsset> mp (new libdcp::MonoPictureAsset (
71                                                          j2c,
72                                                          "build/test/bar",
73                                                          "video.mxf",
74                                                          &d.Progress,
75                                                          24,
76                                                          24,
77                                                          libdcp::Size (32, 32),
78                                                          false,
79                                                          mxf_metadata
80                                                          ));
81
82         libdcp::Key key;
83
84         mp->set_key (key);
85
86         shared_ptr<libdcp::SoundAsset> ms (new libdcp::SoundAsset (
87                                                    wav,
88                                                    "build/test/bar",
89                                                    "audio.mxf",
90                                                    &(d.Progress),
91                                                    24,
92                                                    24,
93                                                    2,
94                                                    false,
95                                                    mxf_metadata
96                                                    ));
97
98         ms->set_key (key);
99         
100         cpl->add_reel (shared_ptr<libdcp::Reel> (new libdcp::Reel (mp, ms, shared_ptr<libdcp::SubtitleAsset> ())));
101         d.add_cpl (cpl);
102
103         d.write_xml (false, xml_metadata, signer);
104
105         libdcp::KDM kdm (
106                 cpl,
107                 signer,
108                 signer->certificates().leaf(),
109                 boost::posix_time::time_from_string ("2013-01-01 00:00:00"),
110                 boost::posix_time::time_from_string ("2013-01-08 00:00:00"),
111                 "libdcp",
112                 "2012-07-17T04:45:18+00:00"
113                 );
114
115         kdm.as_xml ("build/test/bar.kdm.xml");
116         system ("xmllint --path schema --nonet --noout --schema schema/SMPTE-430-1-2006-Amd-1-2009-KDM.xsd build/test/bar.kdm.xml");
117 }