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