From 5ab0c3bc04e4aa5acd883bb8126fc6b185c6c5d6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 22 Dec 2018 22:43:56 +0000 Subject: Incomplete encryption of private keys. --- test/crypto_test.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/wscript | 1 + 2 files changed, 45 insertions(+) create mode 100644 test/crypto_test.cc (limited to 'test') diff --git a/test/crypto_test.cc b/test/crypto_test.cc new file mode 100644 index 000000000..576a6ebc6 --- /dev/null +++ b/test/crypto_test.cc @@ -0,0 +1,44 @@ +/* + Copyright (C) 2018 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic 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. + + DCP-o-matic 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 DCP-o-matic. If not, see . + +*/ + +#include "lib/crypto.h" +#include "lib/exceptions.h" +#include "test.h" +#include +#include + +using std::string; +using std::list; +using boost::shared_array; + +BOOST_AUTO_TEST_CASE (crypto_test) +{ + shared_array key (new unsigned char[dcpomatic::crypto_key_length()]); + shared_array iv = dcpomatic::random_iv (); + + RAND_bytes (key.get(), dcpomatic::crypto_key_length()); + + dcp::Data ciphertext = dcpomatic::encrypt ("Can you see any fish?", key, iv); + BOOST_REQUIRE_EQUAL (dcpomatic::decrypt (ciphertext, key, iv), "Can you see any fish?"); + + key[5]++; + BOOST_REQUIRE_THROW (dcpomatic::decrypt (ciphertext, key, iv), CryptoError); +} + diff --git a/test/wscript b/test/wscript index 47f3dc275..23f31dadc 100644 --- a/test/wscript +++ b/test/wscript @@ -57,6 +57,7 @@ def build(bld): colour_conversion_test.cc config_test.cc content_test.cc + crypto_test.cc dcpomatic_time_test.cc dcp_playback_test.cc dcp_subtitle_test.cc -- cgit v1.2.3