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