Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2019, Regents of the University of California. |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -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_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 | */ |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 36 | using ProbeHandler = function<std::string/*identity name*/ (const JsonSection& json/*requester input*/)>; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 37 | |
| 38 | /** |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 39 | * @brief The function would be invoked whenever the certificate request status gets update |
| 40 | * |
| 41 | * The callback is used to notice the CA application or CA command line tool. The callback is |
| 42 | * fired whenever a request instance is created, challenge status is updated, and when certificate |
| 43 | * is issued. |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 44 | */ |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 45 | using StatusUpdateCallback = function<void (const CertificateRequest&/*the latest request info*/)>; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 46 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 47 | /** |
| 48 | * @brief Represents a CA configuration instance |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 49 | * |
| 50 | * For CA configuration format, please refer to: |
| 51 | * https://github.com/named-data/ndncert/wiki/Ca-Configuration-Sample |
| 52 | * |
| 53 | * @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] | 54 | */ |
| 55 | class CaConfig |
| 56 | { |
| 57 | public: |
| 58 | /** |
| 59 | * @brief Error that can be thrown from CaConfig |
| 60 | */ |
| 61 | class Error : public std::runtime_error |
| 62 | { |
| 63 | public: |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 64 | using std::runtime_error::runtime_error; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | public: |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 68 | /** |
| 69 | * @throw CaConfig::Error when config file does not exist |
| 70 | * @throw CaConfig::Error when the JSON text in the file cannot be parsed correctly |
| 71 | * @throw CaConfig::Error when the ca-prefix attribute in JSON text is empty |
| 72 | * @throw CaConfig::Error when the challenge is not specified or is not supported |
| 73 | */ |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 74 | void |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 75 | load(const std::string& fileName); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 76 | |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 77 | private: |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 78 | void |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 79 | parse(const JsonSection& configJson); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 80 | |
Zhiyi Zhang | 06d6ae9 | 2017-03-08 14:59:45 -0800 | [diff] [blame] | 81 | std::list<std::string> |
Zhiyi Zhang | 5ebeb69 | 2017-03-10 14:13:01 -0800 | [diff] [blame] | 82 | parseChallengeList(const JsonSection& configSection); |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 83 | |
| 84 | public: |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 85 | // basic info |
| 86 | Name m_caName; |
| 87 | |
| 88 | // essential config |
| 89 | time::seconds m_freshnessPeriod; |
| 90 | time::days m_validityPeriod; |
| 91 | std::list<std::string> m_supportedChallenges; |
| 92 | |
| 93 | // optional parameters |
| 94 | std::string m_probe; |
| 95 | std::string m_caInfo; |
| 96 | |
| 97 | // callbacks |
| 98 | ProbeHandler m_probeHandler; |
| 99 | StatusUpdateCallback m_statusUpdateCallback; |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } // namespace ndncert |
| 103 | } // namespace ndn |
| 104 | |
| 105 | #endif // NDNCERT_CA_CONFIG_HPP |