blob: 0195c48dc462d4e2da71173aba6781c182fab2be [file] [log] [blame]
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -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 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"
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070025<<<<<<< HEAD
Alexander Afanasyev7838cfd2020-06-03 14:16:43 -040026#include <ndn-cxx/security/certificate.hpp>
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070027=======
28
29#include <ndn-cxx/security/v2/certificate.hpp>
30>>>>>>> Update CaConfig and ClientCaItem. Add INFO packet encoding and decoding.
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080031
32namespace ndn {
33namespace ndncert {
34
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080035/**
36 * @brief The configuration for a trusted CA from a requester's perspective
37 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070038class ClientCaItem {
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080039public:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070040 /**
41 * CA Name prefix (without /CA suffix).
42 */
43 Name m_caPrefix;
44 /**
45 * CA Information.
46 */
47 std::string m_caInfo;
48 /**
49 * A list of parameter-keys for PROBE.
50 */
51 std::list<std::string> m_probeParameterKeys;
52 /**
53 * Maximum allowed validity period of the certificate being requested.
54 * The value is in the unit of second.
55 */
56 time::seconds m_maxValidityPeriod;
57 /**
58 * CA's certificate.
59 */
60 security::v2::Certificate m_anchor;
61
62 //=======old
63
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080064 // The identity name of the CA. Extracted from config field "ca-prefix"
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080065 Name m_caName;
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080066
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080067 // An instruction for requesters to use _PROBE. Extracted from config field "probe"
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070068 std::string m_probe; // "email::uid::name"
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -080069};
70
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080071/**
72 * @brief Represents Client configuration
73 *
74 * For Client configuration format, please refer to:
75 * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample
76 */
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070077class ClientConfig {
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080078public:
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070079 class Error : public std::runtime_error {
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080080 public:
81 using std::runtime_error::runtime_error;
82 };
83
84public:
Zhiyi Zhang8da54d62019-11-21 00:03:05 -080085 /**
86 * @throw ClientConfig::Error when config file does not exist
87 * @throw ClientConfig::Error when the JSON text in the file cannot be parsed correctly
88 * @throw ClientConfig::Error when the ca-prefix attribute in JSON text is empty
89 * @throw ClientConfig::Error when the certificate in JSON text cannot be parsed correctly
90 */
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -080091 void
92 load(const std::string& fileName);
93
94 void
Zhiyi Zhange4ee8222017-12-08 22:43:04 -080095 load(const JsonSection& configSection);
96
97 void
Zhiyi Zhangcaab5462019-10-18 13:41:02 -070098 save(const std::string& fileName);
99
100 void
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -0800101 addNewCaItem(const ClientCaItem& item);
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -0800102
103 void
104 removeCaItem(const Name& caName);
105
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800106 static ClientCaItem
107 extractCaItem(const JsonSection& configSection);
108
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -0800109public:
Zhiyi Zhang5ebeb692017-03-10 14:13:01 -0800110 std::list<ClientCaItem> m_caItems;
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800111 std::string m_localNdncertAnchor;
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -0800112};
113
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700114} // namespace ndncert
115} // namespace ndn
Zhiyi Zhang32dbb9f2017-02-16 15:15:10 -0800116
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700117#endif // NDNCERT_CLIENT_CONFIG_HPP