| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2017-2018, Regents of the University of California. |
| * |
| * This file is part of ndncert, a certificate management system based on NDN. |
| * |
| * ndncert is free software: you can redistribute it and/or modify it under the terms |
| * of the GNU General Public License as published by the Free Software Foundation, either |
| * version 3 of the License, or (at your option) any later version. |
| * |
| * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY |
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| * |
| * You should have received copies of the GNU General Public License along with |
| * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| * |
| * See AUTHORS.md for complete list of ndncert authors and contributors. |
| */ |
| |
| #ifndef NDNCERT_CA_CONFIG_HPP |
| #define NDNCERT_CA_CONFIG_HPP |
| |
| #include "certificate-request.hpp" |
| #include "client-config.hpp" |
| #include <ndn-cxx/security/v2/certificate.hpp> |
| |
| namespace ndn { |
| namespace ndncert { |
| |
| /** |
| * @brief The function should be able to convert a probe info string to an identity name |
| * |
| * The function should throw exceptions when there is an unexpected input. |
| */ |
| using ProbeHandler = function<std::string/*identity name*/ (const std::string&/*requester input*/)>; |
| |
| /** |
| * @brief The function should recommend a CA plus an identity name from the given list |
| * based on LIST additional info |
| * |
| * The function should throw exceptions when there is an unexpected input. |
| */ |
| using RecommendCaHandler = function<std::tuple<Name/*CA name*/, std::string/*identity*/> |
| (const std::string&/*requester input*/, |
| const std::list<Name>&/*related CA list*/)>; |
| |
| /** |
| * @brief The function would be invoked whenever the certificate request status gets update |
| * |
| * The callback is used to notice the CA application or CA command line tool. The callback is |
| * fired whenever a request instance is created, challenge status is updated, and when certificate |
| * is issued. |
| */ |
| using StatusUpdateCallback = function<void (const CertificateRequest&/*the latest request info*/)>; |
| |
| class CaItem |
| { |
| public: |
| // basic info |
| Name m_caName; |
| |
| // related CAs |
| std::list<Name> m_relatedCaList; |
| |
| // essential config |
| time::seconds m_freshnessPeriod; |
| time::days m_validityPeriod; |
| std::list<std::string> m_supportedChallenges; |
| |
| // optional parameters |
| std::string m_probe; |
| std::string m_targetedList; |
| std::string m_caInfo; |
| |
| // callbacks |
| ProbeHandler m_probeHandler; |
| RecommendCaHandler m_recommendCaHandler; |
| StatusUpdateCallback m_statusUpdateCallback; |
| }; |
| |
| /** |
| * @brief Represents a CA configuration instance |
| * |
| * For CA configuration format, please refer to: |
| * https://github.com/named-data/ndncert/wiki/Ca-Configuration-Sample |
| * |
| * @note Changes made to CaConfig won't be written back to the config |
| */ |
| class CaConfig |
| { |
| public: |
| /** |
| * @brief Error that can be thrown from CaConfig |
| */ |
| class Error : public std::runtime_error |
| { |
| public: |
| using std::runtime_error::runtime_error; |
| }; |
| |
| public: |
| void |
| load(const std::string& fileName); |
| |
| private: |
| void |
| parse(const JsonSection& configJson); |
| |
| std::list<std::string> |
| parseChallengeList(const JsonSection& configSection); |
| |
| std::list<Name> |
| parseRelatedCaList(const JsonSection& section); |
| |
| public: |
| std::list<CaItem> m_caItems; |
| }; |
| |
| } // namespace ndncert |
| } // namespace ndn |
| |
| #endif // NDNCERT_CA_CONFIG_HPP |