ECinema 'KDM' tweaks.
authorCarl Hetherington <cth@carlh.net>
Thu, 9 May 2019 15:32:54 +0000 (16:32 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 13 May 2019 10:07:46 +0000 (11:07 +0100)
src/lib/encrypted_ecinema_kdm.cc
src/lib/encrypted_ecinema_kdm.h
src/tools/dcpomatic_ecinema.cc

index 196caeec9dea0662238833940932f7673b6d77f4..e277eb997c46602b34e116f6d7ada4b544d21b55 100644 (file)
 #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
index f459409fe6e71a69a5436b294716ab052f0fdada..fc6fbdb655c9e08dab372edc666231f389fd4b9f 100644 (file)
@@ -33,6 +33,8 @@ class EncryptedECinemaKDM
 {
 public:
 
+       std::string as_xml () const;
+
 private:
        friend class DecryptedECinemaKDM;
 
index 76305d12de55d11ac066528bd6121ce36e2c1a53..bcd0907263311999869c0d9913c8fe69a42f2e57 100644 (file)
@@ -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";
 }