Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -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 | 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 | |
| 24 | #include "ca-config.hpp" |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 25 | #include "crypto-support/crypto-helper.hpp" |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 26 | #include "ca-storage.hpp" |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 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 | |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 61 | bool |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 62 | setProbeHandler(const ProbeHandler& handler); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 63 | |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 64 | bool |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 65 | setStatusUpdateCallback(const StatusUpdateCallback& onUpdateCallback); |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 66 | |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 67 | static JsonSection |
| 68 | jsonFromBlock(const Block& block); |
| 69 | |
| 70 | static Block |
| 71 | dataContentFromJson(const JsonSection& jsonSection); |
| 72 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 73 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 74 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 75 | onProbe(const Interest& request); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 76 | |
| 77 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 78 | onNew(const Interest& request); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 79 | |
| 80 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 81 | onChallenge(const Interest& request); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 82 | |
| 83 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 84 | onDownload(const Interest& request); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 85 | |
| 86 | void |
| 87 | onRegisterFailed(const std::string& reason); |
| 88 | |
| 89 | CertificateRequest |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 90 | getCertificateRequest(const Interest& request); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 91 | |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 92 | security::v2::Certificate |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 93 | issueCertificate(const CertificateRequest& certRequest); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 94 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 95 | void |
| 96 | registerPrefix(); |
| 97 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 98 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 99 | const JsonSection |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 100 | genProbeResponseJson(const Name& identifier, |
| 101 | const std::string& m_probe, |
| 102 | const JsonSection& parameterJson); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 103 | |
| 104 | const JsonSection |
| 105 | genProbeResponseJson(); |
| 106 | |
| 107 | const JsonSection |
| 108 | genNewResponseJson(const std::string& ecdhKey, const std::string& salt, |
| 109 | const CertificateRequest& request, const std::list<std::string>& challenges); |
| 110 | |
| 111 | const JsonSection |
| 112 | genChallengeResponseJson(const CertificateRequest& request); |
| 113 | |
Zhiyi Zhang | a63b737 | 2017-05-17 14:14:34 -0700 | [diff] [blame] | 114 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 115 | Face& m_face; |
| 116 | CaConfig m_config; |
| 117 | unique_ptr<CaStorage> m_storage; |
| 118 | security::v2::KeyChain& m_keyChain; |
| 119 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 120 | std::list<RegisteredPrefixHandle> m_registeredPrefixHandles; |
| 121 | std::list<InterestFilterHandle> m_interestFilterHandles; |
| 122 | |
| 123 | ECDHState m_ecdh; |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame^] | 124 | uint8_t m_aesKey[16] = {0}; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | } // namespace ndncert |
| 128 | } // namespace ndn |
| 129 | |
| 130 | #endif // NDNCERT_CA_MODULE_HPP |