Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 1 | /* -*- 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 Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 24 | #include "certificate-request.hpp" |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 25 | #include "client-config.hpp" |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 26 | #include <ndn-cxx/security/v2/certificate.hpp> |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace ndncert { |
| 30 | |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame^] | 31 | /** |
| 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 | */ |
| 36 | using 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 | */ |
| 44 | using 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 | /** |
| 49 | * @brief The function would be invoked whenever the certificate request gets update |
| 50 | */ |
| 51 | using RequestUpdateCallback = function<void (const CertificateRequest&/*the latest request info*/)>; |
| 52 | |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 53 | class CaItem |
| 54 | { |
| 55 | public: |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 56 | // basic info |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 57 | Name m_caName; |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 58 | |
| 59 | // related CAs |
Zhiyi Zhang | b23c5bb | 2017-12-18 18:40:52 +0800 | [diff] [blame] | 60 | std::list<Name> m_relatedCaList; |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 61 | |
| 62 | // essential config |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 63 | time::seconds m_freshnessPeriod; |
| 64 | time::days m_validityPeriod; |
| 65 | std::list<std::string> m_supportedChallenges; |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 66 | |
| 67 | // optional parameters |
| 68 | std::string m_probe; |
| 69 | std::string m_targetedList; |
| 70 | std::string m_caInfo; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame^] | 71 | |
| 72 | // callbacks |
| 73 | ProbeHandler m_probeHandler; |
| 74 | RecommendCaHandler m_recommendCaHandler; |
| 75 | RequestUpdateCallback m_requestUpdateCallback; |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 76 | }; |
| 77 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 78 | /** |
| 79 | * @brief Represents a CA configuration instance |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 80 | * |
| 81 | * For CA configuration format, please refer to: |
| 82 | * https://github.com/named-data/ndncert/wiki/Ca-Configuration-Sample |
| 83 | * |
| 84 | * @note Changes made to CaConfig won't be written back to the config |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 85 | */ |
| 86 | class CaConfig |
| 87 | { |
| 88 | public: |
| 89 | /** |
| 90 | * @brief Error that can be thrown from CaConfig |
| 91 | */ |
| 92 | class Error : public std::runtime_error |
| 93 | { |
| 94 | public: |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 95 | using std::runtime_error::runtime_error; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | public: |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 99 | void |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 100 | load(const std::string& fileName); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 101 | |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 102 | private: |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 103 | void |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 104 | parse(const JsonSection& configJson); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 105 | |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 106 | std::list<std::string> |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 107 | parseChallengeList(const JsonSection& configSection); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 108 | |
Zhiyi Zhang | b23c5bb | 2017-12-18 18:40:52 +0800 | [diff] [blame] | 109 | std::list<Name> |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 110 | parseRelatedCaList(const JsonSection& section); |
| 111 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 112 | public: |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 113 | std::list<CaItem> m_caItems; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace ndncert |
| 117 | } // namespace ndn |
| 118 | |
| 119 | #endif // NDNCERT_CA_CONFIG_HPP |