summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-07-21 15:42:48 +0100
committerCarl Hetherington <cth@carlh.net>2014-07-21 15:42:48 +0100
commit55c649e790b73e3f8d493cd12c346e3bddcba25d (patch)
tree4f50d87782a4ec58219e5a2ef468075b5e4d36f7 /src
parent19356a292ba53b6d40270b1e74af5dad2304dbd5 (diff)
Remove some shared_ptr-itis.
Diffstat (limited to 'src')
-rw-r--r--src/certificates.cc33
-rw-r--r--src/certificates.h15
-rw-r--r--src/decrypted_kdm.cc8
-rw-r--r--src/decrypted_kdm.h4
-rw-r--r--src/encrypted_kdm.cc18
-rw-r--r--src/encrypted_kdm.h2
-rw-r--r--src/signer.cc20
7 files changed, 61 insertions, 39 deletions
diff --git a/src/certificates.cc b/src/certificates.cc
index 085cea80..601662ea 100644
--- a/src/certificates.cc
+++ b/src/certificates.cc
@@ -38,7 +38,7 @@
using std::list;
using std::string;
using std::cout;
-using boost::shared_ptr;
+using std::ostream;
using namespace dcp;
/** @param c X509 certificate, which this object will take ownership of */
@@ -276,8 +276,27 @@ Certificate::public_key () const
return _public_key;
}
+bool
+dcp::operator== (Certificate const & a, Certificate const & b)
+{
+ return a.certificate() == b.certificate();
+}
+
+bool
+dcp::operator< (Certificate const & a, Certificate const & b)
+{
+ return a.certificate() < b.certificate();
+}
+
+ostream&
+dcp::operator<< (ostream& s, Certificate const & c)
+{
+ s << c.certificate();
+ return s;
+}
+
/** @return Root certificate */
-shared_ptr<const Certificate>
+Certificate
CertificateChain::root () const
{
assert (!_certificates.empty());
@@ -285,7 +304,7 @@ CertificateChain::root () const
}
/** @return Leaf certificate */
-shared_ptr<const Certificate>
+Certificate
CertificateChain::leaf () const
{
assert (_certificates.size() >= 2);
@@ -312,7 +331,7 @@ CertificateChain::leaf_to_root () const
* @param c Certificate to add.
*/
void
-CertificateChain::add (shared_ptr<const Certificate> c)
+CertificateChain::add (Certificate c)
{
_certificates.push_back (c);
}
@@ -321,7 +340,7 @@ CertificateChain::add (shared_ptr<const Certificate> c)
* @param c Certificate to remove.
*/
void
-CertificateChain::remove (shared_ptr<const Certificate> c)
+CertificateChain::remove (Certificate c)
{
_certificates.remove (c);
}
@@ -363,7 +382,7 @@ CertificateChain::valid () const
break;
}
- if (!X509_STORE_add_cert (store, (*i)->x509 ())) {
+ if (!X509_STORE_add_cert (store, i->x509 ())) {
X509_STORE_free (store);
return false;
}
@@ -375,7 +394,7 @@ CertificateChain::valid () const
}
X509_STORE_set_flags (store, 0);
- if (!X509_STORE_CTX_init (ctx, store, (*j)->x509 (), 0)) {
+ if (!X509_STORE_CTX_init (ctx, store, j->x509 (), 0)) {
X509_STORE_CTX_free (ctx);
X509_STORE_free (store);
return false;
diff --git a/src/certificates.h b/src/certificates.h
index 841d8b7b..ebc4cc53 100644
--- a/src/certificates.h
+++ b/src/certificates.h
@@ -26,7 +26,6 @@
#undef X509_NAME
#include <openssl/x509.h>
-#include <boost/shared_ptr.hpp>
#include <boost/filesystem.hpp>
#include <string>
#include <list>
@@ -84,6 +83,10 @@ private:
mutable RSA* _public_key;
};
+bool operator== (Certificate const & a, Certificate const & b);
+bool operator< (Certificate const & a, Certificate const & b);
+std::ostream& operator<< (std::ostream&s, Certificate const & c);
+
/** @class CertificateChain
* @brief A chain of any number of certificates, from root to leaf.
*/
@@ -92,14 +95,14 @@ class CertificateChain
public:
CertificateChain () {}
- void add (boost::shared_ptr<const Certificate> c);
- void remove (boost::shared_ptr<const Certificate> c);
+ void add (Certificate c);
+ void remove (Certificate c);
void remove (int);
- boost::shared_ptr<const Certificate> root () const;
- boost::shared_ptr<const Certificate> leaf () const;
+ Certificate root () const;
+ Certificate leaf () const;
- typedef std::list<boost::shared_ptr<const Certificate> > List;
+ typedef std::list<Certificate> List;
List leaf_to_root () const;
List root_to_leaf () const;
diff --git a/src/decrypted_kdm.cc b/src/decrypted_kdm.cc
index 62162346..02515fe8 100644
--- a/src/decrypted_kdm.cc
+++ b/src/decrypted_kdm.cc
@@ -213,7 +213,7 @@ DecryptedKDM::DecryptedKDM (
}
EncryptedKDM
-DecryptedKDM::encrypt (shared_ptr<const Signer> signer, shared_ptr<const Certificate> recipient, Formulation formulation) const
+DecryptedKDM::encrypt (shared_ptr<const Signer> signer, Certificate recipient, Formulation formulation) const
{
list<pair<string, string> > key_ids;
list<string> keys;
@@ -229,7 +229,7 @@ DecryptedKDM::encrypt (shared_ptr<const Signer> signer, shared_ptr<const Certifi
uint8_t structure_id[] = { 0xf1, 0xdc, 0x12, 0x44, 0x60, 0x16, 0x9a, 0x0e, 0x85, 0xbc, 0x30, 0x06, 0x42, 0xf8, 0x66, 0xab };
put (&p, structure_id, 16);
- base64_decode (signer->certificates().leaf()->thumbprint (), p, 20);
+ base64_decode (signer->certificates().leaf().thumbprint (), p, 20);
p += 20;
put_uuid (&p, i->cpl_id ());
@@ -240,7 +240,7 @@ DecryptedKDM::encrypt (shared_ptr<const Signer> signer, shared_ptr<const Certifi
put (&p, i->key().value(), ASDCP::KeyLen);
/* Encrypt using the projector's public key */
- RSA* rsa = recipient->public_key ();
+ RSA* rsa = recipient.public_key ();
unsigned char encrypted[RSA_size(rsa)];
int const encrypted_len = RSA_public_encrypt (p - block, block, encrypted, rsa, RSA_PKCS1_OAEP_PADDING);
if (encrypted_len == -1) {
@@ -262,7 +262,7 @@ DecryptedKDM::encrypt (shared_ptr<const Signer> signer, shared_ptr<const Certifi
keys.push_back (lines.str ());
}
- string device_list_description = recipient->common_name ();
+ string device_list_description = recipient.common_name ();
if (device_list_description.find (".") != string::npos) {
device_list_description = device_list_description.substr (device_list_description.find (".") + 1);
}
diff --git a/src/decrypted_kdm.h b/src/decrypted_kdm.h
index 88cbc1e6..91b2f7d3 100644
--- a/src/decrypted_kdm.h
+++ b/src/decrypted_kdm.h
@@ -28,6 +28,7 @@
#include "local_time.h"
#include "decrypted_kdm_key.h"
#include "types.h"
+#include "certificates.h"
#include <boost/filesystem.hpp>
namespace dcp {
@@ -35,7 +36,6 @@ namespace dcp {
class DecryptedKDMKey;
class EncryptedKDM;
class Signer;
-class Certificate;
class CPL;
/** @class DecryptedKDM
@@ -77,7 +77,7 @@ public:
* @param formulation Formulation to use for the encrypted KDM.
* @return Encrypted KDM.
*/
- EncryptedKDM encrypt (boost::shared_ptr<const Signer> signer, boost::shared_ptr<const Certificate> recipient, Formulation formulation) const;
+ EncryptedKDM encrypt (boost::shared_ptr<const Signer> signer, Certificate recipient, Formulation formulation) const;
/** @return This KDM's (decrypted) keys, which could be used to decrypt MXFs. */
std::list<DecryptedKDMKey> keys () const {
diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc
index 93852fb6..7cae0533 100644
--- a/src/encrypted_kdm.cc
+++ b/src/encrypted_kdm.cc
@@ -493,7 +493,7 @@ EncryptedKDM::EncryptedKDM (string s)
EncryptedKDM::EncryptedKDM (
shared_ptr<const Signer> signer,
- shared_ptr<const Certificate> recipient,
+ Certificate recipient,
string device_list_description,
string cpl_id,
string content_title_text,
@@ -508,23 +508,23 @@ EncryptedKDM::EncryptedKDM (
/* Fill our XML-ish description in with the juicy bits that the caller has given */
data::AuthenticatedPublic& aup = _data->authenticated_public;
- aup.signer.x509_issuer_name = signer->certificates().leaf()->issuer ();
- aup.signer.x509_serial_number = signer->certificates().leaf()->serial ();
+ aup.signer.x509_issuer_name = signer->certificates().leaf().issuer ();
+ aup.signer.x509_serial_number = signer->certificates().leaf().serial ();
data::KDMRequiredExtensions& kre = _data->authenticated_public.required_extensions.kdm_required_extensions;
- kre.recipient.x509_issuer_serial.x509_issuer_name = recipient->issuer ();
- kre.recipient.x509_issuer_serial.x509_serial_number = recipient->serial ();
- kre.recipient.x509_subject_name = recipient->subject ();
+ kre.recipient.x509_issuer_serial.x509_issuer_name = recipient.issuer ();
+ kre.recipient.x509_issuer_serial.x509_serial_number = recipient.serial ();
+ kre.recipient.x509_subject_name = recipient.subject ();
kre.authorized_device_info.device_list_description = device_list_description;
kre.composition_playlist_id = cpl_id;
if (formulation == DCI_ANY || formulation == DCI_SPECIFIC) {
- kre.content_authenticator = signer->certificates().leaf()->thumbprint ();
+ kre.content_authenticator = signer->certificates().leaf().thumbprint ();
}
kre.content_title_text = content_title_text;
kre.not_valid_before = not_valid_before;
kre.not_valid_after = not_valid_after;
kre.authorized_device_info.device_list_identifier = make_uuid ();
- string n = recipient->common_name ();
+ string n = recipient.common_name ();
if (n.find (".") != string::npos) {
n = n.substr (n.find (".") + 1);
}
@@ -535,7 +535,7 @@ EncryptedKDM::EncryptedKDM (
kre.authorized_device_info.certificate_thumbprint = "2jmj7l5rSw0yVb/vlWAYkK/YBwk=";
} else if (formulation == DCI_SPECIFIC) {
/* Use the recipient thumbprint */
- kre.authorized_device_info.certificate_thumbprint = recipient->thumbprint ();
+ kre.authorized_device_info.certificate_thumbprint = recipient.thumbprint ();
}
for (list<pair<string, string> >::const_iterator i = key_ids.begin(); i != key_ids.end(); ++i) {
diff --git a/src/encrypted_kdm.h b/src/encrypted_kdm.h
index 1fcd37f4..f89ba596 100644
--- a/src/encrypted_kdm.h
+++ b/src/encrypted_kdm.h
@@ -78,7 +78,7 @@ private:
/** Construct an EncryptedKDM from a set of details */
EncryptedKDM (
boost::shared_ptr<const Signer> signer,
- boost::shared_ptr<const Certificate> recipient,
+ Certificate recipient,
std::string device_list_description,
std::string cpl_id,
std::string cpl_content_title_text,
diff --git a/src/signer.cc b/src/signer.cc
index 0dca8f21..d048ca4c 100644
--- a/src/signer.cc
+++ b/src/signer.cc
@@ -44,9 +44,9 @@ Signer::Signer (boost::filesystem::path openssl)
{
boost::filesystem::path directory = make_certificate_chain (openssl);
- _certificates.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (dcp::file_to_string (directory / "ca.self-signed.pem"))));
- _certificates.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (dcp::file_to_string (directory / "intermediate.signed.pem"))));
- _certificates.add (shared_ptr<dcp::Certificate> (new dcp::Certificate (dcp::file_to_string (directory / "leaf.signed.pem"))));
+ _certificates.add (dcp::Certificate (dcp::file_to_string (directory / "ca.self-signed.pem")));
+ _certificates.add (dcp::Certificate (dcp::file_to_string (directory / "intermediate.signed.pem")));
+ _certificates.add (dcp::Certificate (dcp::file_to_string (directory / "leaf.signed.pem")));
_key = dcp::file_to_string (directory / "leaf.key");
@@ -66,9 +66,9 @@ Signer::sign (xmlpp::Element* parent, Standard standard) const
xmlpp::Element* signer = parent->add_child("Signer");
xmlpp::Element* data = signer->add_child("X509Data", "dsig");
xmlpp::Element* serial_element = data->add_child("X509IssuerSerial", "dsig");
- serial_element->add_child("X509IssuerName", "dsig")->add_child_text (_certificates.leaf()->issuer());
- serial_element->add_child("X509SerialNumber", "dsig")->add_child_text (_certificates.leaf()->serial());
- data->add_child("X509SubjectName", "dsig")->add_child_text (_certificates.leaf()->subject());
+ serial_element->add_child("X509IssuerName", "dsig")->add_child_text (_certificates.leaf().issuer());
+ serial_element->add_child("X509SerialNumber", "dsig")->add_child_text (_certificates.leaf().serial());
+ data->add_child("X509SubjectName", "dsig")->add_child_text (_certificates.leaf().subject());
/* <Signature> */
@@ -119,11 +119,11 @@ Signer::add_signature_value (xmlpp::Node* parent, string ns) const
{
xmlpp::Element* serial = data->add_child("X509IssuerSerial", ns);
- serial->add_child("X509IssuerName", ns)->add_child_text((*i)->issuer ());
- serial->add_child("X509SerialNumber", ns)->add_child_text((*i)->serial ());
+ serial->add_child("X509IssuerName", ns)->add_child_text (i->issuer ());
+ serial->add_child("X509SerialNumber", ns)->add_child_text (i->serial ());
}
- data->add_child("X509Certificate", ns)->add_child_text((*i)->certificate());
+ data->add_child("X509Certificate", ns)->add_child_text (i->certificate());
}
xmlSecDSigCtxPtr signature_context = xmlSecDSigCtxCreate (0);
@@ -165,7 +165,7 @@ Signer::valid () const
}
RSA* private_key = PEM_read_bio_RSAPrivateKey (bio, 0, 0, 0);
- RSA* public_key = _certificates.leaf()->public_key ();
+ RSA* public_key = _certificates.leaf().public_key ();
bool const valid = !BN_cmp (private_key->n, public_key->n);
BIO_free (bio);