summaryrefslogtreecommitdiff
path: root/src/decrypted_kdm.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-01-24 04:15:26 +0100
committerCarl Hetherington <cth@carlh.net>2021-01-24 04:15:26 +0100
commitceaf7bc52712cb60708ed5eb5c62c5e463dd8e89 (patch)
treec55e4b85ee30138ce83263045d77d01631378b2e /src/decrypted_kdm.cc
parent6c37cc1979b2a01205a888c4c98f3334685ee8dd (diff)
Tidying.
Diffstat (limited to 'src/decrypted_kdm.cc')
-rw-r--r--src/decrypted_kdm.cc33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc
index 0a3eeabd..174efb1b 100644
--- a/src/decrypted_kdm.cc
+++ b/src/decrypted_kdm.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -31,6 +31,12 @@
files in the program, then also delete it here.
*/
+
+/** @file src/decrypted_kdm.cc
+ * @brief DecryptedKDM class
+ */
+
+
#include "decrypted_kdm.h"
#include "decrypted_kdm_key.h"
#include "encrypted_kdm.h"
@@ -48,6 +54,7 @@
#include <openssl/pem.h>
#include <openssl/err.h>
+
using std::list;
using std::vector;
using std::string;
@@ -60,9 +67,11 @@ using std::shared_ptr;
using boost::optional;
using namespace dcp;
+
/* Magic value specified by SMPTE S430-1-2006 */
static uint8_t smpte_structure_id[] = { 0xf1, 0xdc, 0x12, 0x44, 0x60, 0x16, 0x9a, 0x0e, 0x85, 0xbc, 0x30, 0x06, 0x42, 0xf8, 0x66, 0xab };
+
static void
put (uint8_t ** d, string s)
{
@@ -70,6 +79,7 @@ put (uint8_t ** d, string s)
(*d) += s.length();
}
+
static void
put (uint8_t ** d, uint8_t const * s, int N)
{
@@ -77,6 +87,7 @@ put (uint8_t ** d, uint8_t const * s, int N)
(*d) += N;
}
+
void
DecryptedKDM::put_uuid (uint8_t ** d, string id)
{
@@ -96,6 +107,7 @@ DecryptedKDM::put_uuid (uint8_t ** d, string id)
*d += 16;
}
+
string
DecryptedKDM::get_uuid (unsigned char ** p)
{
@@ -114,6 +126,7 @@ DecryptedKDM::get_uuid (unsigned char ** p)
return buffer;
}
+
static string
get (uint8_t ** p, int N)
{
@@ -126,16 +139,17 @@ get (uint8_t ** p, int N)
return g;
}
+
DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
{
/* Read the private key */
- BIO* bio = BIO_new_mem_buf (const_cast<char *> (private_key.c_str ()), -1);
+ auto bio = BIO_new_mem_buf (const_cast<char *>(private_key.c_str()), -1);
if (!bio) {
throw MiscError ("could not create memory BIO");
}
- RSA* rsa = PEM_read_bio_RSAPrivateKey (bio, 0, 0, 0);
+ auto rsa = PEM_read_bio_RSAPrivateKey (bio, 0, 0, 0);
if (!rsa) {
throw FileError ("could not read RSA private key file", private_key, errno);
}
@@ -148,7 +162,7 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
int const cipher_value_len = base64_decode (i, cipher_value, sizeof (cipher_value));
/* Decrypt it */
- unsigned char * decrypted = new unsigned char[RSA_size(rsa)];
+ auto decrypted = new unsigned char[RSA_size(rsa)];
int const decrypted_len = RSA_private_decrypt (cipher_value_len, cipher_value, decrypted, rsa, RSA_PKCS1_OAEP_PADDING);
if (decrypted_len == -1) {
delete[] decrypted;
@@ -217,6 +231,7 @@ DecryptedKDM::DecryptedKDM (EncryptedKDM const & kdm, string private_key)
_issue_date = kdm.issue_date ();
}
+
DecryptedKDM::DecryptedKDM (
LocalTime not_valid_before,
LocalTime not_valid_after,
@@ -233,6 +248,7 @@ DecryptedKDM::DecryptedKDM (
}
+
DecryptedKDM::DecryptedKDM (
string cpl_id,
map<shared_ptr<const ReelMXF>, Key> keys,
@@ -253,6 +269,7 @@ DecryptedKDM::DecryptedKDM (
}
}
+
DecryptedKDM::DecryptedKDM (
shared_ptr<const CPL> cpl,
Key key,
@@ -282,23 +299,21 @@ DecryptedKDM::DecryptedKDM (
}
}
-/** @param type (MDIK, MDAK etc.)
- * @param key_id Key ID.
- * @param key The actual symmetric key.
- * @param cpl_id ID of CPL that the key is for.
- */
+
void
DecryptedKDM::add_key (optional<string> type, string key_id, Key key, string cpl_id, Standard standard)
{
_keys.push_back (DecryptedKDMKey (type, key_id, key, cpl_id, standard));
}
+
void
DecryptedKDM::add_key (DecryptedKDMKey key)
{
_keys.push_back (key);
}
+
EncryptedKDM
DecryptedKDM::encrypt (
shared_ptr<const CertificateChain> signer,