summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-01-03 21:01:26 +0000
committerCarl Hetherington <cth@carlh.net>2013-01-03 21:01:26 +0000
commit6a0c75ae216a36438537c1ebcb817e0250c7168e (patch)
tree3c138125a55a25058f64da20602be9f0032652af /src
parent50b5f8f9df0439d2d8fa9004e0b4af2f3e1eb44c (diff)
Fix missing certificates in CPLs.
Diffstat (limited to 'src')
-rw-r--r--src/certificates.cc24
-rw-r--r--src/certificates.h1
-rw-r--r--src/dcp.cc5
3 files changed, 30 insertions, 0 deletions
diff --git a/src/certificates.cc b/src/certificates.cc
index fe03f10e..621f44f2 100644
--- a/src/certificates.cc
+++ b/src/certificates.cc
@@ -27,6 +27,30 @@ Certificate::~Certificate ()
}
string
+Certificate::certificate () const
+{
+ BIO* bio = BIO_new (BIO_s_mem ());
+ if (!bio) {
+ throw MiscError ("could not create memory BIO");
+ }
+
+ PEM_write_bio_X509 (bio, _certificate);
+
+ string s;
+ char* data;
+ long int const data_length = BIO_get_mem_data (bio, &data);
+ for (long int i = 0; i < data_length; ++i) {
+ s += data[i];
+ }
+
+ BIO_free (bio);
+
+ boost::replace_all (s, "-----BEGIN CERTIFICATE-----\n", "");
+ boost::replace_all (s, "-----END CERTIFICATE-----\n", "");
+ return s;
+}
+
+string
Certificate::issuer () const
{
X509_NAME* n = X509_get_issuer_name (_certificate);
diff --git a/src/certificates.h b/src/certificates.h
index 428c36ea..a1a409ac 100644
--- a/src/certificates.h
+++ b/src/certificates.h
@@ -17,6 +17,7 @@ public:
Certificate (X509 *);
~Certificate ();
+ std::string certificate () const;
std::string issuer () const;
std::string serial () const;
std::string subject () const;
diff --git a/src/dcp.cc b/src/dcp.cc
index 2a1a156b..aa7bb46a 100644
--- a/src/dcp.cc
+++ b/src/dcp.cc
@@ -506,6 +506,7 @@ CPL::write_xml (bool encrypted, CertificateChain const & certificates, string co
list<shared_ptr<Certificate> > c = certificates.leaf_to_root ();
for (list<shared_ptr<Certificate> >::iterator i = c.begin(); i != c.end(); ++i) {
xmlpp::Element* data = key_info->add_child("X509Data", "dsig");
+
{
xmlpp::Element* serial = data->add_child("X509IssuerSerial", "dsig");
serial->add_child("X509IssuerName", "dsig")->add_child_text(
@@ -513,8 +514,12 @@ CPL::write_xml (bool encrypted, CertificateChain const & certificates, string co
);
serial->add_child("X509SerialNumber", "dsig")->add_child_text((*i)->serial());
}
+
+ data->add_child("X509Certificate", "dsig")->add_child_text((*i)->certificate());
}
+ doc.write_to_file_formatted ("/home/carl/fuckwit.xml", "UTF-8");
+
xmlSecKeysMngrPtr keys_manager = xmlSecKeysMngrCreate();
if (!keys_manager) {
throw MiscError ("could not create keys manager");