blob: fbdfb24b0f723bd3d81315adb5cbc34d146dce44 [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
21#ifndef NDNCERT_CA_CONFIG_HPP
22#define NDNCERT_CA_CONFIG_HPP
23
Zhiyi Zhang48f23782020-09-28 12:11:24 -070024#include <ndn-cxx/security/v2/certificate.hpp>
25
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080026#include "certificate-request.hpp"
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070027#include "client-config.hpp"
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080028
29namespace ndn {
30namespace ndncert {
31
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080032/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070033 * @brief The name assignment function provided by the CA operator to generate available
34 * namecomponents.
Zhiyi Zhangf6c5d272020-09-28 10:17:32 -070035 * The function does not guarantee that all the returned names are available. Therefore the
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070036 * CA should further check the availability of each returned name and remove unavailable results.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080037 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070038 * @p vector, input, a list of parameter key-value pair used for name assignment.
39 * @return a vector containing the possible namespaces derived from the parameters.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080040 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070041using NameAssignmentFunc = function<std::vector<std::string>(const std::vector<std::tuple<std::string, std::string>>)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080042
43/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070044 * @brief The function would be invoked whenever the certificate request status is updated.
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080045 * The callback is used to notice the CA application or CA command line tool. The callback is
46 * fired whenever a request instance is created, challenge status is updated, and when certificate
47 * is issued.
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070048 *
49 * @p CertificateRequest, input, the state of the certificate request whose status is updated.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080050 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070051using StatusUpdateCallback = function<void(const CertificateRequest&)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080052
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080053/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070054 * @brief CA's configuration on NDNCERT.
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070055 * For CA configuration format, please refer to:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070056 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070057 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070058 * The format of CA configuration in JSON
59 * {
60 * "ca-prefix": "",
61 * "ca-info": "",
62 * "max-validity-period": "",
Zhiyi Zhang48f23782020-09-28 12:11:24 -070063 * "max-suffix-length": "",
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070064 * "probe-parameters":
65 * [
66 * {"probe-parameter-key": ""},
67 * {"probe-parameter-key": ""}
68 * ]
69 * "supported-challenges":
70 * [
71 * {"challenge": ""},
72 * {"challenge": ""}
73 * ]
74 * }
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080075 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070076class CaConfig {
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080077public:
78 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070079 * Load CA configuration from the file.
80 *
81 * @param fileName, the configuration file name.
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070082 * @throw std::runtime_error when config file does not exist or the configuration
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070083 * in the file cannot be parsed correctly.
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070084 * @throw std::runtime_error when the ca-prefix attribute in JSON text is empty.
85 * @throw std::runtime_error when the challenge is not specified or is not supported.
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080086 */
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080087 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080088 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080089
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080090private:
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080091 void
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070092 parse(const JsonSection& configJson);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080093
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070094 void
95 parseProbeParameters(const JsonSection& section);
96
97 void
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080098 parseChallengeList(const JsonSection& configSection);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080099
100public:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700101 /**
102 * CA Name prefix (without /CA suffix).
103 */
104 Name m_caPrefix;
105 /**
106 * CA Information.
107 */
108 std::string m_caInfo;
109 /**
110 * A list of parameter-keys for PROBE.
111 */
112 std::list<std::string> m_probeParameterKeys;
113 /**
114 * Maximum allowed validity period of the certificate being requested.
115 * The value is in the unit of second.
116 */
117 time::seconds m_maxValidityPeriod;
118 /**
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700119 * Maximum allowed suffix length of requested name.
120 * E.g., When its value is 2, at most 2 name components can be assigned after m_caPrefix.
121 */
122 size_t m_maxSuffixLength;
123 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700124 * A list of supported challenges.
125 */
126 std::list<std::string> m_supportedChallenges;
127 /**
128 * NameAssignmentFunc Callback function
129 */
130 NameAssignmentFunc m_nameAssignmentFunc;
131 /**
132 * StatusUpdate Callback function
133 */
134 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800135};
136
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700137} // namespace ndncert
138} // namespace ndn
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800139
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700140#endif // NDNCERT_CA_CONFIG_HPP