blob: ec8ccb1f25834f2968613151dba988e8b3af9ea7 [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 {
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 */
Zhiyi Zhang997669a2020-10-28 21:15:40 -070056 optional<size_t> m_maxSuffixLength = nullopt;
Zhiyi Zhang9829da92020-09-30 16:19:34 -070057 /**
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 Zhang32d4b4e2020-10-28 22:10:49 -070082namespace ca {
83
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080084/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070085 * @brief The function would be invoked whenever the certificate request status is updated.
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080086 * The callback is used to notice the CA application or CA command line tool. The callback is
87 * fired whenever a request instance is created, challenge status is updated, and when certificate
88 * is issued.
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070089 *
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070090 * @param RequestState The state of the certificate request whose status is updated.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080091 */
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070092using StatusUpdateCallback = function<void(const RequestState&)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080093
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080094/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070095 * @brief CA's configuration on NDNCERT.
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070096 * For CA configuration format, please refer to:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070097 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070098 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070099 * The format of CA configuration in JSON
100 * {
101 * "ca-prefix": "",
102 * "ca-info": "",
103 * "max-validity-period": "",
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700104 * "max-suffix-length": "",
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700105 * "probe-parameters":
106 * [
107 * {"probe-parameter-key": ""},
108 * {"probe-parameter-key": ""}
109 * ]
110 * "supported-challenges":
111 * [
112 * {"challenge": ""},
113 * {"challenge": ""}
114 * ]
115 * }
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800116 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -0700117class CaConfig
118{
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800119public:
120 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700121 * Load CA configuration from the file.
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700122 * @throw std::runtime_error when config file cannot be correctly parsed.
Zhiyi Zhang8da54d62019-11-21 00:03:05 -0800123 */
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800124 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -0800125 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800126
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700127 CaProfile m_caItem;
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700128 /**
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700129 * Used for CA redirection as specified in
130 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3-PROBE-Extensions#probe-extension-for-redirection
131 */
Zhiyi Zhang997669a2020-10-28 21:15:40 -0700132 optional<std::vector<std::shared_ptr<security::Certificate>>> m_redirection = nullopt;
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700133 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700134 * StatusUpdate Callback function
135 */
136 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhang74c61142020-10-07 21:00:49 -0700137 /**
138 * Name Assignment Functions
139 */
140 std::vector<std::unique_ptr<NameAssignmentFunc>> m_nameAssignmentFuncs;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800141};
142
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700143} // namespace ca
144
Zhiyi Zhang3002e6b2020-10-29 18:54:07 -0700145namespace requester {
146
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700147/**
148 * @brief Represents Client configuration
149 *
150 * For Client configuration format, please refer to:
151 * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample
152 */
Zhiyi Zhanga16b7582020-10-29 18:59:46 -0700153class ProfileStorage
Zhiyi Zhang684c67c2020-10-12 14:28:17 -0700154{
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700155public:
156 /**
157 * @throw std::runtime_error when config file cannot be correctly parsed.
158 */
159 void
160 load(const std::string& fileName);
161
162 /**
163 * @throw std::runtime_error when config file cannot be correctly parsed.
164 */
165 void
166 load(const JsonSection& configSection);
167
168 void
169 save(const std::string& fileName) const;
170
171 void
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700172 removeCaProfile(const Name& caName);
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700173
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700174 /**
175 * Be cautious. This will add a new trust anchor for requesters.
176 */
177 void
178 addCaProfile(const CaProfile& profile);
179
180 std::list<CaProfile> m_caItems;
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700181};
182
Zhiyi Zhang3002e6b2020-10-29 18:54:07 -0700183} // namespace requester
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700184} // namespace ndncert
185} // namespace ndn
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800186
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700187#endif // NDNCERT_CONFIGURATION_HPP