X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fconfig.cc;h=9dd6f638e7c6e16ba29545f942dc1388ed887378;hb=refs%2Ftags%2Fv2.13.95;hp=b64690aadf4df86569b3e6a047d223038c1fbbfb;hpb=35992b8f2c9d58a08d1ecb08a39d7c99362fd2c0;p=dcpomatic.git diff --git a/src/lib/config.cc b/src/lib/config.cc index b64690aad..9dd6f638e 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -32,6 +32,7 @@ #include "film.h" #include "dkdm_wrapper.h" #include "compose.hpp" +#include "crypto.h" #include #include #include @@ -61,6 +62,7 @@ using boost::shared_ptr; using boost::optional; using boost::dynamic_pointer_cast; using boost::algorithm::trim; +using boost::shared_array; using dcp::raw_convert; Config* Config::_instance = 0; @@ -176,7 +178,7 @@ Config::set_defaults () _player_watermark_theatre = ""; _player_watermark_period = 1; _player_watermark_duration = 50; - _allow_spl_editing = true; + _player_lock_file = boost::none; #endif _allowed_dcp_frame_rates.clear (); @@ -435,7 +437,19 @@ try BOOST_FOREACH (cxml::NodePtr i, decryption->node_children ("Certificate")) { c->add (dcp::Certificate (i->content ())); } - c->set_key (decryption->string_child ("PrivateKey")); + optional key = decryption->optional_string_child ("PrivateKey"); +#ifdef DCPOMATIC_VARIANT_SWAROOP + if (key) { + c->set_key (*key); + } else { + dcp::Data encrypted_key (path("private")); + dcp::Data iv (path("iv")); + c->set_key (dcpomatic::decrypt (encrypted_key, key_from_uuid(), iv)); + } +#else + DCPOMATIC_ASSERT (key); + c->set_key (*key); +#endif _decryption_chain = c; } else { _decryption_chain = create_certificate_chain (); @@ -528,7 +542,7 @@ try BOOST_FOREACH (cxml::ConstNodePtr i, f.node_children("RequiredMonitor")) { _required_monitors.push_back(Monitor(i)); } - _allow_spl_editing = f.optional_bool_child("AllowSPLEditing").get_value_or(true); + _player_lock_file = f.optional_string_child("PlayerLockFile"); #endif /* Replace any cinemas from config.xml with those from the configured file */ @@ -599,6 +613,19 @@ Config::write () const write_cinemas (); } +#ifdef DCPOMATIC_VARIANT_SWAROOP +/* Make up a key from the machine UUID */ +dcp::Data +Config::key_from_uuid () const +{ + dcp::Data key (dcpomatic::crypto_key_length()); + memset (key.data().get(), 0, key.size()); + string const magic = command_and_read ("dcpomatic2_uuid"); + strncpy ((char *) key.data().get(), magic.c_str(), dcpomatic::crypto_key_length()); + return key; +} +#endif + void Config::write_config () const { @@ -656,8 +683,8 @@ Config::write_config () const } if (_default_container) { /* [XML:opt] DefaultContainer ID of default container - * to use when creating new films (185,239 or - * 190). + to use when creating new films (185,239 or + 190). */ root->add_child("DefaultContainer")->add_child_text (_default_container->id ()); } @@ -779,7 +806,14 @@ Config::write_config () const BOOST_FOREACH (dcp::Certificate const & i, _decryption_chain->unordered()) { decryption->add_child("Certificate")->add_child_text (i.certificate (true)); } +#ifdef DCPOMATIC_VARIANT_SWAROOP + dcp::Data iv = dcpomatic::random_iv (); + dcp::Data encrypted_key = dcpomatic::encrypt (_decryption_chain->key().get(), key_from_uuid(), iv); + encrypted_key.write (path("private")); + iv.write (path("iv")); +#else decryption->add_child("PrivateKey")->add_child_text (_decryption_chain->key().get ()); +#endif /* [XML] History Filename of DCP to present in the File menu of the GUI; there can be more than one of these tags. @@ -941,15 +975,26 @@ Config::write_config () const BOOST_FOREACH (Monitor i, _required_monitors) { i.as_xml(root->add_child("RequiredMonitor")); } - root->add_child("AllowSPLEditing")->add_child_text(_allow_spl_editing ? "1" : "0"); + if (_player_lock_file) { + root->add_child("PlayerLockFile")->add_child_text(_player_lock_file->string()); + } #endif try { - doc.write_to_file_formatted(config_file().string()); + string const s = doc.write_to_string_formatted (); + boost::filesystem::path tmp (string(config_file().string()).append(".tmp")); + FILE* f = fopen_boost (tmp, "w"); + if (!f) { + throw FileError (_("Could not open file for writing"), tmp); + } + checked_fwrite (s.c_str(), s.length(), f, tmp); + fclose (f); + boost::filesystem::remove (config_file()); + boost::filesystem::rename (tmp, config_file()); } catch (xmlpp::exception& e) { string s = e.what (); trim (s); - throw FileError (s, path("config.xml")); + throw FileError (s, config_file()); } } @@ -965,7 +1010,9 @@ Config::write_cinemas () const } try { - doc.write_to_file_formatted (_cinemas_file.string ()); + doc.write_to_file_formatted (_cinemas_file.string() + ".tmp"); + boost::filesystem::remove (_cinemas_file); + boost::filesystem::rename (_cinemas_file.string() + ".tmp", _cinemas_file); } catch (xmlpp::exception& e) { string s = e.what (); trim (s); @@ -1190,10 +1237,16 @@ Config::config_file () } /* See if there's a link */ - f.read_file (main); - optional link = f.optional_string_child("Link"); - if (link) { - return *link; + try { + f.read_file (main); + optional link = f.optional_string_child("Link"); + if (link) { + return *link; + } + } catch (xmlpp::exception& e) { + /* There as a problem reading the main configuration file, + so there can't be a link. + */ } return main;