2 Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of libdcp.
6 libdcp is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libdcp is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libdcp. If not, see <http://www.gnu.org/licenses/>.
19 In addition, as a special exception, the copyright holders give
20 permission to link the code of portions of this program with the
21 OpenSSL library under certain conditions as described in each
22 individual source file, and distribute linked combinations
25 You must obey the GNU General Public License in all respects
26 for all of the code used other than OpenSSL. If you modify
27 file(s) with this exception, you may extend this exception to your
28 version of the file(s), but you are not obligated to do so. If you
29 do not wish to do so, delete this exception statement from your
30 version. If you delete this exception statement from all source
31 files in the program, then also delete it here.
34 /** @file src/signer_chain.h
35 * @brief Functions to make signer chains.
38 #ifndef LIBDCP_CERTIFICATE_CHAIN_H
39 #define LIBDCP_CERTIFICATE_CHAIN_H
41 #include "certificate.h"
43 #include <boost/filesystem.hpp>
44 #include <boost/optional.hpp>
52 /** @class CertificateChain
53 * @brief A chain of any number of certificates, from root to leaf.
55 class CertificateChain
58 CertificateChain () {}
60 /** Create a chain of certificates for signing things.
61 * @param openssl Name of openssl binary (if it is on the path) or full path.
62 * @return Directory (which should be deleted by the caller) containing:
63 * - ca.self-signed.pem self-signed root certificate
64 * - intermediate.signed.pem intermediate certificate
65 * - leaf.key leaf certificate private key
66 * - leaf.signed.pem leaf certificate
69 boost::filesystem::path openssl,
70 std::string organisation = "example.org",
71 std::string organisational_unit = "example.org",
72 std::string root_common_name = ".smpte-430-2.ROOT.NOT_FOR_PRODUCTION",
73 std::string intermediate_common_name = ".smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION",
74 std::string leaf_common_name = "CS.smpte-430-2.LEAF.NOT_FOR_PRODUCTION"
77 explicit CertificateChain (std::string);
79 void add (Certificate c);
80 void remove (Certificate c);
83 Certificate root () const;
84 Certificate leaf () const;
86 typedef std::list<Certificate> List;
88 List leaf_to_root () const;
89 List root_to_leaf () const;
92 bool attempt_reorder ();
94 void sign (xmlpp::Element* parent, Standard standard) const;
95 void add_signature_value (xmlpp::Node* parent, std::string ns) const;
97 boost::optional<std::string> key () const {
101 void set_key (std::string k) {
105 std::string chain () const;
108 friend class ::certificates;
111 /** Leaf certificate's private key, if known */
112 boost::optional<std::string> _key;