Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 7838cfd | 2020-06-03 14:16:43 -0400 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 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_CLIENT_CONFIG_HPP |
| 22 | #define NDNCERT_CLIENT_CONFIG_HPP |
| 23 | |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 24 | #include "certificate-request.hpp" |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 25 | #include <ndn-cxx/security/v2/certificate.hpp> |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | |
Zhiyi Zhang | e4ee822 | 2017-12-08 22:43:04 -0800 | [diff] [blame] | 30 | /** |
| 31 | * @brief The configuration for a trusted CA from a requester's perspective |
| 32 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 33 | class ClientCaItem { |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 34 | public: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 35 | /** |
| 36 | * CA Name prefix (without /CA suffix). |
| 37 | */ |
| 38 | Name m_caPrefix; |
| 39 | /** |
| 40 | * CA Information. |
| 41 | */ |
| 42 | std::string m_caInfo; |
| 43 | /** |
| 44 | * A list of parameter-keys for PROBE. |
| 45 | */ |
| 46 | std::list<std::string> m_probeParameterKeys; |
| 47 | /** |
| 48 | * Maximum allowed validity period of the certificate being requested. |
| 49 | * The value is in the unit of second. |
| 50 | */ |
| 51 | time::seconds m_maxValidityPeriod; |
| 52 | /** |
| 53 | * CA's certificate. |
| 54 | */ |
| 55 | security::v2::Certificate m_anchor; |
| 56 | |
| 57 | //=======old |
| 58 | |
Zhiyi Zhang | e4ee822 | 2017-12-08 22:43:04 -0800 | [diff] [blame] | 59 | // The identity name of the CA. Extracted from config field "ca-prefix" |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 60 | Name m_caName; |
Zhiyi Zhang | e4ee822 | 2017-12-08 22:43:04 -0800 | [diff] [blame] | 61 | |
Zhiyi Zhang | e4ee822 | 2017-12-08 22:43:04 -0800 | [diff] [blame] | 62 | // An instruction for requesters to use _PROBE. Extracted from config field "probe" |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 63 | std::string m_probe; // "email::uid::name" |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
Zhiyi Zhang | e4ee822 | 2017-12-08 22:43:04 -0800 | [diff] [blame] | 66 | /** |
| 67 | * @brief Represents Client configuration |
| 68 | * |
| 69 | * For Client configuration format, please refer to: |
| 70 | * https://github.com/named-data/ndncert/wiki/Client-Configuration-Sample |
| 71 | */ |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 72 | class ClientConfig { |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 73 | public: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 74 | class Error : public std::runtime_error { |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 75 | public: |
| 76 | using std::runtime_error::runtime_error; |
| 77 | }; |
| 78 | |
| 79 | public: |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 80 | /** |
| 81 | * @throw ClientConfig::Error when config file does not exist |
| 82 | * @throw ClientConfig::Error when the JSON text in the file cannot be parsed correctly |
| 83 | * @throw ClientConfig::Error when the ca-prefix attribute in JSON text is empty |
| 84 | * @throw ClientConfig::Error when the certificate in JSON text cannot be parsed correctly |
| 85 | */ |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 86 | void |
| 87 | load(const std::string& fileName); |
| 88 | |
| 89 | void |
Zhiyi Zhang | e4ee822 | 2017-12-08 22:43:04 -0800 | [diff] [blame] | 90 | load(const JsonSection& configSection); |
| 91 | |
| 92 | void |
Zhiyi Zhang | caab546 | 2019-10-18 13:41:02 -0700 | [diff] [blame] | 93 | save(const std::string& fileName); |
| 94 | |
| 95 | void |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 96 | addNewCaItem(const ClientCaItem& item); |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 97 | |
| 98 | void |
| 99 | removeCaItem(const Name& caName); |
| 100 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 101 | static ClientCaItem |
| 102 | extractCaItem(const JsonSection& configSection); |
| 103 | |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 104 | public: |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 105 | std::list<ClientCaItem> m_caItems; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 106 | std::string m_localNdncertAnchor; |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 109 | } // namespace ndncert |
| 110 | } // namespace ndn |
Zhiyi Zhang | 32dbb9f | 2017-02-16 15:15:10 -0800 | [diff] [blame] | 111 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 112 | #endif // NDNCERT_CLIENT_CONFIG_HPP |