blob: 4e466e23d988ad87a503c5facd54e70766ede9dd [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 Zhang34f03f02020-10-29 18:34:42 -070024#include "detail/ca-request-state.hpp"
Zhiyi Zhangc2c4ed22020-10-14 17:16:28 -070025#include "name-assignment/assignment-func.hpp"
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080026
27namespace ndn {
28namespace ndncert {
29
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070030struct CaProfile {
tylerliu1f480be2020-11-10 13:02:53 -080031public:
32 /**
33 * Parse the configuration json and modify current struct to the result.
34 * @param configJson the configuration json to parse
35 */
36 void
37 parse(const JsonSection& configJson);
38
39 /**
40 * @return the JSON representation of this profile.
41 */
42 JsonSection
43 toJson() const;
44
45public:
Zhiyi Zhang9829da92020-09-30 16:19:34 -070046 /**
47 * CA Name prefix (without /CA suffix).
48 */
49 Name m_caPrefix;
50 /**
51 * CA Information.
52 * Default: "".
53 */
54 std::string m_caInfo;
55 /**
56 * A list of parameter-keys for PROBE.
57 * Default: empty list.
58 */
59 std::list<std::string> m_probeParameterKeys;
60 /**
61 * Maximum allowed validity period of the certificate being requested.
62 * The value is in the unit of second.
63 * Default: one day (86400 seconds).
64 */
65 time::seconds m_maxValidityPeriod;
66 /**
67 * Maximum allowed suffix length of requested name.
68 * E.g., When its value is 2, at most 2 name components can be assigned after m_caPrefix.
69 * Default: none.
70 */
Zhiyi Zhang997669a2020-10-28 21:15:40 -070071 optional<size_t> m_maxSuffixLength = nullopt;
Zhiyi Zhang9829da92020-09-30 16:19:34 -070072 /**
73 * A list of supported challenges. Only CA side will have m_supportedChallenges.
74 * Default: empty list.
75 */
76 std::list<std::string> m_supportedChallenges;
77 /**
78 * CA's certificate. Only Client side will have m_cert.
79 * Default: nullptr.
80 */
tylerliua7bea662020-10-08 18:51:02 -070081 std::shared_ptr<security::Certificate> m_cert;
Zhiyi Zhang9829da92020-09-30 16:19:34 -070082
Zhiyi Zhang9829da92020-09-30 16:19:34 -070083private:
84 void
85 parseProbeParameters(const JsonSection& section);
86
87 void
88 parseChallengeList(const JsonSection& configSection);
89};
90
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070091namespace ca {
92
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080093/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070094 * @brief CA's configuration on NDNCERT.
tylerliu1f480be2020-11-10 13:02:53 -080095 * @sa 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
tylerliu1f480be2020-11-10 13:02:53 -0800125public:
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700126 CaProfile m_caItem;
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700127 /**
tylerliu1f480be2020-11-10 13:02:53 -0800128 * Used for CA redirection
129 * @sa https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3-PROBE-Extensions#probe-extension-for-redirection
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700130 */
Zhiyi Zhang997669a2020-10-28 21:15:40 -0700131 optional<std::vector<std::shared_ptr<security::Certificate>>> m_redirection = nullopt;
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700132 /**
Zhiyi Zhang74c61142020-10-07 21:00:49 -0700133 * Name Assignment Functions
134 */
135 std::vector<std::unique_ptr<NameAssignmentFunc>> m_nameAssignmentFuncs;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800136};
137
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700138} // namespace ca
139
Zhiyi Zhang3002e6b2020-10-29 18:54:07 -0700140namespace requester {
141
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700142/**
143 * @brief Represents Client configuration
tylerliu1f480be2020-11-10 13:02:53 -0800144 * @sa https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700145 */
Zhiyi Zhanga16b7582020-10-29 18:59:46 -0700146class ProfileStorage
Zhiyi Zhang684c67c2020-10-12 14:28:17 -0700147{
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700148public:
149 /**
150 * @throw std::runtime_error when config file cannot be correctly parsed.
151 */
152 void
153 load(const std::string& fileName);
154
155 /**
156 * @throw std::runtime_error when config file cannot be correctly parsed.
157 */
158 void
159 load(const JsonSection& configSection);
160
161 void
162 save(const std::string& fileName) const;
163
164 void
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700165 removeCaProfile(const Name& caName);
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700166
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700167 /**
168 * Be cautious. This will add a new trust anchor for requesters.
169 */
170 void
171 addCaProfile(const CaProfile& profile);
172
tylerliu1f480be2020-11-10 13:02:53 -0800173 const std::list<CaProfile>&
174 getCaItems() const;
175
176private:
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700177 std::list<CaProfile> m_caItems;
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700178};
179
Zhiyi Zhang3002e6b2020-10-29 18:54:07 -0700180} // namespace requester
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700181} // namespace ndncert
182} // namespace ndn
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800183
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700184#endif // NDNCERT_CONFIGURATION_HPP