X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fsigner.cc;h=f6cc76ac4edbfdd9e84d7d34d362cd2e0a34af33;hb=491ac453512ac1982f62fc0d2a310586427601d7;hp=0dca8f2153268ed999a1073bcd7a869077deaec9;hpb=19356a292ba53b6d40270b1e74af5dad2304dbd5;p=libdcp.git diff --git a/src/signer.cc b/src/signer.cc index 0dca8f21..f6cc76ac 100644 --- a/src/signer.cc +++ b/src/signer.cc @@ -36,23 +36,45 @@ using std::string; using std::list; -using std::cout; using boost::shared_ptr; using namespace dcp; Signer::Signer (boost::filesystem::path openssl) { - boost::filesystem::path directory = make_certificate_chain (openssl); + create (make_certificate_chain (openssl)); +} + +Signer::Signer (boost::filesystem::path openssl, + string organisation, + string organisational_unit, + string root_common_name, + string intermediate_common_name, + string leaf_common_name + ) +{ + create ( + make_certificate_chain ( + openssl, + organisation, + organisational_unit, + root_common_name, + intermediate_common_name, + leaf_common_name + ) + ); +} - _certificates.add (shared_ptr (new dcp::Certificate (dcp::file_to_string (directory / "ca.self-signed.pem")))); - _certificates.add (shared_ptr (new dcp::Certificate (dcp::file_to_string (directory / "intermediate.signed.pem")))); - _certificates.add (shared_ptr (new dcp::Certificate (dcp::file_to_string (directory / "leaf.signed.pem")))); +void +Signer::create (boost::filesystem::path directory) +{ + _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"); boost::filesystem::remove_all (directory); } - /** Add a <Signer> and <ds:Signature> nodes to an XML node. * @param parent XML node to add to. @@ -66,9 +88,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()); /* */ @@ -119,11 +141,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 +187,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);