Check that we can decrypt a DKDM when it is loaded (#1011).
authorCarl Hetherington <cth@carlh.net>
Sat, 6 Jan 2018 23:27:45 +0000 (23:27 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 6 Jan 2018 23:27:45 +0000 (23:27 +0000)
ChangeLog
src/tools/dcpomatic_kdm.cc

index c0e5b3468344709902f8890274bed2d083fa9168..809cf70964ed1f4f15e1bebda05ef10daaf53af4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2018-01-06  Carl Hetherington  <cth@carlh.net>
 
 2018-01-06  Carl Hetherington  <cth@carlh.net>
 
+       * Check that we can decrypt a DKDM when it is loaded into
+       the KDM creator (#1011).
+
        * Fix crash in some cases when an incorrect KDM has been
        added to a DCP (#1000).
 
        * Fix crash in some cases when an incorrect KDM has been
        added to a DCP (#1000).
 
index 26e7f8479ec465f5d34011af2b0ab846d5106d14..9995d80a9819111056549285610c7740d44df378 100644 (file)
@@ -406,9 +406,20 @@ private:
                if (d->ShowModal() == wxID_OK) {
                        shared_ptr<DKDMBase> new_dkdm;
                        try {
                if (d->ShowModal() == wxID_OK) {
                        shared_ptr<DKDMBase> new_dkdm;
                        try {
-                               new_dkdm.reset (
-                                       new DKDM (dcp::EncryptedKDM (dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE)))
-                                       );
+                               dcp::EncryptedKDM ekdm(dcp::file_to_string (wx_to_std (d->GetPath ()), MAX_KDM_SIZE));
+
+                               /* Decrypt the DKDM to make sure that we can */
+                               shared_ptr<const dcp::CertificateChain> chain = Config::instance()->decryption_chain();
+                               DCPOMATIC_ASSERT (chain->key());
+                               dcp::DecryptedKDM dkdm(ekdm, chain->key().get());
+
+                               new_dkdm.reset(new DKDM(ekdm));
+                               shared_ptr<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ());
+                               if (!group) {
+                                       group = Config::instance()->dkdms ();
+                               }
+                               add_dkdm_model (new_dkdm, group);
+                               add_dkdm_view (new_dkdm);
                        } catch (dcp::KDMFormatError& e) {
                                error_dialog (
                                        this,
                        } catch (dcp::KDMFormatError& e) {
                                error_dialog (
                                        this,
@@ -418,14 +429,12 @@ private:
                                                )
                                        );
                                return;
                                                )
                                        );
                                return;
+                       } catch (dcp::KDMDecryptionError) {
+                               error_dialog (
+                                       this,
+                                       _("Could not decrypt the DKDM.  Perhaps it was not created with the correct certificate.")
+                                       );
                        }
                        }
-
-                       shared_ptr<DKDMGroup> group = dynamic_pointer_cast<DKDMGroup> (selected_dkdm ());
-                       if (!group) {
-                               group = Config::instance()->dkdms ();
-                       }
-                       add_dkdm_model (new_dkdm, group);
-                       add_dkdm_view (new_dkdm);
                }
                d->Destroy ();
        }
                }
                d->Destroy ();
        }