libdcp
certificate_chain.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
3 
4  This file is part of libdcp.
5 
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.
10 
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.
15 
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/>.
18 
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
23  including the two.
24 
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.
32 */
33 
34 
40 #ifndef LIBDCP_CERTIFICATE_CHAIN_H
41 #define LIBDCP_CERTIFICATE_CHAIN_H
42 
43 
44 #include "certificate.h"
45 #include "types.h"
46 #include <boost/filesystem.hpp>
47 #include <boost/optional.hpp>
48 
49 
50 namespace xmlpp {
51  class Node;
52 }
53 
54 
55 struct certificates_validation1;
56 struct certificates_validation2;
57 struct certificates_validation3;
58 struct certificates_validation4;
59 struct certificates_validation5;
60 struct certificates_validation6;
61 struct certificates_validation7;
62 struct certificates_validation8;
63 
64 
65 namespace dcp {
66 
67 
75 {
76 public:
77  CertificateChain () {}
78 
88  boost::filesystem::path openssl,
89  int validity_in_days,
90  std::string organisation = "example.org",
91  std::string organisational_unit = "example.org",
92  std::string root_common_name = ".smpte-430-2.ROOT.NOT_FOR_PRODUCTION",
93  std::string intermediate_common_name = ".smpte-430-2.INTERMEDIATE.NOT_FOR_PRODUCTION",
94  std::string leaf_common_name = "CS.smpte-430-2.LEAF.NOT_FOR_PRODUCTION"
95  );
96 
100  explicit CertificateChain (std::string s);
101 
105  void add (Certificate c);
106 
110  void remove (Certificate c);
111 
115  void remove (int i);
116 
118  Certificate root () const;
119 
121  Certificate leaf () const;
122 
123  typedef std::vector<Certificate> List;
124 
126  List leaf_to_root () const;
128  List root_to_leaf () const;
129  List unordered () const;
130 
131  bool valid (std::string* reason = nullptr) const;
132 
138  bool chain_valid () const;
139 
143  bool private_key_valid () const;
144 
149  void sign (xmlpp::Element* parent, Standard standard) const;
150 
156  void add_signature_value (xmlpp::Element* parent, std::string ns, bool add_indentation) const;
157 
158  boost::optional<std::string> key () const {
159  return _key;
160  }
161 
162  void set_key (std::string k) {
163  _key = k;
164  }
165 
166  std::string chain () const;
167 
168 private:
169  friend struct ::certificates_validation1;
170  friend struct ::certificates_validation2;
171  friend struct ::certificates_validation3;
172  friend struct ::certificates_validation4;
173  friend struct ::certificates_validation5;
174  friend struct ::certificates_validation6;
175  friend struct ::certificates_validation7;
176  friend struct ::certificates_validation8;
177 
178  bool chain_valid (List const & chain) const;
179 
183  boost::optional<std::string> _key;
184 };
185 
186 
187 }
188 
189 
190 #endif
Certificate class.
A chain of any number of certificates, from root to leaf.
void add(Certificate c)
Certificate leaf() const
Certificate root() const
boost::optional< std::string > _key
void add_signature_value(xmlpp::Element *parent, std::string ns, bool add_indentation) const
void sign(xmlpp::Element *parent, Standard standard) const
void remove(Certificate c)
A wrapper for an X509 certificate.
Definition: certificate.h:66
Namespace for everything in libdcp.
Definition: array_data.h:50
Miscellaneous types.