blob: a0e66ae511fdae23649686d2d694613abaffa397 [file] [log] [blame]
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -08003 * Copyright (c) 2017-2018, 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 Zhangdaf2fd72017-01-19 11:31:35 -080026#include <ndn-cxx/security/v2/certificate.hpp>
27
28namespace ndn {
29namespace ndncert {
30
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080031/**
32 * @brief The function should be able to convert a probe info string to an identity name
33 *
34 * The function should throw exceptions when there is an unexpected input.
35 */
36using ProbeHandler = function<std::string/*identity name*/ (const std::string&/*requester input*/)>;
37
38/**
39 * @brief The function should recommend a CA plus an identity name from the given list
40 * based on LIST additional info
41 *
42 * The function should throw exceptions when there is an unexpected input.
43 */
44using RecommendCaHandler = function<std::tuple<Name/*CA name*/, std::string/*identity*/>
45 (const std::string&/*requester input*/,
46 const std::list<Name>&/*related CA list*/)>;
47
48/**
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080049 * @brief The function would be invoked whenever the certificate request status gets update
50 *
51 * The callback is used to notice the CA application or CA command line tool. The callback is
52 * fired whenever a request instance is created, challenge status is updated, and when certificate
53 * is issued.
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080054 */
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080055using StatusUpdateCallback = function<void (const CertificateRequest&/*the latest request info*/)>;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080056
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080057class CaItem
58{
59public:
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070060 // basic info
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080061 Name m_caName;
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070062
63 // related CAs
Zhiyi Zhangb23c5bb2017-12-18 18:40:52 +080064 std::list<Name> m_relatedCaList;
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070065
66 // essential config
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080067 time::seconds m_freshnessPeriod;
68 time::days m_validityPeriod;
69 std::list<std::string> m_supportedChallenges;
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070070
71 // optional parameters
72 std::string m_probe;
73 std::string m_targetedList;
74 std::string m_caInfo;
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080075
76 // callbacks
77 ProbeHandler m_probeHandler;
78 RecommendCaHandler m_recommendCaHandler;
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080079 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080080};
81
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080082/**
83 * @brief Represents a CA configuration instance
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070084 *
85 * For CA configuration format, please refer to:
86 * https://github.com/named-data/ndncert/wiki/Ca-Configuration-Sample
87 *
88 * @note Changes made to CaConfig won't be written back to the config
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080089 */
90class CaConfig
91{
92public:
93 /**
94 * @brief Error that can be thrown from CaConfig
95 */
96 class Error : public std::runtime_error
97 {
98 public:
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080099 using std::runtime_error::runtime_error;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800100 };
101
102public:
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800103 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -0800104 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800105
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -0800106private:
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800107 void
Zhiyi Zhangad6cf932017-10-26 16:19:15 -0700108 parse(const JsonSection& configJson);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800109
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -0800110 std::list<std::string>
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -0800111 parseChallengeList(const JsonSection& configSection);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800112
Zhiyi Zhangb23c5bb2017-12-18 18:40:52 +0800113 std::list<Name>
Zhiyi Zhangad6cf932017-10-26 16:19:15 -0700114 parseRelatedCaList(const JsonSection& section);
115
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800116public:
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -0800117 std::list<CaItem> m_caItems;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -0800118};
119
120} // namespace ndncert
121} // namespace ndn
122
123#endif // NDNCERT_CA_CONFIG_HPP