summaryrefslogtreecommitdiff
path: root/src/encrypted_kdm.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/encrypted_kdm.cc')
-rw-r--r--src/encrypted_kdm.cc216
1 files changed, 105 insertions, 111 deletions
diff --git a/src/encrypted_kdm.cc b/src/encrypted_kdm.cc
index 7cae0533..960af070 100644
--- a/src/encrypted_kdm.cc
+++ b/src/encrypted_kdm.cc
@@ -43,17 +43,17 @@ class Signer
public:
Signer () {}
- Signer (shared_ptr<const cxml::Node> node)
+ Signer (cxml::ConstNodePtr node)
: x509_issuer_name (node->string_child ("X509IssuerName"))
, x509_serial_number (node->string_child ("X509SerialNumber"))
{
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
- node->add_child("X509IssuerName", "ds")->add_child_text (x509_issuer_name);
- node->add_child("X509SerialNumber", "ds")->add_child_text (x509_serial_number);
+ node->add_child("X509IssuerName", "ds")->set_content (x509_issuer_name);
+ node->add_child("X509SerialNumber", "ds")->set_content (x509_serial_number);
}
string x509_issuer_name;
@@ -65,17 +65,17 @@ class X509Data
public:
X509Data () {}
- X509Data (boost::shared_ptr<const cxml::Node> node)
- : x509_issuer_serial (Signer (node->node_child ("X509IssuerSerial")))
+ X509Data (cxml::ConstNodePtr node)
+ : x509_issuer_serial (Signer (node->child ("X509IssuerSerial")))
, x509_certificate (node->string_child ("X509Certificate"))
{
node->done ();
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
x509_issuer_serial.as_xml (node->add_child ("X509IssuerSerial", "ds"));
- node->add_child("X509Certificate", "ds")->add_child_text (x509_certificate);
+ node->add_child("X509Certificate", "ds")->set_content (x509_certificate);
}
Signer x509_issuer_serial;
@@ -91,18 +91,18 @@ public:
: uri (u)
{}
- Reference (shared_ptr<const cxml::Node> node)
+ Reference (cxml::ConstNodePtr node)
: uri (node->string_attribute ("URI"))
, digest_value (node->string_child ("DigestValue"))
{
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
node->set_attribute ("URI", uri);
node->add_child("DigestMethod", "ds")->set_attribute ("Algorithm", "http://www.w3.org/2001/04/xmlenc#sha256");
- node->add_child("DigestValue", "ds")->add_child_text (digest_value);
+ node->add_child("DigestValue", "ds")->set_content (digest_value);
}
string uri;
@@ -117,10 +117,10 @@ public:
, authenticated_private ("#ID_AuthenticatedPrivate")
{}
- SignedInfo (shared_ptr<const cxml::Node> node)
+ SignedInfo (cxml::ConstNodePtr node)
{
- list<shared_ptr<cxml::Node> > references = node->node_children ("Reference");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = references.begin(); i != references.end(); ++i) {
+ cxml::NodeList references = node->children ("Reference");
+ for (cxml::NodeList::const_iterator i = references.begin(); i != references.end(); ++i) {
if ((*i)->string_attribute ("URI") == "#ID_AuthenticatedPublic") {
authenticated_public = Reference (*i);
} else if ((*i)->string_attribute ("URI") == "#ID_AuthenticatedPrivate") {
@@ -131,7 +131,7 @@ public:
}
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
node->add_child ("CanonicalizationMethod", "ds")->set_attribute (
"Algorithm", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"
@@ -155,22 +155,22 @@ class Signature
public:
Signature () {}
- Signature (shared_ptr<const cxml::Node> node)
- : signed_info (node->node_child ("SignedInfo"))
+ Signature (cxml::ConstNodePtr node)
+ : signed_info (node->child ("SignedInfo"))
, signature_value (node->string_child ("SignatureValue"))
{
- list<shared_ptr<cxml::Node> > x509_data_nodes = node->node_child("KeyInfo")->node_children ("X509Data");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = x509_data_nodes.begin(); i != x509_data_nodes.end(); ++i) {
+ cxml::NodeList x509_data_nodes = node->child("KeyInfo")->children ("X509Data");
+ for (cxml::NodeList::const_iterator i = x509_data_nodes.begin(); i != x509_data_nodes.end(); ++i) {
x509_data.push_back (X509Data (*i));
}
}
- void as_xml (xmlpp::Node* node) const
+ void as_xml (cxml::NodePtr node) const
{
signed_info.as_xml (node->add_child ("SignedInfo", "ds"));
- node->add_child("SignatureValue", "ds")->add_child_text (signature_value);
+ node->add_child("SignatureValue", "ds")->set_content (signature_value);
- xmlpp::Element* key_info_node = node->add_child ("KeyInfo", "ds");
+ cxml::NodePtr key_info_node = node->add_child ("KeyInfo", "ds");
for (std::list<X509Data>::const_iterator i = x509_data.begin(); i != x509_data.end(); ++i) {
i->as_xml (key_info_node->add_child ("X509Data", "ds"));
}
@@ -186,26 +186,26 @@ class AuthenticatedPrivate
public:
AuthenticatedPrivate () {}
- AuthenticatedPrivate (shared_ptr<const cxml::Node> node)
+ AuthenticatedPrivate (cxml::ConstNodePtr node)
{
- list<shared_ptr<cxml::Node> > encrypted_key_nodes = node->node_children ("EncryptedKey");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = encrypted_key_nodes.begin(); i != encrypted_key_nodes.end(); ++i) {
- encrypted_key.push_back ((*i)->node_child("CipherData")->string_child ("CipherValue"));
+ cxml::NodeList encrypted_key_nodes = node->children ("EncryptedKey");
+ for (cxml::NodeList::const_iterator i = encrypted_key_nodes.begin(); i != encrypted_key_nodes.end(); ++i) {
+ encrypted_key.push_back ((*i)->child("CipherData")->string_child ("CipherValue"));
}
}
- void as_xml (xmlpp::Element* node, map<string, xmlpp::Attribute *>& references) const
+ void as_xml (cxml::NodePtr node) const
{
- references["ID_AuthenticatedPrivate"] = node->set_attribute ("Id", "ID_AuthenticatedPrivate");
+ node->set_attribute ("Id", "ID_AuthenticatedPrivate");
for (list<string>::const_iterator i = encrypted_key.begin(); i != encrypted_key.end(); ++i) {
- xmlpp::Element* encrypted_key = node->add_child ("EncryptedKey", "enc");
- xmlpp::Element* encryption_method = encrypted_key->add_child ("EncryptionMethod", "enc");
+ cxml::NodePtr encrypted_key = node->add_child ("EncryptedKey", "enc");
+ cxml::NodePtr encryption_method = encrypted_key->add_child ("EncryptionMethod", "enc");
encryption_method->set_attribute ("Algorithm", "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
- xmlpp::Element* digest_method = encryption_method->add_child ("DigestMethod", "ds");
+ cxml::NodePtr digest_method = encryption_method->add_child ("DigestMethod", "ds");
digest_method->set_attribute ("Algorithm", "http://www.w3.org/2000/09/xmldsig#sha1");
- xmlpp::Element* cipher_data = encrypted_key->add_child ("CipherData", "enc");
- cipher_data->add_child("CipherValue", "enc")->add_child_text (*i);
+ cxml::NodePtr cipher_data = encrypted_key->add_child ("CipherData", "enc");
+ cipher_data->add_child("CipherValue", "enc")->set_content (*i);
}
}
@@ -217,7 +217,7 @@ class TypedKeyId
public:
TypedKeyId () {}
- TypedKeyId (shared_ptr<const cxml::Node> node)
+ TypedKeyId (cxml::ConstNodePtr node)
: key_type (node->string_child ("KeyType"))
, key_id (node->string_child ("KeyId").substr (9))
{
@@ -229,10 +229,10 @@ public:
, key_id (id)
{}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
- node->add_child("KeyType")->add_child_text (key_type);
- node->add_child("KeyId")->add_child_text ("urn:uuid:" + key_id);
+ node->add_child("KeyType")->set_content (key_type);
+ node->add_child("KeyId")->set_content ("urn:uuid:" + key_id);
}
string key_type;
@@ -244,15 +244,15 @@ class KeyIdList
public:
KeyIdList () {}
- KeyIdList (shared_ptr<const cxml::Node> node)
+ KeyIdList (cxml::ConstNodePtr node)
{
- list<shared_ptr<cxml::Node> > typed_key_id_nodes = node->node_children ("TypedKeyId");
- for (list<shared_ptr<cxml::Node> >::const_iterator i = typed_key_id_nodes.begin(); i != typed_key_id_nodes.end(); ++i) {
+ cxml::NodeList typed_key_id_nodes = node->children ("TypedKeyId");
+ for (cxml::NodeList::const_iterator i = typed_key_id_nodes.begin(); i != typed_key_id_nodes.end(); ++i) {
typed_key_id.push_back (TypedKeyId (*i));
}
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
for (list<TypedKeyId>::const_iterator i = typed_key_id.begin(); i != typed_key_id.end(); ++i) {
i->as_xml (node->add_child("TypedKeyId"));
@@ -267,20 +267,20 @@ class AuthorizedDeviceInfo
public:
AuthorizedDeviceInfo () {}
- AuthorizedDeviceInfo (shared_ptr<const cxml::Node> node)
+ AuthorizedDeviceInfo (cxml::ConstNodePtr node)
: device_list_identifier (node->string_child ("DeviceListIdentifier").substr (9))
, device_list_description (node->string_child ("DeviceListDescription"))
- , certificate_thumbprint (node->node_child("DeviceList")->string_child ("CertificateThumbprint"))
+ , certificate_thumbprint (node->child("DeviceList")->string_child ("CertificateThumbprint"))
{
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
- node->add_child ("DeviceListIdentifier")->add_child_text ("urn:uuid:" + device_list_identifier);
- node->add_child ("DeviceListDescription")->add_child_text (device_list_description);
- xmlpp::Element* device_list = node->add_child ("DeviceList");
- device_list->add_child("CertificateThumbprint")->add_child_text (certificate_thumbprint);
+ node->add_child ("DeviceListIdentifier")->set_content ("urn:uuid:" + device_list_identifier);
+ node->add_child ("DeviceListDescription")->set_content (device_list_description);
+ cxml::NodePtr device_list = node->add_child ("DeviceList");
+ device_list->add_child("CertificateThumbprint")->set_content (certificate_thumbprint);
}
/** DeviceListIdentifier without the urn:uuid: prefix */
@@ -294,17 +294,17 @@ class X509IssuerSerial
public:
X509IssuerSerial () {}
- X509IssuerSerial (shared_ptr<const cxml::Node> node)
+ X509IssuerSerial (cxml::ConstNodePtr node)
: x509_issuer_name (node->string_child ("X509IssuerName"))
, x509_serial_number (node->string_child ("X509SerialNumber"))
{
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
- node->add_child("X509IssuerName", "ds")->add_child_text (x509_issuer_name);
- node->add_child("X509SerialNumber", "ds")->add_child_text (x509_serial_number);
+ node->add_child("X509IssuerName", "ds")->set_content (x509_issuer_name);
+ node->add_child("X509SerialNumber", "ds")->set_content (x509_serial_number);
}
string x509_issuer_name;
@@ -316,17 +316,17 @@ class Recipient
public:
Recipient () {}
- Recipient (shared_ptr<const cxml::Node> node)
- : x509_issuer_serial (node->node_child ("X509IssuerSerial"))
+ Recipient (cxml::ConstNodePtr node)
+ : x509_issuer_serial (node->child ("X509IssuerSerial"))
, x509_subject_name (node->string_child ("X509SubjectName"))
{
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
x509_issuer_serial.as_xml (node->add_child ("X509IssuerSerial"));
- node->add_child("X509SubjectName")->add_child_text (x509_subject_name);
+ node->add_child("X509SubjectName")->set_content (x509_subject_name);
}
X509IssuerSerial x509_issuer_serial;
@@ -338,36 +338,36 @@ class KDMRequiredExtensions
public:
KDMRequiredExtensions () {}
- KDMRequiredExtensions (shared_ptr<const cxml::Node> node)
- : recipient (node->node_child ("Recipient"))
+ KDMRequiredExtensions (cxml::ConstNodePtr node)
+ : recipient (node->child ("Recipient"))
, composition_playlist_id (node->string_child ("CompositionPlaylistId").substr (9))
, content_title_text (node->string_child ("ContentTitleText"))
, not_valid_before (node->string_child ("ContentKeysNotValidBefore"))
, not_valid_after (node->string_child ("ContentKeysNotValidAfter"))
- , authorized_device_info (node->node_child ("AuthorizedDeviceInfo"))
- , key_id_list (node->node_child ("KeyIdList"))
+ , authorized_device_info (node->child ("AuthorizedDeviceInfo"))
+ , key_id_list (node->child ("KeyIdList"))
{
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
node->set_attribute ("xmlns", "http://www.smpte-ra.org/schemas/430-1/2006/KDM");
recipient.as_xml (node->add_child ("Recipient"));
- node->add_child("CompositionPlaylistId")->add_child_text ("urn:uuid:" + composition_playlist_id);
+ node->add_child("CompositionPlaylistId")->set_content ("urn:uuid:" + composition_playlist_id);
if (content_authenticator) {
- node->add_child("ContentAuthenticator")->add_child_text (content_authenticator.get ());
+ node->add_child("ContentAuthenticator")->set_content (content_authenticator.get ());
}
- node->add_child("ContentTitleText")->add_child_text (content_title_text);
- node->add_child("ContentKeysNotValidBefore")->add_child_text (not_valid_before.as_string ());
- node->add_child("ContentKeysNotValidAfter")->add_child_text (not_valid_after.as_string ());
+ node->add_child("ContentTitleText")->set_content (content_title_text);
+ node->add_child("ContentKeysNotValidBefore")->set_content (not_valid_before.as_string ());
+ node->add_child("ContentKeysNotValidAfter")->set_content (not_valid_after.as_string ());
authorized_device_info.as_xml (node->add_child ("AuthorizedDeviceInfo"));
key_id_list.as_xml (node->add_child ("KeyIdList"));
- xmlpp::Element* forensic_mark_flag_list = node->add_child ("ForensicMarkFlagList");
- forensic_mark_flag_list->add_child("ForensicMarkFlag")->add_child_text ("http://www.smpte-ra.org/430-1/2006/KDM#mrkflg-picture-disable");
- forensic_mark_flag_list->add_child("ForensicMarkFlag")->add_child_text ("http://www.smpte-ra.org/430-1/2006/KDM#mrkflg-audio-disable");
+ cxml::NodePtr forensic_mark_flag_list = node->add_child ("ForensicMarkFlagList");
+ forensic_mark_flag_list->add_child("ForensicMarkFlag")->set_content ("http://www.smpte-ra.org/430-1/2006/KDM#mrkflg-picture-disable");
+ forensic_mark_flag_list->add_child("ForensicMarkFlag")->set_content ("http://www.smpte-ra.org/430-1/2006/KDM#mrkflg-audio-disable");
}
Recipient recipient;
@@ -385,13 +385,13 @@ class RequiredExtensions
public:
RequiredExtensions () {}
- RequiredExtensions (shared_ptr<const cxml::Node> node)
- : kdm_required_extensions (node->node_child ("KDMRequiredExtensions"))
+ RequiredExtensions (cxml::ConstNodePtr node)
+ : kdm_required_extensions (node->child ("KDMRequiredExtensions"))
{
}
- void as_xml (xmlpp::Element* node) const
+ void as_xml (cxml::NodePtr node) const
{
kdm_required_extensions.as_xml (node->add_child ("KDMRequiredExtensions"));
}
@@ -407,24 +407,24 @@ public:
, issue_date (LocalTime().as_string ())
{}
- AuthenticatedPublic (shared_ptr<const cxml::Node> node)
+ AuthenticatedPublic (cxml::ConstNodePtr node)
: message_id (node->string_child ("MessageId").substr (9))
, annotation_text (node->string_child ("AnnotationText"))
, issue_date (node->string_child ("IssueDate"))
- , signer (node->node_child ("Signer"))
- , required_extensions (node->node_child ("RequiredExtensions"))
+ , signer (node->child ("Signer"))
+ , required_extensions (node->child ("RequiredExtensions"))
{
}
- void as_xml (xmlpp::Element* node, map<string, xmlpp::Attribute *>& references) const
+ void as_xml (cxml::NodePtr node) const
{
- references["ID_AuthenticatedPublic"] = node->set_attribute ("Id", "ID_AuthenticatedPublic");
+ node->set_attribute ("Id", "ID_AuthenticatedPublic");
- node->add_child("MessageId")->add_child_text ("urn:uuid:" + message_id);
- node->add_child("MessageType")->add_child_text ("http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type");
- node->add_child("AnnotationText")->add_child_text (annotation_text);
- node->add_child("IssueDate")->add_child_text (issue_date);
+ node->add_child("MessageId")->set_content ("urn:uuid:" + message_id);
+ node->add_child("MessageType")->set_content ("http://www.smpte-ra.org/430-1/2006/KDM#kdm-key-type");
+ node->add_child("AnnotationText")->set_content (annotation_text);
+ node->add_child("IssueDate")->set_content (issue_date);
signer.as_xml (node->add_child ("Signer"));
required_extensions.as_xml (node->add_child ("RequiredExtensions"));
@@ -450,30 +450,31 @@ public:
}
- EncryptedKDMData (shared_ptr<const cxml::Node> node)
- : authenticated_public (node->node_child ("AuthenticatedPublic"))
- , authenticated_private (node->node_child ("AuthenticatedPrivate"))
- , signature (node->node_child ("Signature"))
+ EncryptedKDMData (cxml::ConstNodePtr node)
+ : authenticated_public (node->child ("AuthenticatedPublic"))
+ , authenticated_private (node->child ("AuthenticatedPrivate"))
+ , signature (node->child ("Signature"))
{
}
- shared_ptr<xmlpp::Document> as_xml () const
+ cxml::NodePtr as_xml () const
{
- shared_ptr<xmlpp::Document> document (new xmlpp::Document ());
- xmlpp::Element* root = document->create_root_node ("DCinemaSecurityMessage", "http://www.smpte-ra.org/schemas/430-3/2006/ETM");
- root->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "ds");
- root->set_namespace_declaration ("http://www.w3.org/2001/04/xmlenc#", "enc");
- map<string, xmlpp::Attribute *> references;
- authenticated_public.as_xml (root->add_child ("AuthenticatedPublic"), references);
- authenticated_private.as_xml (root->add_child ("AuthenticatedPrivate"), references);
+ cxml::NodePtr root (new cxml::Node);
+ root->set_name ("DCinemaSecurityMessage");
+ root->set_attribute ("xmlns", "http://www.smpte-ra.org/schemas/430-3/2006/ETM");
+ root->set_attribute ("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#");
+ root->set_attribute ("xmlns:enc", "http://www.w3.org/2001/04/xmlenc#");
+ authenticated_public.as_xml (root->add_child ("AuthenticatedPublic"));
+ authenticated_private.as_xml (root->add_child ("AuthenticatedPrivate"));
signature.as_xml (root->add_child ("Signature", "ds"));
- for (map<string, xmlpp::Attribute*>::const_iterator i = references.begin(); i != references.end(); ++i) {
- xmlAddID (0, document->cobj(), (const xmlChar *) i->first.c_str(), i->second->cobj ());
- }
+ /* XXX */
+// for (map<string, xmlpp::Attribute*>::const_iterator i = references.begin(); i != references.end(); ++i) {
+// xmlAddID (0, document->cobj(), (const xmlChar *) i->first.c_str(), i->second->cobj ());
+// }
- return document;
+ return root;
}
AuthenticatedPublic authenticated_public;
@@ -486,8 +487,7 @@ public:
EncryptedKDM::EncryptedKDM (string s)
{
- shared_ptr<cxml::Document> doc (new cxml::Document ("DCinemaSecurityMessage"));
- doc->read_string (s);
+ cxml::NodePtr doc = cxml::read_string (s);
_data = new data::EncryptedKDMData (doc);
}
@@ -545,17 +545,16 @@ EncryptedKDM::EncryptedKDM (
_data->authenticated_private.encrypted_key = keys;
/* Read the XML so far and sign it */
- shared_ptr<xmlpp::Document> doc = _data->as_xml ();
- xmlpp::Node::NodeList children = doc->get_root_node()->get_children ();
- for (xmlpp::Node::NodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
- if ((*i)->get_name() == "Signature") {
+ cxml::NodePtr doc = _data->as_xml ();
+ cxml::NodeList children = doc->children ();
+ for (cxml::NodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
+ if ((*i)->name() == "Signature") {
signer->add_signature_value (*i, "ds");
}
}
/* Read the bits that add_signature_value did back into our variables */
- shared_ptr<cxml::Node> signed_doc (new cxml::Node (doc->get_root_node ()));
- _data->signature = data::Signature (signed_doc->node_child ("Signature"));
+ _data->signature = data::Signature (doc->child ("Signature"));
}
EncryptedKDM::EncryptedKDM (EncryptedKDM const & other)
@@ -593,12 +592,7 @@ EncryptedKDM::as_xml (boost::filesystem::path path) const
string
EncryptedKDM::as_xml () const
{
- xmlpp::Document document;
- xmlpp::Element* root = document.create_root_node ("DCinemaSecurityMessage", "http://www.smpte-ra.org/schemas/430-3/2006/ETM");
- root->set_namespace_declaration ("http://www.w3.org/2000/09/xmldsig#", "ds");
- root->set_namespace_declaration ("http://www.w3.org/2001/04/xmlenc#", "enc");
-
- return _data->as_xml()->write_to_string ("UTF-8");
+ return cxml::write_to_string (_data->as_xml ());
}
list<string>