diff options
| author | Carl Hetherington <cth@carlh.net> | 2019-05-09 16:32:54 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2019-05-13 11:07:46 +0100 |
| commit | cb0a41355327f0308e5b56c21bff1d1ac004a9cb (patch) | |
| tree | 6b9a62ebf3f5074ebf18b1af8f0c42d7a1ac8978 | |
| parent | 19a4388397813392d11dce07e4453c9b798b8bdb (diff) | |
ECinema 'KDM' tweaks.
| -rw-r--r-- | src/lib/encrypted_ecinema_kdm.cc | 29 | ||||
| -rw-r--r-- | src/lib/encrypted_ecinema_kdm.h | 2 | ||||
| -rw-r--r-- | src/tools/dcpomatic_ecinema.cc | 4 |
3 files changed, 32 insertions, 3 deletions
diff --git a/src/lib/encrypted_ecinema_kdm.cc b/src/lib/encrypted_ecinema_kdm.cc index 196caeec9..e277eb997 100644 --- a/src/lib/encrypted_ecinema_kdm.cc +++ b/src/lib/encrypted_ecinema_kdm.cc @@ -23,18 +23,43 @@ #include "encrypted_ecinema_kdm.h" #include <dcp/key.h> #include <dcp/certificate.h> +#include <libxml++/libxml++.h> #include <openssl/rsa.h> #include <iostream> using std::cout; +using std::string; using boost::shared_ptr; using dcp::Certificate; EncryptedECinemaKDM::EncryptedECinemaKDM (dcp::Key content_key, Certificate recipient) { RSA* rsa = recipient.public_key (); - dcp::Data encrypted (RSA_size(rsa)); - int const N = RSA_public_encrypt (content_key.length(), content_key.value(), encrypted.data().get(), rsa, RSA_PKCS1_OAEP_PADDING); + _content_key = dcp::Data (RSA_size(rsa)); + int const N = RSA_public_encrypt (content_key.length(), content_key.value(), _content_key.data().get(), rsa, RSA_PKCS1_OAEP_PADDING); +} + +string +EncryptedECinemaKDM::as_xml () const +{ + string key; + + /* Lazy overallocation */ + char out[_content_key.size() * 2]; + Kumu::base64encode (_content_key.data().get(), _content_key.size(), out, _content_key.size() * 2); + int const N = strlen (out); + string lines; + for (int i = 0; i < N; ++i) { + if (i > 0 && (i % 64) == 0) { + lines += "\n"; + } + lines += out[i]; + } + + xmlpp::Document document; + xmlpp::Element* root = document.create_root_node ("ECinemaSecurityMesage"); + root->add_child("Key")->add_child_text(lines); + return document.write_to_string ("UTF-8"); } #endif diff --git a/src/lib/encrypted_ecinema_kdm.h b/src/lib/encrypted_ecinema_kdm.h index f459409fe..fc6fbdb65 100644 --- a/src/lib/encrypted_ecinema_kdm.h +++ b/src/lib/encrypted_ecinema_kdm.h @@ -33,6 +33,8 @@ class EncryptedECinemaKDM { public: + std::string as_xml () const; + private: friend class DecryptedECinemaKDM; diff --git a/src/tools/dcpomatic_ecinema.cc b/src/tools/dcpomatic_ecinema.cc index 76305d12d..bcd090726 100644 --- a/src/tools/dcpomatic_ecinema.cc +++ b/src/tools/dcpomatic_ecinema.cc @@ -180,5 +180,7 @@ main (int argc, char* argv[]) avformat_free_context (input_fc); avformat_free_context (output_fc); - DecryptedECinemaKDM kdm (key); + DecryptedECinemaKDM decrypted_kdm (key); + EncryptedECinemaKDM encrypted_kdm = decrypted_kdm.encrypt (Config::instance()->decryption_chain()); + cout << encrypted_kdm.as_xml() << "\n"; } |
