diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-03-19 21:46:01 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-03-19 21:46:01 +0000 |
| commit | 7702e5d643440e75369078863b34f8a574ee4143 (patch) | |
| tree | e01edc51718fd6c475b449748ff7fa6e5c526bc9 /test | |
| parent | c91aa27e13703874c944fed763b5b039ceae71d2 (diff) | |
Considerable re-work of KDM class to express the difference between encrypted and unencrypted KDMs.
Diffstat (limited to 'test')
| -rw-r--r-- | test/decryption_test.cc | 13 | ||||
| -rw-r--r-- | test/encryption_test.cc | 14 | ||||
| -rw-r--r-- | test/kdm_key_test.cc | 49 | ||||
| -rw-r--r-- | test/kdm_test.cc | 30 | ||||
| -rw-r--r-- | test/local_time_test.cc | 63 | ||||
| -rw-r--r-- | test/round_trip_test.cc | 24 | ||||
| -rw-r--r-- | test/utc_offset_to_string_test.cc | 32 | ||||
| -rw-r--r-- | test/wscript | 3 |
8 files changed, 106 insertions, 122 deletions
diff --git a/test/decryption_test.cc b/test/decryption_test.cc index 8dfeffa6..f80bb900 100644 --- a/test/decryption_test.cc +++ b/test/decryption_test.cc @@ -18,10 +18,11 @@ */ #include <boost/test/unit_test.hpp> -#include "kdm.h" #include "dcp.h" #include "mono_picture_frame.h" #include "cpl.h" +#include "decrypted_kdm.h" +#include "encrypted_kdm.h" #include "argb_frame.h" #include "mono_picture_mxf.h" #include "reel_picture_asset.h" @@ -58,11 +59,11 @@ BOOST_AUTO_TEST_CASE (decryption_test) encrypted.read (); BOOST_CHECK_EQUAL (encrypted.encrypted (), true); - dcp::KDM kdm ( - "test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml", + dcp::DecryptedKDM kdm ( + dcp::EncryptedKDM ("test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml"), "test/data/private.key" ); - + encrypted.add (kdm); shared_ptr<const dcp::ARGBFrame> plaintext_frame = get_frame (plaintext); @@ -78,8 +79,8 @@ BOOST_AUTO_TEST_CASE (decryption_test) /** Load in a KDM that didn't work at first */ BOOST_AUTO_TEST_CASE (failing_kdm_test) { - dcp::KDM kdm ( - "test/data/target.pem.crt.de5d4eba-e683-41ca-bdda-aa4ad96af3f4.kdm.xml", + dcp::DecryptedKDM kdm ( + dcp::EncryptedKDM ("test/data/target.pem.crt.de5d4eba-e683-41ca-bdda-aa4ad96af3f4.kdm.xml"), "test/data/private.key" ); } diff --git a/test/encryption_test.cc b/test/encryption_test.cc index 8fe34ddd..a4bc0600 100644 --- a/test/encryption_test.cc +++ b/test/encryption_test.cc @@ -17,7 +17,6 @@ */ -#include "kdm.h" #include "KM_util.h" #include "metadata.h" #include "certificates.h" @@ -35,6 +34,8 @@ #include "subtitle_content.h" #include "reel_mono_picture_asset.h" #include "reel_sound_asset.h" +#include "encrypted_kdm.h" +#include "decrypted_kdm.h" #include <sndfile.h> #include <boost/test/unit_test.hpp> #include <boost/shared_ptr.hpp> @@ -123,17 +124,16 @@ BOOST_AUTO_TEST_CASE (encryption_test) d.add (cpl); d.write_xml (dcp::SMPTE, xml_metadata, signer); - dcp::KDM kdm ( + dcp::DecryptedKDM kdm ( cpl, - signer, - signer->certificates().leaf(), - boost::posix_time::time_from_string ("2013-01-01 00:00:00"), - boost::posix_time::time_from_string ("2017-01-08 00:00:00"), + dcp::LocalTime ("2013-01-01T00:00:00+00:00"), + dcp::LocalTime ("2017-01-08T00:00:00+00:00"), "libdcp", + "test", "2012-07-17T04:45:18+00:00" ); - kdm.as_xml ("build/test/bar.kdm.xml"); + kdm.encrypt(signer, signer->certificates().leaf()).as_xml ("build/test/bar.kdm.xml"); int r = system ( "xmllint --path schema --nonet --noout --schema schema/SMPTE-430-1-2006-Amd-1-2009-KDM.xsd build/test/bar.kdm.xml " diff --git a/test/kdm_key_test.cc b/test/kdm_key_test.cc deleted file mode 100644 index 4a84fe3b..00000000 --- a/test/kdm_key_test.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include <boost/test/unit_test.hpp> -#include "kdm.h" - -BOOST_AUTO_TEST_CASE (kdm_key_test) -{ - uint8_t foo[138]; - memset (foo, 0, 138); - dcp::KDMKey kkey (foo, 138); - - uint8_t* raw = new uint8_t[16]; - uint8_t* p = raw; - kkey.put_uuid (&p, "5d51e8a1-b2a5-4da6-9b66-4615c3609440"); - BOOST_CHECK_EQUAL (raw[0], 0x5d); - BOOST_CHECK_EQUAL (raw[1], 0x51); - BOOST_CHECK_EQUAL (raw[2], 0xe8); - BOOST_CHECK_EQUAL (raw[3], 0xa1); - BOOST_CHECK_EQUAL (raw[4], 0xb2); - BOOST_CHECK_EQUAL (raw[5], 0xa5); - BOOST_CHECK_EQUAL (raw[6], 0x4d); - BOOST_CHECK_EQUAL (raw[7], 0xa6); - BOOST_CHECK_EQUAL (raw[8], 0x9b); - BOOST_CHECK_EQUAL (raw[9], 0x66); - BOOST_CHECK_EQUAL (raw[10], 0x46); - BOOST_CHECK_EQUAL (raw[11], 0x15); - BOOST_CHECK_EQUAL (raw[12], 0xc3); - BOOST_CHECK_EQUAL (raw[13], 0x60); - BOOST_CHECK_EQUAL (raw[14], 0x94); - BOOST_CHECK_EQUAL (raw[15], 0x40); - delete[] raw; -} diff --git a/test/kdm_test.cc b/test/kdm_test.cc index 5fff4fde..7de62f5a 100644 --- a/test/kdm_test.cc +++ b/test/kdm_test.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,44 +18,46 @@ */ #include <boost/test/unit_test.hpp> -#include "kdm.h" +#include <libxml++/libxml++.h> +#include "encrypted_kdm.h" +#include "decrypted_kdm.h" using std::list; +using std::stringstream; using boost::shared_ptr; BOOST_AUTO_TEST_CASE (kdm_test) { - dcp::KDM kdm ( - "test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml", + dcp::DecryptedKDM kdm ( + dcp::EncryptedKDM ("test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml"), "test/data/private.key" ); - list<dcp::KDMKey> keys = kdm.keys (); + list<dcp::DecryptedKDMKey> keys = kdm.keys (); BOOST_CHECK_EQUAL (keys.size(), 2); BOOST_CHECK_EQUAL (keys.front().cpl_id(), "eece17de-77e8-4a55-9347-b6bab5724b9f"); - BOOST_CHECK_EQUAL (keys.front().key_id(), "4ac4f922-8239-4831-b23b-31426d0542c4"); - BOOST_CHECK_EQUAL (keys.front().not_valid_before(), "2013-07-06T20:04:58+00:00"); - BOOST_CHECK_EQUAL (keys.front().not_valid_after(), "2023-07-02T20:04:56+00:00"); + BOOST_CHECK_EQUAL (keys.front().id(), "4ac4f922-8239-4831-b23b-31426d0542c4"); BOOST_CHECK_EQUAL (keys.front().key().hex(), "8a2729c3e5b65c45d78305462104c3fb"); BOOST_CHECK_EQUAL (keys.back().cpl_id(), "eece17de-77e8-4a55-9347-b6bab5724b9f"); - BOOST_CHECK_EQUAL (keys.back().key_id(), "73baf5de-e195-4542-ab28-8a465f7d4079"); - BOOST_CHECK_EQUAL (keys.back().not_valid_before(), "2013-07-06T20:04:58+00:00"); - BOOST_CHECK_EQUAL (keys.back().not_valid_after(), "2023-07-02T20:04:56+00:00"); + BOOST_CHECK_EQUAL (keys.back().id(), "73baf5de-e195-4542-ab28-8a465f7d4079"); BOOST_CHECK_EQUAL (keys.back().key().hex(), "5327fb7ec2e807bd57059615bf8a169d"); } /* Check that we can read in a KDM and then write it back out again the same */ BOOST_AUTO_TEST_CASE (kdm_passthrough_test) { - dcp::xml::DCinemaSecurityMessage kdm ( + dcp::EncryptedKDM kdm ( "test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml" ); - shared_ptr<xmlpp::Document> doc = kdm.as_xml (); - doc->write_to_file_formatted ("build/kdm.xml", "UTF-8"); + shared_ptr<xmlpp::DomParser> parser (new xmlpp::DomParser ()); + stringstream s; + s << kdm.as_xml (); + parser->parse_stream (s); + parser->get_document()->write_to_file_formatted ("build/kdm.xml", "UTF-8"); int const r = system ( "xmldiff -c test/data/kdm_TONEPLATES-SMPTE-ENC_.smpte-430-2.ROOT.NOT_FOR_PRODUCTION_20130706_20230702_CAR_OV_t1_8971c838.xml build/kdm.xml" ); diff --git a/test/local_time_test.cc b/test/local_time_test.cc new file mode 100644 index 00000000..b7f49a32 --- /dev/null +++ b/test/local_time_test.cc @@ -0,0 +1,63 @@ +/* + Copyright (C) 2014 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <boost/test/unit_test.hpp> +#include "local_time.h" +#include "exceptions.h" + +/** Check that dcp::LocalTime works */ +BOOST_AUTO_TEST_CASE (local_time_test) +{ + /* Badly-formatted times */ + BOOST_CHECK_THROW (dcp::LocalTime (""), dcp::TimeFormatError); + BOOST_CHECK_THROW (dcp::LocalTime ("XXX"), dcp::TimeFormatError); + BOOST_CHECK_THROW (dcp::LocalTime ("2013-01-05T18:06:59+04:0"), dcp::TimeFormatError); + BOOST_CHECK_THROW (dcp::LocalTime ("2013-01-05T18:06:59X04:00"), dcp::TimeFormatError); + BOOST_CHECK_THROW (dcp::LocalTime ("2013-01-05T18-06:59+04:00"), dcp::TimeFormatError); + BOOST_CHECK_THROW (dcp::LocalTime ("2013!01-05T18:06:59+04:00"), dcp::TimeFormatError); + + /* Correctly-formatted */ + + { + dcp::LocalTime t ("2013-01-05T18:06:59+04:00"); + BOOST_CHECK_EQUAL (t._year, 2013); + BOOST_CHECK_EQUAL (t._month, 1); + BOOST_CHECK_EQUAL (t._day, 5); + BOOST_CHECK_EQUAL (t._hour, 18); + BOOST_CHECK_EQUAL (t._minute, 6); + BOOST_CHECK_EQUAL (t._second, 59); + BOOST_CHECK_EQUAL (t._tz_hour, 4); + BOOST_CHECK_EQUAL (t._tz_minute, 0); + BOOST_CHECK_EQUAL (t.as_string(), "2013-01-05T18:06:59+04:00"); + } + + { + dcp::LocalTime t ("2011-11-20T01:06:59-09:30"); + BOOST_CHECK_EQUAL (t._year, 2011); + BOOST_CHECK_EQUAL (t._month, 11); + BOOST_CHECK_EQUAL (t._day, 20); + BOOST_CHECK_EQUAL (t._hour, 1); + BOOST_CHECK_EQUAL (t._minute, 6); + BOOST_CHECK_EQUAL (t._second, 59); + BOOST_CHECK_EQUAL (t._tz_hour, -9); + BOOST_CHECK_EQUAL (t._tz_minute, 30); + BOOST_CHECK_EQUAL (t.as_string(), "2011-11-20T01:06:59-09:30"); + } +} + diff --git a/test/round_trip_test.cc b/test/round_trip_test.cc index e94d8c72..ef1f1f41 100644 --- a/test/round_trip_test.cc +++ b/test/round_trip_test.cc @@ -18,7 +18,8 @@ */ #include "certificates.h" -#include "kdm.h" +#include "decrypted_kdm.h" +#include "encrypted_kdm.h" #include "signer.h" #include "mono_picture_mxf.h" #include "sound_mxf.h" @@ -78,29 +79,28 @@ BOOST_AUTO_TEST_CASE (round_trip_test) cpl->add (reel); /* A KDM using our certificate chain's leaf key pair */ - dcp::KDM kdm_A ( + dcp::DecryptedKDM kdm_A ( cpl, - signer, - signer->certificates().leaf(), - boost::posix_time::time_from_string ("2013-01-01 00:00:00"), - boost::posix_time::time_from_string ("2013-01-08 00:00:00"), + dcp::LocalTime ("2013-01-01T00:00:00+00:00"), + dcp::LocalTime ("2013-01-08T00:00:00+00:00"), "libdcp", + "test", "2012-07-17T04:45:18+00:00" ); boost::filesystem::path const kdm_file = work_dir / "kdm.xml"; - kdm_A.as_xml (kdm_file); + kdm_A.encrypt(signer, signer->certificates().leaf()).as_xml (kdm_file); /* Reload the KDM, using our private key to decrypt it */ - dcp::KDM kdm_B (kdm_file, "build/test/signer/leaf.key"); + dcp::DecryptedKDM kdm_B (dcp::EncryptedKDM (kdm_file), "build/test/signer/leaf.key"); /* Check that the decrypted KDMKeys are the same as the ones we started with */ BOOST_CHECK_EQUAL (kdm_A.keys().size(), kdm_B.keys().size()); - list<dcp::KDMKey> keys_A = kdm_A.keys (); - list<dcp::KDMKey> keys_B = kdm_B.keys (); - list<dcp::KDMKey>::const_iterator i = keys_A.begin(); - list<dcp::KDMKey>::const_iterator j = keys_B.begin(); + list<dcp::DecryptedKDMKey> keys_A = kdm_A.keys (); + list<dcp::DecryptedKDMKey> keys_B = kdm_B.keys (); + list<dcp::DecryptedKDMKey>::const_iterator i = keys_A.begin(); + list<dcp::DecryptedKDMKey>::const_iterator j = keys_B.begin(); while (i != keys_A.end ()) { BOOST_CHECK (*i == *j); ++i; diff --git a/test/utc_offset_to_string_test.cc b/test/utc_offset_to_string_test.cc deleted file mode 100644 index 3b4e0b46..00000000 --- a/test/utc_offset_to_string_test.cc +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (C) 2013 Carl Hetherington <cth@carlh.net> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include <boost/test/unit_test.hpp> -#include "metadata.h" -#include "util.h" - -/** Test dcp::utc_offset_to_string */ -BOOST_AUTO_TEST_CASE (utc_offset_to_string_test) -{ - BOOST_CHECK_EQUAL (dcp::utc_offset_to_string (30), "+00:30"); - BOOST_CHECK_EQUAL (dcp::utc_offset_to_string (60), "+01:00"); - BOOST_CHECK_EQUAL (dcp::utc_offset_to_string (61), "+01:01"); - BOOST_CHECK_EQUAL (dcp::utc_offset_to_string (7 * 60), "+07:00"); - BOOST_CHECK_EQUAL (dcp::utc_offset_to_string (-11 * 60), "-11:00"); -} diff --git a/test/wscript b/test/wscript index 407765af..7e7122b1 100644 --- a/test/wscript +++ b/test/wscript @@ -29,14 +29,13 @@ def build(bld): decryption_test.cc encryption_test.cc frame_info_test.cc - kdm_key_test.cc + local_time_test.cc kdm_test.cc read_dcp_test.cc recovery_test.cc round_trip_test.cc subtitle_tests.cc test.cc - utc_offset_to_string_test.cc util_test.cc """ obj.target = 'tests' |
