blob: 50d2a8bb54eedc1d62a2a8e8b8596d24c312d7d3 [file] [log] [blame]
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7838cfd2020-06-03 14:16:43 -04003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -08004 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
tylerliu8704d032020-06-23 10:18:15 -070021#ifndef NDNCERT_CONFIGURATION_HPP
22#define NDNCERT_CONFIGURATION_HPP
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080023
Zhiyi Zhang062be6d2020-10-14 17:13:43 -070024#include "detail/ca-state.hpp"
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070025#include "name-assignments/assignment-funcs.hpp"
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080026
27namespace ndn {
28namespace ndncert {
29
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070030struct CaProfile {
Zhiyi Zhang9829da92020-09-30 16:19:34 -070031 /**
32 * CA Name prefix (without /CA suffix).
33 */
34 Name m_caPrefix;
35 /**
36 * CA Information.
37 * Default: "".
38 */
39 std::string m_caInfo;
40 /**
41 * A list of parameter-keys for PROBE.
42 * Default: empty list.
43 */
44 std::list<std::string> m_probeParameterKeys;
45 /**
46 * Maximum allowed validity period of the certificate being requested.
47 * The value is in the unit of second.
48 * Default: one day (86400 seconds).
49 */
50 time::seconds m_maxValidityPeriod;
51 /**
52 * Maximum allowed suffix length of requested name.
53 * E.g., When its value is 2, at most 2 name components can be assigned after m_caPrefix.
54 * Default: none.
55 */
56 boost::optional<size_t> m_maxSuffixLength;
57 /**
58 * A list of supported challenges. Only CA side will have m_supportedChallenges.
59 * Default: empty list.
60 */
61 std::list<std::string> m_supportedChallenges;
62 /**
63 * CA's certificate. Only Client side will have m_cert.
64 * Default: nullptr.
65 */
tylerliua7bea662020-10-08 18:51:02 -070066 std::shared_ptr<security::Certificate> m_cert;
Zhiyi Zhang9829da92020-09-30 16:19:34 -070067
68 void
69 parse(const JsonSection& configJson);
70
71 JsonSection
72 toJson() const;
73
74private:
75 void
76 parseProbeParameters(const JsonSection& section);
77
78 void
79 parseChallengeList(const JsonSection& configSection);
80};
81
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080082/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070083 * @brief The function would be invoked whenever the certificate request status is updated.
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080084 * The callback is used to notice the CA application or CA command line tool. The callback is
85 * fired whenever a request instance is created, challenge status is updated, and when certificate
86 * is issued.
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070087 *
tylerliu8704d032020-06-23 10:18:15 -070088 * @p CaState, input, the state of the certificate request whose status is updated.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080089 */
tylerliu8704d032020-06-23 10:18:15 -070090using StatusUpdateCallback = function<void(const CaState&)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080091
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080092/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070093 * @brief CA's configuration on NDNCERT.
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070094 * For CA configuration format, please refer to:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070095 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070096 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070097 * The format of CA configuration in JSON
98 * {
99 * "ca-prefix": "",
100 * "ca-info": "",
101 * "max-validity-period": "",
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700102 * "max-suffix-length": "",
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700103 * "probe-parameters":
104 * [
105 * {"probe-parameter-key": ""},
106 * {"probe-parameter-key": ""}
107 * ]
108 * "supported-challenges":
109 * [
110 * {"challenge": ""},
111 * {"challenge": ""}
112 * ]
113 * }
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800114 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -0700115class CaConfig
116{
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800117public:
118 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700119 * Load CA configuration from the file.
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700120 * @throw std::runtime_error when config file cannot be correctly parsed.
Zhiyi Zhang8da54d62019-11-21 00:03:05 -0800121 */
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800122 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -0800123 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800124
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700125 CaProfile m_caItem;
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700126 /**
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700127 * Used for CA redirection as specified in
128 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3-PROBE-Extensions#probe-extension-for-redirection
129 */
tylerliua7bea662020-10-08 18:51:02 -0700130 boost::optional<std::vector<std::shared_ptr<security::Certificate>>> m_redirection;
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700131 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700132 * StatusUpdate Callback function
133 */
134 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhang74c61142020-10-07 21:00:49 -0700135 /**
136 * Name Assignment Functions
137 */
138 std::vector<std::unique_ptr<NameAssignmentFunc>> m_nameAssignmentFuncs;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800139};
140
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700141/**
142 * @brief Represents Client configuration
143 *
144 * For Client configuration format, please refer to:
145 * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample
146 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -0700147class RequesterCaCache
148{
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700149public:
150 /**
151 * @throw std::runtime_error when config file cannot be correctly parsed.
152 */
153 void
154 load(const std::string& fileName);
155
156 /**
157 * @throw std::runtime_error when config file cannot be correctly parsed.
158 */
159 void
160 load(const JsonSection& configSection);
161
162 void
163 save(const std::string& fileName) const;
164
165 void
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700166 removeCaProfile(const Name& caName);
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700167
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700168 /**
169 * Be cautious. This will add a new trust anchor for requesters.
170 */
171 void
172 addCaProfile(const CaProfile& profile);
173
174 std::list<CaProfile> m_caItems;
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700175};
176
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700177} // namespace ndncert
178} // namespace ndn
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800179
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700180#endif // NDNCERT_CONFIGURATION_HPP