summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-07-07 19:35:42 +0100
committerCarl Hetherington <cth@carlh.net>2018-07-07 19:35:42 +0100
commit5c9e39df078aab9f03ae186d0758d4d710f90bab (patch)
tree24ba2ec0e0d1e0f55411efed26396ad93f6879a0 /src/lib
parent173fc4c4ca837cbea881efc361604b82806a1807 (diff)
Give better errors when incorrect KDMs are used (#1326).
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcp.cc25
-rw-r--r--src/lib/emailer.cc2
-rw-r--r--src/lib/exceptions.cc12
-rw-r--r--src/lib/exceptions.h16
-rw-r--r--src/lib/job.cc6
5 files changed, 54 insertions, 7 deletions
diff --git a/src/lib/dcp.cc b/src/lib/dcp.cc
index 7e6c66c6c..28e5c4fd2 100644
--- a/src/lib/dcp.cc
+++ b/src/lib/dcp.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -23,9 +23,13 @@
#include "dcp_content.h"
#include <dcp/dcp.h>
#include <dcp/decrypted_kdm.h>
+#include <dcp/exceptions.h>
#include <boost/foreach.hpp>
+#include "i18n.h"
+
using std::list;
+using std::string;
using boost::shared_ptr;
/** Find all the CPLs in our directories, cross-add assets and return the CPLs */
@@ -54,7 +58,24 @@ DCP::cpls () const
if (_dcp_content->kdm ()) {
BOOST_FOREACH (shared_ptr<dcp::DCP> i, dcps) {
- i->add (dcp::DecryptedKDM (_dcp_content->kdm().get(), Config::instance()->decryption_chain()->key().get ()));
+ try {
+ i->add (dcp::DecryptedKDM (_dcp_content->kdm().get(), Config::instance()->decryption_chain()->key().get ()));
+ } catch (dcp::KDMDecryptionError& e) {
+ /* Flesh out the error a bit */
+ string const kdm_subject_name = _dcp_content->kdm()->recipient_x509_subject_name();
+ bool on_chain = false;
+ shared_ptr<const dcp::CertificateChain> dc = Config::instance()->decryption_chain();
+ BOOST_FOREACH (dcp::Certificate i, dc->root_to_leaf()) {
+ if (i.subject() == kdm_subject_name) {
+ on_chain = true;
+ }
+ }
+ if (!on_chain) {
+ throw KDMError (_("KDM was not made for DCP-o-matic's decryption certificate."), e.what());
+ } else if (on_chain && kdm_subject_name != dc->leaf().subject()) {
+ throw KDMError (_("KDM was made for DCP-o-matic but not for its leaf certificate."), e.what());
+ }
+ }
}
}
diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc
index 7edad20b1..57b06ed61 100644
--- a/src/lib/emailer.cc
+++ b/src/lib/emailer.cc
@@ -219,7 +219,7 @@ Emailer::send (string server, int port, string user, string password)
CURLcode const r = curl_easy_perform (curl);
if (r != CURLE_OK) {
- throw KDMError (String::compose (_("Failed to send email (%1)"), curl_easy_strerror (r)));
+ throw KDMError (_("Failed to send email"), curl_easy_strerror (r));
}
curl_slist_free_all (recipients);
diff --git a/src/lib/exceptions.cc b/src/lib/exceptions.cc
index 43a8f3b86..481d2e89d 100644
--- a/src/lib/exceptions.cc
+++ b/src/lib/exceptions.cc
@@ -89,4 +89,14 @@ ProgrammingError::ProgrammingError (string file, int line, string message)
KDMAsContentError::KDMAsContentError ()
: runtime_error (_("This file is a KDM. KDMs should be added to DCP content by right-clicking the content and choosing \"Add KDM\"."))
-{}
+{
+
+}
+
+KDMError::KDMError (string s, string d)
+ : runtime_error (String::compose ("%1 (%2)", s, d))
+ , _summary (s)
+ , _detail (d)
+{
+
+}
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h
index 5efb045b7..7220af35f 100644
--- a/src/lib/exceptions.h
+++ b/src/lib/exceptions.h
@@ -192,9 +192,19 @@ public:
class KDMError : public std::runtime_error
{
public:
- explicit KDMError (std::string s)
- : std::runtime_error (s)
- {}
+ KDMError (std::string s, std::string d);
+
+ std::string summary () const {
+ return _summary;
+ }
+
+ std::string detail () const {
+ return _detail;
+ }
+
+private:
+ std::string _summary;
+ std::string _detail;
};
/** @class PixelFormatError
diff --git a/src/lib/job.cc b/src/lib/job.cc
index 65e2567cc..06416d1fe 100644
--- a/src/lib/job.cc
+++ b/src/lib/job.cc
@@ -180,6 +180,12 @@ Job::run_wrapper ()
set_progress (1);
set_state (FINISHED_ERROR);
+ } catch (KDMError& e) {
+
+ set_error (e.summary(), e.detail());
+ set_progress (1);
+ set_state (FINISHED_ERROR);
+
} catch (std::exception& e) {
set_error (