Fix missing certificates in CPLs.
authorCarl Hetherington <cth@carlh.net>
Thu, 3 Jan 2013 21:01:26 +0000 (21:01 +0000)
committerCarl Hetherington <cth@carlh.net>
Thu, 3 Jan 2013 21:01:26 +0000 (21:01 +0000)
src/certificates.cc
src/certificates.h
src/dcp.cc

index fe03f10e3b8a4dffd46ca636d3f473bce434ed57..621f44f22ff12a05ef166ed89057274a0d844d01 100644 (file)
@@ -26,6 +26,30 @@ Certificate::~Certificate ()
        X509_free (_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
 {
index 428c36ea173c4d72c88cde8c7b5eaa9bc59449ab..a1a409ac0902fb9ccd0a7bac43fe5973f8d1229c 100644 (file)
@@ -17,6 +17,7 @@ public:
        Certificate (X509 *);
        ~Certificate ();
 
+       std::string certificate () const;
        std::string issuer () const;
        std::string serial () const;
        std::string subject () const;
index 2a1a156b3fcf5ba7f2c36fb71a172cf73f792de2..aa7bb46a2164a0a66514196d5c8cffca2294dd87 100644 (file)
@@ -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");