Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 2 | /* |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2022, Regents of the University of California. |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDNS (Named Data Networking Domain Name Service). |
| 6 | * See AUTHORS.md for complete list of NDNS authors and contributors. |
| 7 | * |
| 8 | * NDNS is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef NDNS_DAEMON_RRSET_FACTORY_HPP |
| 21 | #define NDNS_DAEMON_RRSET_FACTORY_HPP |
| 22 | |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 23 | #include "rrset.hpp" |
| 24 | #include "logger.hpp" |
| 25 | #include "daemon/db-mgr.hpp" |
Yumin Xia | a484ba7 | 2016-11-10 20:40:12 -0800 | [diff] [blame] | 26 | #include "ndns-enum.hpp" |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 27 | |
| 28 | #include <ndn-cxx/link.hpp> |
| 29 | #include <ndn-cxx/security/key-chain.hpp> |
| 30 | |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 31 | #include <boost/filesystem/path.hpp> |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 32 | |
| 33 | namespace ndn { |
| 34 | namespace ndns { |
| 35 | |
| 36 | class RrsetFactory |
| 37 | { |
| 38 | public: |
| 39 | /** @brief Represents an error might be thrown during runtime |
| 40 | */ |
| 41 | class Error : public std::runtime_error |
| 42 | { |
| 43 | public: |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 44 | using std::runtime_error::runtime_error; |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | public: |
Yumin Xia | b87b9d9 | 2016-11-14 23:41:25 -0800 | [diff] [blame] | 48 | RrsetFactory(const boost::filesystem::path& dbFile, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 49 | const Name& zoneName, |
| 50 | KeyChain& keyChain, |
| 51 | const Name& inputDskCertName); |
| 52 | |
| 53 | void |
| 54 | checkZoneKey(); |
| 55 | |
| 56 | Rrset |
| 57 | generateNsRrset(const Name& label, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 58 | uint64_t version, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 59 | time::seconds ttl, |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame] | 60 | std::vector<Name> delegations); |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 61 | |
| 62 | Rrset |
| 63 | generateTxtRrset(const Name& label, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 64 | uint64_t version, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 65 | time::seconds ttl, |
| 66 | const std::vector<std::string>& contents); |
| 67 | |
| 68 | Rrset |
Yumin Xia | acd2133 | 2016-11-28 22:54:48 -0800 | [diff] [blame] | 69 | generateAuthRrset(const Name& label, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 70 | uint64_t version, |
Yumin Xia | acd2133 | 2016-11-28 22:54:48 -0800 | [diff] [blame] | 71 | time::seconds ttl); |
| 72 | |
| 73 | Rrset |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 74 | generateCertRrset(const Name& label, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 75 | uint64_t version, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 76 | time::seconds ttl, |
Alexander Afanasyev | 60514ec | 2020-06-03 14:18:53 -0400 | [diff] [blame] | 77 | const ndn::security::Certificate& cert); |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 78 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 79 | /** |
| 80 | * @brief DoE records are just txt records of all entries of a zone |
| 81 | * which means the any range showed in this record does not exist |
| 82 | */ |
| 83 | Rrset |
| 84 | generateDoeRrset(const Name& label, |
| 85 | uint64_t version, |
| 86 | time::seconds ttl, |
| 87 | const Name& lowerLabel, |
| 88 | const Name& upperLabel); |
| 89 | |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 90 | static std::vector<std::string> |
| 91 | wireDecodeTxt(const Block& wire); |
| 92 | |
| 93 | NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 94 | // only used for database-test-data unit test |
| 95 | void |
| 96 | onlyCheckZone(); |
| 97 | |
| 98 | private: |
| 99 | std::pair<Rrset, Name> |
| 100 | generateBaseRrset(const Name& label, |
| 101 | const name::Component& type, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 102 | uint64_t version, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 103 | const time::seconds& ttl); |
| 104 | |
| 105 | bool |
| 106 | matchCertificate(const Name& certName, const Name& identity); |
| 107 | |
| 108 | template<encoding::Tag TAG> |
Davide Pesavento | 9802612 | 2022-03-14 22:00:03 -0400 | [diff] [blame] | 109 | size_t |
| 110 | wireEncode(EncodingImpl<TAG>& encoder, const std::vector<Block>& rrs) const; |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 111 | |
Davide Pesavento | 9802612 | 2022-03-14 22:00:03 -0400 | [diff] [blame] | 112 | Block |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 113 | wireEncode(const std::vector<Block>& rrs) const; |
| 114 | |
| 115 | void |
| 116 | sign(Data& data); |
| 117 | |
Yumin Xia | 3c6b1fd | 2016-12-11 19:08:47 -0800 | [diff] [blame] | 118 | void |
Davide Pesavento | 9802612 | 2022-03-14 22:00:03 -0400 | [diff] [blame] | 119 | setContentType(Data& data, NdnsContentType contentType, const time::seconds& ttl); |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 120 | |
| 121 | private: |
| 122 | KeyChain& m_keyChain; |
| 123 | std::string m_dbFile; |
| 124 | Zone m_zone; |
| 125 | Name m_dskCertName; |
| 126 | Name m_dskName; |
| 127 | bool m_checked; |
| 128 | }; |
| 129 | |
| 130 | } // namespace ndns |
| 131 | } // namespace ndn |
| 132 | |
| 133 | #endif // NDNS_DAEMON_RRSET_FACTORY_HPP |