X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Futil.cc;h=4b780e1b7f9471176a54274c7ad983914027818f;hb=a710d799bd2bb2c5a05668180b4781a9dc847188;hp=667ee8ce95926f8c10bf24db3c71d2a41fa77b76;hpb=089b90439e745a218494e76b45e7df6215af01df;p=dcpomatic.git diff --git a/src/lib/util.cc b/src/lib/util.cc index 667ee8ce9..4b780e1b7 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -46,6 +46,8 @@ #include #include #include +#include +#include extern "C" { #include #include @@ -63,6 +65,7 @@ extern "C" { #include "config.h" #include "ratio.h" #include "job.h" +#include "cross.h" #ifdef DCPOMATIC_WINDOWS #include "stack.hpp" #endif @@ -807,7 +810,7 @@ tidy_for_filename (string f) { string t; for (size_t i = 0; i < f.length(); ++i) { - if (isalpha (f[i]) || f[i] == '_' || f[i] == '-') { + if (isalnum (f[i]) || f[i] == '_' || f[i] == '-') { t += f[i]; } else { t += '_'; @@ -816,4 +819,57 @@ tidy_for_filename (string f) return t; } + +shared_ptr +make_signer () +{ + boost::filesystem::path const sd = Config::instance()->signer_chain_directory (); + + /* Remake the chain if any of it is missing */ + list files; + files.push_back ("ca.self-signed.pem"); + files.push_back ("intermediate.signed.pem"); + files.push_back ("leaf.signed.pem"); + files.push_back ("leaf.key"); + + list::const_iterator i = files.begin(); + while (i != files.end()) { + boost::filesystem::path p (sd); + p /= *i; + if (!boost::filesystem::exists (p)) { + boost::filesystem::remove_all (sd); + boost::filesystem::create_directories (sd); + libdcp::make_signer_chain (sd, openssl_path ()); + break; + } + + ++i; + } + + libdcp::CertificateChain chain; + + { + boost::filesystem::path p (sd); + p /= "ca.self-signed.pem"; + chain.add (shared_ptr (new libdcp::Certificate (p))); + } + + { + boost::filesystem::path p (sd); + p /= "intermediate.signed.pem"; + chain.add (shared_ptr (new libdcp::Certificate (p))); + } + + { + boost::filesystem::path p (sd); + p /= "leaf.signed.pem"; + chain.add (shared_ptr (new libdcp::Certificate (p))); + } + + boost::filesystem::path signer_key (sd); + signer_key /= "leaf.key"; + + return shared_ptr (new libdcp::Signer (chain, signer_key)); +} +