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 | /* |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2018, 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 | |
| 23 | #include "common.hpp" |
| 24 | #include "rrset.hpp" |
| 25 | #include "logger.hpp" |
| 26 | #include "daemon/db-mgr.hpp" |
Yumin Xia | a484ba7 | 2016-11-10 20:40:12 -0800 | [diff] [blame] | 27 | #include "ndns-enum.hpp" |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 28 | |
| 29 | #include <ndn-cxx/link.hpp> |
| 30 | #include <ndn-cxx/security/key-chain.hpp> |
| 31 | |
| 32 | #include <vector> |
| 33 | #include <string> |
Yumin Xia | b87b9d9 | 2016-11-14 23:41:25 -0800 | [diff] [blame] | 34 | #include <boost/filesystem.hpp> |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 35 | |
| 36 | namespace ndn { |
| 37 | namespace ndns { |
| 38 | |
| 39 | class RrsetFactory |
| 40 | { |
| 41 | public: |
| 42 | /** @brief Represents an error might be thrown during runtime |
| 43 | */ |
| 44 | class Error : public std::runtime_error |
| 45 | { |
| 46 | public: |
| 47 | explicit |
| 48 | Error(const std::string& what) : std::runtime_error(what) |
| 49 | { |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | public: |
Yumin Xia | b87b9d9 | 2016-11-14 23:41:25 -0800 | [diff] [blame] | 54 | RrsetFactory(const boost::filesystem::path& dbFile, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 55 | const Name& zoneName, |
| 56 | KeyChain& keyChain, |
| 57 | const Name& inputDskCertName); |
| 58 | |
| 59 | void |
| 60 | checkZoneKey(); |
| 61 | |
| 62 | Rrset |
| 63 | generateNsRrset(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, |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 66 | const ndn::DelegationList& delegations); |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 67 | |
| 68 | Rrset |
| 69 | generateTxtRrset(const Name& label, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame^] | 70 | uint64_t version, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 71 | time::seconds ttl, |
| 72 | const std::vector<std::string>& contents); |
| 73 | |
| 74 | Rrset |
Yumin Xia | acd2133 | 2016-11-28 22:54:48 -0800 | [diff] [blame] | 75 | generateAuthRrset(const Name& label, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame^] | 76 | uint64_t version, |
Yumin Xia | acd2133 | 2016-11-28 22:54:48 -0800 | [diff] [blame] | 77 | time::seconds ttl); |
| 78 | |
| 79 | Rrset |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 80 | generateCertRrset(const Name& label, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame^] | 81 | uint64_t version, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 82 | time::seconds ttl, |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 83 | const ndn::security::v2::Certificate& cert); |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 84 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame^] | 85 | /** |
| 86 | * @brief DoE records are just txt records of all entries of a zone |
| 87 | * which means the any range showed in this record does not exist |
| 88 | */ |
| 89 | Rrset |
| 90 | generateDoeRrset(const Name& label, |
| 91 | uint64_t version, |
| 92 | time::seconds ttl, |
| 93 | const Name& lowerLabel, |
| 94 | const Name& upperLabel); |
| 95 | |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 96 | static std::vector<std::string> |
| 97 | wireDecodeTxt(const Block& wire); |
| 98 | |
| 99 | NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 100 | // only used for database-test-data unit test |
| 101 | void |
| 102 | onlyCheckZone(); |
| 103 | |
| 104 | private: |
| 105 | std::pair<Rrset, Name> |
| 106 | generateBaseRrset(const Name& label, |
| 107 | const name::Component& type, |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame^] | 108 | uint64_t version, |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 109 | const time::seconds& ttl); |
| 110 | |
| 111 | bool |
| 112 | matchCertificate(const Name& certName, const Name& identity); |
| 113 | |
| 114 | template<encoding::Tag TAG> |
| 115 | inline size_t |
| 116 | wireEncode(EncodingImpl<TAG>& block, const std::vector<Block>& rrs) const; |
| 117 | |
| 118 | const Block |
| 119 | wireEncode(const std::vector<Block>& rrs) const; |
| 120 | |
| 121 | void |
| 122 | sign(Data& data); |
| 123 | |
Yumin Xia | 3c6b1fd | 2016-12-11 19:08:47 -0800 | [diff] [blame] | 124 | void |
| 125 | setContentType(Data& data, NdnsContentType contentType, |
| 126 | const time::seconds& ttl); |
Yumin Xia | f853ad7 | 2016-11-03 21:14:07 -0700 | [diff] [blame] | 127 | |
| 128 | private: |
| 129 | KeyChain& m_keyChain; |
| 130 | std::string m_dbFile; |
| 131 | Zone m_zone; |
| 132 | Name m_dskCertName; |
| 133 | Name m_dskName; |
| 134 | bool m_checked; |
| 135 | }; |
| 136 | |
| 137 | } // namespace ndns |
| 138 | } // namespace ndn |
| 139 | |
| 140 | #endif // NDNS_DAEMON_RRSET_FACTORY_HPP |
| 141 | |