Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 3 | * Copyright (c) 2017-2022, Regents of the University of California. |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -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_MODULE_HPP |
| 22 | #define NDNCERT_CA_MODULE_HPP |
| 23 | |
Zhiyi Zhang | 3f20f95 | 2020-11-19 19:26:43 -0800 | [diff] [blame] | 24 | #include "detail/ca-configuration.hpp" |
Zhiyi Zhang | dc25ddf | 2020-10-20 14:28:55 -0700 | [diff] [blame] | 25 | #include "detail/crypto-helpers.hpp" |
Zhiyi Zhang | 062be6d | 2020-10-14 17:13:43 -0700 | [diff] [blame] | 26 | #include "detail/ca-storage.hpp" |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 27 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 28 | #include <ndn-cxx/face.hpp> |
| 29 | #include <ndn-cxx/security/key-chain.hpp> |
| 30 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 31 | namespace ndncert::ca { |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 32 | |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 33 | /** |
| 34 | * @brief The function would be invoked whenever the certificate request status is updated. |
| 35 | * The callback is used to notice the CA application or CA command line tool. The callback is |
| 36 | * fired whenever a request instance is created, challenge status is updated, and when certificate |
| 37 | * is issued. |
| 38 | * |
| 39 | * @param RequestState The state of the certificate request whose status is updated. |
| 40 | */ |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 41 | using StatusUpdateCallback = std::function<void(const RequestState&)>; |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 42 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 43 | class CaModule : boost::noncopyable |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 44 | { |
| 45 | public: |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 46 | CaModule(ndn::Face& face, ndn::KeyChain& keyChain, const std::string& configPath, |
Zhiyi Zhang | 91c846b | 2017-04-12 14:16:31 -0700 | [diff] [blame] | 47 | const std::string& storageType = "ca-storage-sqlite3"); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 48 | |
| 49 | ~CaModule(); |
| 50 | |
| 51 | CaConfig& |
| 52 | getCaConf() |
| 53 | { |
| 54 | return m_config; |
| 55 | } |
| 56 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 57 | const std::unique_ptr<CaStorage>& |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 58 | getCaStorage() const |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 59 | { |
| 60 | return m_storage; |
| 61 | } |
| 62 | |
Zhiyi Zhang | f6c5d27 | 2020-09-28 10:17:32 -0700 | [diff] [blame] | 63 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 64 | setStatusUpdateCallback(const StatusUpdateCallback& onUpdateCallback); |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 65 | |
Zhiyi Zhang | 696cd04 | 2020-10-07 21:27:36 -0700 | [diff] [blame] | 66 | Data |
| 67 | getCaProfileData(); |
Zhiyi Zhang | fc1678a | 2020-05-12 16:52:14 -0700 | [diff] [blame] | 68 | |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 69 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | 696cd04 | 2020-10-07 21:27:36 -0700 | [diff] [blame] | 70 | void |
| 71 | onCaProfileDiscovery(const Interest& request); |
swa770 | 20643ac | 2020-03-26 02:24:45 -0700 | [diff] [blame] | 72 | |
| 73 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 74 | onProbe(const Interest& request); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 75 | |
| 76 | void |
Zhiyi Zhang | 01e91a3 | 2020-09-29 12:10:00 -0700 | [diff] [blame] | 77 | onNewRenewRevoke(const Interest& request, RequestType requestType); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 78 | |
| 79 | void |
tylerliu | 4a00aad | 2020-09-26 02:03:17 -0700 | [diff] [blame] | 80 | onChallenge(const Interest& request); |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame] | 81 | |
| 82 | void |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 83 | onRegisterFailed(const std::string& reason); |
| 84 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 85 | std::unique_ptr<RequestState> |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 86 | getCertificateRequest(const Interest& request); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 87 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 88 | Certificate |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 89 | issueCertificate(const RequestState& requestState); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 90 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 91 | void |
| 92 | registerPrefix(); |
| 93 | |
Zhiyi Zhang | aafc55e | 2020-09-28 17:54:48 -0700 | [diff] [blame] | 94 | Data |
| 95 | generateErrorDataPacket(const Name& name, ErrorCode error, const std::string& errorInfo); |
| 96 | |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 97 | NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 98 | ndn::Face& m_face; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 99 | CaConfig m_config; |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 100 | std::unique_ptr<CaStorage> m_storage; |
| 101 | ndn::KeyChain& m_keyChain; |
Zhiyi Zhang | a2c39f7 | 2020-10-06 16:45:55 -0700 | [diff] [blame] | 102 | uint8_t m_requestIdGenKey[32]; |
Zhiyi Zhang | 696cd04 | 2020-10-07 21:27:36 -0700 | [diff] [blame] | 103 | std::unique_ptr<Data> m_profileData; |
tylerliu | 1f480be | 2020-11-10 13:02:53 -0800 | [diff] [blame] | 104 | /** |
| 105 | * StatusUpdate Callback function |
| 106 | */ |
| 107 | StatusUpdateCallback m_statusUpdateCallback; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 108 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 109 | std::list<ndn::RegisteredPrefixHandle> m_registeredPrefixHandles; |
| 110 | std::list<ndn::InterestFilterHandle> m_interestFilterHandles; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 113 | } // namespace ndncert::ca |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 114 | |
| 115 | #endif // NDNCERT_CA_MODULE_HPP |