Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -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_MODULE_HPP |
| 22 | #define NDNCERT_CA_MODULE_HPP |
| 23 | |
| 24 | #include "ca-config.hpp" |
| 25 | #include "ca-storage.hpp" |
| 26 | #include "json-helper.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace ndncert { |
| 30 | |
| 31 | class CaModule : noncopyable |
| 32 | { |
| 33 | public: |
| 34 | /** |
| 35 | * @brief Error that can be thrown from CaModule |
| 36 | */ |
| 37 | class Error : public std::runtime_error |
| 38 | { |
| 39 | public: |
| 40 | using std::runtime_error::runtime_error; |
| 41 | }; |
| 42 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 43 | public: |
| 44 | CaModule(Face& face, security::v2::KeyChain& keyChain, const std::string& configPath, |
Zhiyi Zhang | 91c846b | 2017-04-12 14:16:31 -0700 | [diff] [blame] | 45 | const std::string& storageType = "ca-storage-sqlite3"); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 46 | |
| 47 | ~CaModule(); |
| 48 | |
| 49 | CaConfig& |
| 50 | getCaConf() |
| 51 | { |
| 52 | return m_config; |
| 53 | } |
| 54 | |
| 55 | const unique_ptr<CaStorage>& |
| 56 | getCaStorage() |
| 57 | { |
| 58 | return m_storage; |
| 59 | } |
| 60 | |
| 61 | void |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame^] | 62 | setProbeHandler(const Name caName, const ProbeHandler& handler); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 63 | |
Zhiyi Zhang | a63b737 | 2017-05-17 14:14:34 -0700 | [diff] [blame] | 64 | void |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame^] | 65 | setRecommendCaHandler(const Name caName, const RecommendCaHandler& handler); |
| 66 | |
| 67 | void |
| 68 | setRequestUpdateCallback(const Name caName, const RequestUpdateCallback& onUpateCallback); |
| 69 | |
Zhiyi Zhang | a63b737 | 2017-05-17 14:14:34 -0700 | [diff] [blame] | 70 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 71 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 72 | void |
| 73 | handleProbe(const Interest& request, const CaItem& caItem); |
| 74 | |
| 75 | void |
| 76 | handleNew(const Interest& request, const CaItem& caItem); |
| 77 | |
| 78 | void |
| 79 | handleSelect(const Interest& request, const CaItem& caItem); |
| 80 | |
| 81 | void |
| 82 | handleValidate(const Interest& request, const CaItem& caItem); |
| 83 | |
| 84 | void |
| 85 | handleStatus(const Interest& request, const CaItem& caItem); |
| 86 | |
| 87 | void |
| 88 | handleDownload(const Interest& request, const CaItem& caItem); |
| 89 | |
| 90 | void |
| 91 | onRegisterFailed(const std::string& reason); |
| 92 | |
| 93 | CertificateRequest |
| 94 | getCertificateRequest(const Interest& request, const Name& caName); |
| 95 | |
| 96 | void |
| 97 | issueCertificate(const CertificateRequest& certRequest, const CaItem& caItem); |
| 98 | |
| 99 | static JsonSection |
| 100 | jsonFromNameComponent(const Name& name, int pos); |
| 101 | |
| 102 | static Block |
| 103 | dataContentFromJson(const JsonSection& jsonSection); |
| 104 | |
Zhiyi Zhang | a63b737 | 2017-05-17 14:14:34 -0700 | [diff] [blame] | 105 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 106 | Face& m_face; |
| 107 | CaConfig m_config; |
| 108 | unique_ptr<CaStorage> m_storage; |
| 109 | security::v2::KeyChain& m_keyChain; |
| 110 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 111 | std::list<const RegisteredPrefixId*> m_registeredPrefixIds; |
| 112 | std::list<const InterestFilterId*> m_interestFilterIds; |
| 113 | }; |
| 114 | |
| 115 | } // namespace ndncert |
| 116 | } // namespace ndn |
| 117 | |
| 118 | #endif // NDNCERT_CA_MODULE_HPP |