blob: 72dd78faca32b9114518d21932af32f677e8aebf [file] [log] [blame]
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang916ba2d2018-02-01 18:16:27 -08003 * Copyright (c) 2017-2018, Regents of the University of California.
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -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_CLIENT_CONFIG_HPP
22#define NDNCERT_CLIENT_CONFIG_HPP
23
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080024#include "certificate-request.hpp"
25#include <ndn-cxx/security/v2/certificate.hpp>
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080026
27namespace ndn {
28namespace ndncert {
29
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080030/**
31 * @brief The configuration for a trusted CA from a requester's perspective
32 */
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080033class ClientCaItem
34{
35public:
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080036 // The identity name of the CA. Extracted from config field "ca-prefix"
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080037 Name m_caName;
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080038
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080039 // A brief introduction to the CA. Extracted from config field "ca-info"
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080040 std::string m_caInfo;
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080041 // An instruction for requesters to use _PROBE. Extracted from config field "probe"
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080042 std::string m_probe;
Zhiyi Zhang916ba2d2018-02-01 18:16:27 -080043 // Whether support list function
44 bool m_isListEnabled;
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080045 // An instruction for requesters to get a recommended CA. Extracted from config field "target-list"
46 std::string m_targetedList;
47
48 // CA's certificate
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080049 security::v2::Certificate m_anchor;
50};
51
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080052/**
53 * @brief Represents Client configuration
54 *
55 * For Client configuration format, please refer to:
56 * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample
57 */
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080058class ClientConfig
59{
60public:
61 class Error : public std::runtime_error
62 {
63 public:
64 using std::runtime_error::runtime_error;
65 };
66
67public:
68 void
69 load(const std::string& fileName);
70
71 void
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080072 load(const JsonSection& configSection);
73
74 void
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080075 addNewCaItem(const ClientCaItem& item);
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080076
77 void
78 removeCaItem(const Name& caName);
79
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080080 static ClientCaItem
81 extractCaItem(const JsonSection& configSection);
82
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080083public:
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080084 std::list<ClientCaItem> m_caItems;
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080085 std::string m_localNdncertAnchor;
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080086};
87
88} // namespace ndncert
89} // namespace ndn
90
91#endif // NDNCERT_CLIENT_CONFIG_HPP