blob: e624e345aad2cebe1591e79aef5136f3f7668a3c [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 Zhang5ebeb692017-03-10 14:13:01 -080024#include "certificate-request.hpp"
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070025#include "client-config.hpp"
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070026#include <ndn-cxx/security/v2/certificate.hpp>
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080027
28namespace ndn {
29namespace ndncert {
30
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080031/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070032 * @brief The name assignment function provided by the CA operator to generate available
33 * namecomponents.
Zhiyi Zhangf6c5d272020-09-28 10:17:32 -070034 * The function does not guarantee that all the returned names are available. Therefore the
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070035 * CA should further check the availability of each returned name and remove unavailable results.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080036 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070037 * @p vector, input, a list of parameter key-value pair used for name assignment.
38 * @return a vector containing the possible namespaces derived from the parameters.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080039 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070040using NameAssignmentFunc = function<std::vector<std::string>(const std::vector<std::tuple<std::string, std::string>>)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080041
42/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070043 * @brief The function would be invoked whenever the certificate request status is updated.
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080044 * The callback is used to notice the CA application or CA command line tool. The callback is
45 * fired whenever a request instance is created, challenge status is updated, and when certificate
46 * is issued.
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070047 *
48 * @p CertificateRequest, input, the state of the certificate request whose status is updated.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080049 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070050using StatusUpdateCallback = function<void(const CertificateRequest&)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080051
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080052/**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070053 * @brief CA's configuration on NDNCERT.
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070054 * For CA configuration format, please refer to:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070055 * https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#213-ca-profile
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070056 *
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070057 * The format of CA configuration in JSON
58 * {
59 * "ca-prefix": "",
60 * "ca-info": "",
61 * "max-validity-period": "",
62 * "probe-parameters":
63 * [
64 * {"probe-parameter-key": ""},
65 * {"probe-parameter-key": ""}
66 * ]
67 * "supported-challenges":
68 * [
69 * {"challenge": ""},
70 * {"challenge": ""}
71 * ]
72 * }
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080073 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070074class CaConfig {
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080075public:
76 /**
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070077 * Load CA configuration from the file.
78 *
79 * @param fileName, the configuration file name.
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070080 * @throw std::runtime_error when config file does not exist or the configuration
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070081 * in the file cannot be parsed correctly.
Zhiyi Zhangb2f8b942020-09-28 10:37:02 -070082 * @throw std::runtime_error when the ca-prefix attribute in JSON text is empty.
83 * @throw std::runtime_error when the challenge is not specified or is not supported.
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080084 */
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080085 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080086 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080087
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080088private:
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080089 void
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070090 parse(const JsonSection& configJson);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080091
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070092 void
93 parseProbeParameters(const JsonSection& section);
94
95 void
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080096 parseChallengeList(const JsonSection& configSection);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080097
98public:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070099 /**
100 * CA Name prefix (without /CA suffix).
101 */
102 Name m_caPrefix;
103 /**
104 * CA Information.
105 */
106 std::string m_caInfo;
107 /**
108 * A list of parameter-keys for PROBE.
109 */
110 std::list<std::string> m_probeParameterKeys;
111 /**
112 * Maximum allowed validity period of the certificate being requested.
113 * The value is in the unit of second.
114 */
115 time::seconds m_maxValidityPeriod;
116 /**
117 * A list of supported challenges.
118 */
119 std::list<std::string> m_supportedChallenges;
120 /**
121 * NameAssignmentFunc Callback function
122 */
123 NameAssignmentFunc m_nameAssignmentFunc;
124 /**
125 * StatusUpdate Callback function
126 */
127 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800128};
129
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700130} // namespace ndncert
131} // namespace ndn
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800132
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700133#endif // NDNCERT_CA_CONFIG_HPP