Allow Signer and certificate chains to be made with specified organisation, common...
authorCarl Hetherington <cth@carlh.net>
Thu, 11 Sep 2014 13:06:19 +0000 (14:06 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 11 Sep 2014 13:06:19 +0000 (14:06 +0100)
src/certificate_chain.cc
src/certificate_chain.h
src/signer.cc
src/signer.h

index 5d01790b0ac381aa9c43e7fb3b37d259135ba451..b2ebeca8c9bd86beaf196b538a032c8a4be6b0d5 100644 (file)
@@ -157,7 +157,14 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
 }
 
 boost::filesystem::path
-dcp::make_certificate_chain (boost::filesystem::path openssl)
+dcp::make_certificate_chain (
+       boost::filesystem::path openssl,
+       string organisation,
+       string organisational_unit,
+       string root_common_name,
+       string intermediate_common_name,
+       string leaf_common_name
+       )
 {
        boost::filesystem::path directory = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path ();
        boost::filesystem::create_directories (directory);
@@ -185,7 +192,10 @@ dcp::make_certificate_chain (boost::filesystem::path openssl)
                  << "CN = Entity and dnQualifier\n";
        }
 
-       string const ca_subject = "/O=example.org/OU=example.org/CN=.smpte-430-2.ROOT.NOT_FOR_PRODUCTION/dnQualifier=" + public_key_digest ("ca.key", openssl);
+       string const ca_subject = "/O=" + organisation +
+               "/OU=" + organisational_unit +
+               "/CN=" + root_common_name +
+               "/dnQualifier=" + public_key_digest ("ca.key", openssl);
 
        {
                stringstream c;
@@ -213,8 +223,10 @@ dcp::make_certificate_chain (boost::filesystem::path openssl)
                  << "CN = Entity and dnQualifier\n";
        }
                
-       string const inter_subject = "/O=example.org/OU=example.org/CN=.smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION/dnQualifier="
-               + public_key_digest ("intermediate.key", openssl);
+       string const inter_subject = "/O=" + organisation +
+               "/OU=" + organisational_unit +
+               "/CN=" + intermediate_common_name +
+               "/dnQualifier=" + public_key_digest ("intermediate.key", openssl);
 
        {
                stringstream s;
@@ -248,8 +260,10 @@ dcp::make_certificate_chain (boost::filesystem::path openssl)
                  << "CN = Entity and dnQualifier\n";
        }
 
-       string const leaf_subject = "/O=example.org/OU=example.org/CN=CS.smpte-430-2.LEAF.NOT_FOR_PRODUCTION/dnQualifier="
-               + public_key_digest ("leaf.key", openssl);
+       string const leaf_subject = "/O=" + organisation +
+               "/OU=" + organisational_unit +
+               "/CN=" + leaf_common_name +
+               "/dnQualifier=" + public_key_digest ("leaf.key", openssl);
 
        {
                stringstream s;
index 6a6fc48357bf80ab79602cba4bd224301dd2906a..e074f8fd531c5dd43523ef8a7c5ddc5ba3c25f98 100644 (file)
@@ -33,6 +33,13 @@ namespace dcp {
  *    - leaf.key                leaf certificate private key
  *    - leaf.signed.pem         leaf certificate
  */
-boost::filesystem::path make_certificate_chain (boost::filesystem::path openssl);
-
+boost::filesystem::path make_certificate_chain (
+       boost::filesystem::path openssl,
+       std::string organisation = "example.org",
+       std::string organisational_unit = "example.org",
+       std::string root_common_name = ".smpte-430-2.ROOT.NOT_FOR_PRODUCTION",
+       std::string intermediate_common_name = ".smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION",
+       std::string leaf_common_name = "CS.smpte-430-2.LEAF.NOT_FOR_PRODUCTION"
+       );
+       
 }
index d048ca4c9a93518992b9c0de64abe3984b5ee869..67c8ac58fabc43fececf9d5bee97816809cb0b6a 100644 (file)
@@ -42,8 +42,32 @@ 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
+                       )
+               );
+}
 
+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")));
@@ -52,7 +76,6 @@ Signer::Signer (boost::filesystem::path openssl)
 
        boost::filesystem::remove_all (directory);
 }
-       
 
 /** Add a &lt;Signer&gt; and &lt;ds:Signature&gt; nodes to an XML node.
  *  @param parent XML node to add to.
index 6fd17033f1c24d41a3652c09addd60d1a227acb6..1d53d5baf2eefec241dcec1645ec04f739cf8c49 100644 (file)
@@ -42,6 +42,15 @@ class Signer
 {
 public:
        Signer (boost::filesystem::path openssl);
+
+       Signer (
+               boost::filesystem::path openssl,
+               std::string organisation,
+               std::string organisational_unit,
+               std::string root_common_name,
+               std::string intermediate_common_name,
+               std::string leaf_common_name
+               );
        
        /** @param c Certificate chain to sign with.
         *  @param k Key to sign with as a PEM-format string.
@@ -73,7 +82,8 @@ public:
        bool valid () const;
        
 private:       
-
+       void create (boost::filesystem::path directory);
+       
        /** Certificate chain to sign with */
        CertificateChain _certificates;
        /** Key to sign with as a PEM-format string */