blob: 59b3b09d789a1f027356dd774c7c95f39fc92275 [file] [log] [blame]
Yumin Xiaf853ad72016-11-03 21:14:07 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Yumin Xiaacd21332016-11-28 22:54:48 -08003 * Copyright (c) 2014-2017, Regents of the University of California.
Yumin Xiaf853ad72016-11-03 21:14:07 -07004 *
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 Xiaa484ba72016-11-10 20:40:12 -080027#include "ndns-enum.hpp"
Yumin Xiaf853ad72016-11-03 21:14:07 -070028
29#include <ndn-cxx/link.hpp>
30#include <ndn-cxx/security/key-chain.hpp>
31
32#include <vector>
33#include <string>
Yumin Xiab87b9d92016-11-14 23:41:25 -080034#include <boost/filesystem.hpp>
Yumin Xiaf853ad72016-11-03 21:14:07 -070035
36namespace ndn {
37namespace ndns {
38
39class RrsetFactory
40{
41public:
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
53public:
Yumin Xiab87b9d92016-11-14 23:41:25 -080054 RrsetFactory(const boost::filesystem::path& dbFile,
Yumin Xiaf853ad72016-11-03 21:14:07 -070055 const Name& zoneName,
56 KeyChain& keyChain,
57 const Name& inputDskCertName);
58
59 void
60 checkZoneKey();
61
62 Rrset
63 generateNsRrset(const Name& label,
Yumin Xiaf853ad72016-11-03 21:14:07 -070064 const uint64_t version,
65 time::seconds ttl,
Yumin Xia2c509c22017-02-09 14:37:36 -080066 const ndn::DelegationList& delegations);
Yumin Xiaf853ad72016-11-03 21:14:07 -070067
68 Rrset
69 generateTxtRrset(const Name& label,
Yumin Xiaf853ad72016-11-03 21:14:07 -070070 const uint64_t version,
71 time::seconds ttl,
72 const std::vector<std::string>& contents);
73
74 Rrset
Yumin Xiaacd21332016-11-28 22:54:48 -080075 generateAuthRrset(const Name& label,
Yumin Xiaacd21332016-11-28 22:54:48 -080076 const uint64_t version,
77 time::seconds ttl);
78
79 Rrset
Yumin Xiaf853ad72016-11-03 21:14:07 -070080 generateCertRrset(const Name& label,
Yumin Xiaf853ad72016-11-03 21:14:07 -070081 const uint64_t version,
82 time::seconds ttl,
Yumin Xia2c509c22017-02-09 14:37:36 -080083 const ndn::security::v2::Certificate& cert);
Yumin Xiaf853ad72016-11-03 21:14:07 -070084
85 static std::vector<std::string>
86 wireDecodeTxt(const Block& wire);
87
88NDNS_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
89 // only used for database-test-data unit test
90 void
91 onlyCheckZone();
92
93private:
94 std::pair<Rrset, Name>
95 generateBaseRrset(const Name& label,
96 const name::Component& type,
97 const uint64_t version,
98 const time::seconds& ttl);
99
100 bool
101 matchCertificate(const Name& certName, const Name& identity);
102
103 template<encoding::Tag TAG>
104 inline size_t
105 wireEncode(EncodingImpl<TAG>& block, const std::vector<Block>& rrs) const;
106
107 const Block
108 wireEncode(const std::vector<Block>& rrs) const;
109
110 void
111 sign(Data& data);
112
Yumin Xia3c6b1fd2016-12-11 19:08:47 -0800113 void
114 setContentType(Data& data, NdnsContentType contentType,
115 const time::seconds& ttl);
Yumin Xiaf853ad72016-11-03 21:14:07 -0700116
117private:
118 KeyChain& m_keyChain;
119 std::string m_dbFile;
120 Zone m_zone;
121 Name m_dskCertName;
122 Name m_dskName;
123 bool m_checked;
124};
125
126} // namespace ndns
127} // namespace ndn
128
129#endif // NDNS_DAEMON_RRSET_FACTORY_HPP
130