blob: b80558c5b5491dec19464809499ba2c37b44c454 [file] [log] [blame]
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
4 *
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 Zhang06d6ae92017-03-08 14:59:45 -080031class CaItem
32{
33public:
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070034 // basic info
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080035 Name m_caName;
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070036
37 // related CAs
Zhiyi Zhangb23c5bb2017-12-18 18:40:52 +080038 std::list<Name> m_relatedCaList;
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070039
40 // essential config
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080041 time::seconds m_freshnessPeriod;
42 time::days m_validityPeriod;
43 std::list<std::string> m_supportedChallenges;
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070044
45 // optional parameters
46 std::string m_probe;
47 std::string m_targetedList;
48 std::string m_caInfo;
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080049};
50
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080051/**
52 * @brief Represents a CA configuration instance
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070053 *
54 * For CA configuration format, please refer to:
55 * https://github.com/named-data/ndncert/wiki/Ca-Configuration-Sample
56 *
57 * @note Changes made to CaConfig won't be written back to the config
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080058 */
59class CaConfig
60{
61public:
62 /**
63 * @brief Error that can be thrown from CaConfig
64 */
65 class Error : public std::runtime_error
66 {
67 public:
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080068 using std::runtime_error::runtime_error;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080069 };
70
71public:
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080072 void
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080073 load(const std::string& fileName);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080074
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080075private:
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080076 void
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070077 parse(const JsonSection& configJson);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080078
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080079 std::list<std::string>
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080080 parseChallengeList(const JsonSection& configSection);
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080081
Zhiyi Zhangb23c5bb2017-12-18 18:40:52 +080082 std::list<Name>
Zhiyi Zhangad6cf932017-10-26 16:19:15 -070083 parseRelatedCaList(const JsonSection& section);
84
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080085public:
Zhiyi Zhang06d6ae92017-03-08 14:59:45 -080086 std::list<CaItem> m_caItems;
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080087};
88
89} // namespace ndncert
90} // namespace ndn
91
92#endif // NDNCERT_CA_CONFIG_HPP