Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [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. |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [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 | |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 20 | #include "mgmt/management-tool.hpp" |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 21 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 22 | #include "daemon/rrset-factory.hpp" |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 23 | #include "util/cert-helper.hpp" |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 24 | #include "ndns-enum.hpp" |
| 25 | #include "ndns-label.hpp" |
| 26 | #include "ndns-tlv.hpp" |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 27 | |
| 28 | #include "boost-test.hpp" |
| 29 | #include "key-chain-fixture.hpp" |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 30 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 31 | #include <boost/algorithm/string/replace.hpp> |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 32 | #include <boost/range/adaptors.hpp> |
Davide Pesavento | 28229df | 2020-01-04 15:11:25 -0500 | [diff] [blame] | 33 | #include <boost/test/tools/output_test_stream.hpp> |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 34 | |
Davide Pesavento | 28229df | 2020-01-04 15:11:25 -0500 | [diff] [blame] | 35 | #include <ndn-cxx/security/transform.hpp> |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 36 | #include <ndn-cxx/util/io.hpp> |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 37 | #include <ndn-cxx/util/random.hpp> |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 38 | #include <ndn-cxx/util/regex.hpp> |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 39 | |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 40 | #include <iostream> |
| 41 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 42 | namespace ndn { |
| 43 | namespace ndns { |
| 44 | namespace tests { |
| 45 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 46 | using boost::test_tools::output_test_stream; |
| 47 | |
| 48 | const auto TEST_DATABASE = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "management_tool.db"; |
| 49 | const auto TEST_CERTDIR = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "management_tool_certs"; |
| 50 | const Name FAKE_ROOT("/fake-root/123456789"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 51 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 52 | /** |
| 53 | * @brief Recursive copy a directory using Boost Filesystem |
| 54 | * |
| 55 | * Based on from http://stackoverflow.com/q/8593608/2150331 |
| 56 | */ |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 57 | static void |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 58 | copyDir(const boost::filesystem::path& source, const boost::filesystem::path& destination) |
| 59 | { |
| 60 | namespace fs = boost::filesystem; |
| 61 | |
| 62 | fs::create_directory(destination); |
| 63 | for (fs::directory_iterator file(source); file != fs::directory_iterator(); ++file) { |
| 64 | fs::path current(file->path()); |
| 65 | if (is_directory(current)) { |
| 66 | copyDir(current, destination / current.filename()); |
| 67 | } |
| 68 | else { |
Eric Newberry | 9edaf26 | 2018-06-07 23:44:57 -0700 | [diff] [blame] | 69 | copy_file(current, destination / current.filename()); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | class TestHome : boost::noncopyable |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 75 | { |
| 76 | public: |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 77 | TestHome() |
| 78 | { |
| 79 | if (std::getenv("HOME")) |
| 80 | m_origHome = std::getenv("HOME"); |
| 81 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 82 | auto p = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "tests" / "unit" / "mgmt"; |
| 83 | setenv("HOME", p.c_str(), 1); |
| 84 | boost::filesystem::remove_all(p); |
| 85 | boost::filesystem::create_directories(p); |
| 86 | copyDir("tests/unit/mgmt/.ndn", p / ".ndn"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | ~TestHome() |
| 90 | { |
| 91 | if (!m_origHome.empty()) |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 92 | setenv("HOME", m_origHome.data(), 1); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 93 | else |
| 94 | unsetenv("HOME"); |
| 95 | } |
| 96 | |
| 97 | protected: |
| 98 | std::string m_origHome; |
| 99 | }; |
| 100 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 101 | class ManagementToolFixture : public TestHome, public KeyChainFixture |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 102 | { |
| 103 | public: |
| 104 | class Error : public std::runtime_error |
| 105 | { |
| 106 | public: |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 107 | using std::runtime_error::runtime_error; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | class PreviousStateCleaner |
| 111 | { |
| 112 | public: |
| 113 | PreviousStateCleaner() |
| 114 | { |
| 115 | boost::filesystem::remove(TEST_DATABASE); |
| 116 | boost::filesystem::remove_all(TEST_CERTDIR); |
| 117 | } |
| 118 | }; |
| 119 | |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 120 | ManagementToolFixture() |
Alexander Afanasyev | fde570c | 2016-12-19 16:02:55 -0800 | [diff] [blame] | 121 | : m_tool(TEST_DATABASE.string().c_str(), m_keyChain) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 122 | , m_dbMgr(TEST_DATABASE.string().c_str()) |
| 123 | { |
| 124 | boost::filesystem::create_directory(TEST_CERTDIR); |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 125 | Identity root = m_keyChain.createIdentity("NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 126 | Key ksk = root.getDefaultKey(); |
| 127 | m_keyChain.deleteCertificate(ksk, ksk.getDefaultCertificate().getName()); |
| 128 | Certificate kskCert = CertHelper::createCertificate(m_keyChain, ksk, ksk, "CERT"); |
| 129 | m_keyChain.addCertificate(ksk, kskCert); |
| 130 | rootKsk = kskCert.getName(); |
| 131 | |
| 132 | Key dsk = m_keyChain.createKey(root); |
| 133 | // replace rootDsk's default cert with ksk-signing cert |
| 134 | m_keyChain.deleteCertificate(dsk, dsk.getDefaultCertificate().getName()); |
| 135 | Certificate dskCert = CertHelper::createCertificate(m_keyChain, dsk, ksk, "CERT"); |
| 136 | m_keyChain.addCertificate(dsk, dskCert); |
| 137 | rootDsk = dskCert.getName(); |
| 138 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 139 | Identity other = m_keyChain.createIdentity("/ndns-test/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 140 | Key otherKskKey = other.getDefaultKey(); |
| 141 | m_keyChain.deleteCertificate(otherKskKey, otherKskKey.getDefaultCertificate().getName()); |
| 142 | Certificate otherKskCert = CertHelper::createCertificate(m_keyChain, otherKskKey, otherKskKey, "CERT"); |
| 143 | m_keyChain.addCertificate(otherKskKey, otherKskCert); |
| 144 | otherKsk = otherKskCert.getName(); |
| 145 | |
| 146 | // replace rootDsk's default cert with ksk-signing cert |
| 147 | Key otherDskKey = m_keyChain.createKey(other); |
| 148 | m_keyChain.deleteCertificate(otherDskKey, otherDskKey.getDefaultCertificate().getName()); |
| 149 | Certificate otherDskCert = CertHelper::createCertificate(m_keyChain, otherDskKey, otherKskKey, "CERT"); |
| 150 | m_keyChain.addCertificate(otherDskKey, otherDskCert); |
| 151 | otherDsk = otherDskCert.getName(); |
| 152 | |
| 153 | Certificate rootDkeyCert = CertHelper::createCertificate(m_keyChain, otherDskKey, otherKskKey, "CERT"); |
| 154 | m_keyChain.addCertificate(otherDskKey, rootDkeyCert); |
| 155 | rootDkey = rootDkeyCert.getName(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 158 | std::vector<Certificate> |
| 159 | getCerts(const Name& zoneName) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 160 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 161 | Zone zone(zoneName); |
| 162 | std::vector<Certificate> certs; |
| 163 | std::map<std::string, Block> zoneInfo = m_dbMgr.getZoneInfo(zone); |
| 164 | // ksk are always the first key |
| 165 | certs.push_back(Certificate(zoneInfo["ksk"])); |
| 166 | certs.push_back(Certificate(zoneInfo["dsk"])); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 167 | return certs; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 170 | Rrset |
| 171 | findRrSet(Zone& zone, const Name& label, const name::Component& type) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 172 | { |
| 173 | Rrset rrset(&zone); |
| 174 | rrset.setLabel(label); |
| 175 | rrset.setType(type); |
| 176 | |
| 177 | if (!m_dbMgr.find(rrset)) |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 178 | NDN_THROW(Error("Record not found")); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 179 | else |
| 180 | return rrset; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 181 | } |
| 182 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 183 | Name |
| 184 | getLabel(const Zone& zone, const Name& fullName) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 185 | { |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 186 | size_t zoneNameSize = zone.getName().size(); |
| 187 | return fullName.getSubName(zoneNameSize + 1, fullName.size() - zoneNameSize - 3); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 188 | } |
| 189 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 190 | Certificate |
| 191 | findCertFromIdentity(const Name& identityName, const Name& certName) |
| 192 | { |
| 193 | Certificate rtn; |
| 194 | Identity identity = CertHelper::getIdentity(m_keyChain, identityName); |
| 195 | for (const auto& key : identity.getKeys()) { |
| 196 | for (const auto& cert : key.getCertificates()) { |
| 197 | if (cert.getName() == certName) { |
| 198 | rtn = cert; |
| 199 | return rtn; |
| 200 | } |
| 201 | } |
| 202 | } |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 203 | NDN_THROW(Error("Certificate not found in keyChain")); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | Certificate |
| 207 | findCertFromDb(Zone& zone, const Name& fullName) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 208 | { |
| 209 | Rrset rrset = findRrSet(zone, getLabel(zone, fullName), label::CERT_RR_TYPE); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 210 | Certificate cert; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 211 | cert.wireDecode(rrset.getData()); |
| 212 | return cert; |
| 213 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 214 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 215 | Certificate |
| 216 | findDkeyFromDb(const Name& zoneName) |
| 217 | { |
| 218 | Zone zone(zoneName); |
| 219 | std::map<std::string, Block> zoneInfo = m_dbMgr.getZoneInfo(zone); |
| 220 | return Certificate(zoneInfo["dkey"]); |
| 221 | } |
| 222 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 223 | Response |
| 224 | findResponse(Zone& zone, const Name& label, const name::Component& type) |
| 225 | { |
| 226 | Rrset rrset = findRrSet(zone, label, type); |
| 227 | Data data(rrset.getData()); |
| 228 | Response resp; |
Yumin Xia | 6343c5b | 2016-10-20 15:45:50 -0700 | [diff] [blame] | 229 | resp.fromData(zone.getName(), data); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 230 | return resp; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | public: |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 234 | PreviousStateCleaner cleaner; // must be first variable |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 235 | ndns::ManagementTool m_tool; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 236 | ndns::DbMgr m_dbMgr; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 237 | |
| 238 | // Names of pre-created certificates |
| 239 | // Uncomment and run InitPreconfiguredKeys test case and then update names in the |
| 240 | // constructor. |
| 241 | Name rootKsk; |
| 242 | Name rootDsk; |
| 243 | Name otherKsk; |
| 244 | Name otherDsk; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 245 | Name rootDkey; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 246 | }; |
| 247 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 248 | BOOST_FIXTURE_TEST_SUITE(ManagementTool, ManagementToolFixture) |
| 249 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 250 | // BOOST_FIXTURE_TEST_CASE(InitPreconfiguredKeys, ManagementToolFixture) |
| 251 | // { |
| 252 | // using time::seconds; |
| 253 | |
| 254 | // auto generateCerts = [this] (const Name& zone, const Name& parentCert = Name()) -> Name { |
| 255 | // // to re-generate certificates, uncomment and then update rootKsk/rootDsk names |
| 256 | // Name kskName = m_keyChain.generateRsaKeyPair(zone, true); |
| 257 | // auto kskCert = m_keyChain |
| 258 | // .prepareUnsignedIdentityCertificate(kskName, zone, time::fromUnixTimestamp(seconds(0)), |
| 259 | // time::fromUnixTimestamp(seconds(2147483648)), {}); |
| 260 | // if (parentCert.empty()) { |
| 261 | // m_keyChain.selfSign(*kskCert); |
| 262 | // } |
| 263 | // else { |
| 264 | // m_keyChain.sign(*kskCert, parentCert); |
| 265 | // } |
| 266 | // m_keyChain.addCertificate(*kskCert); |
| 267 | |
| 268 | // Name dskName = m_keyChain.generateRsaKeyPair(zone, false); |
| 269 | // auto dskCert = m_keyChain |
| 270 | // .prepareUnsignedIdentityCertificate(dskName, zone, time::fromUnixTimestamp(seconds(0)), |
| 271 | // time::fromUnixTimestamp(seconds(2147483648)), {}); |
| 272 | // m_keyChain.sign(*dskCert, kskCert->getName()); |
| 273 | // m_keyChain.addCertificate(*dskCert); |
| 274 | |
| 275 | // return dskCert->getName(); |
| 276 | // }; |
| 277 | |
| 278 | // Name rootDsk = generateCerts(ROOT_ZONE); |
| 279 | // generateCerts("/ndns-test", rootDsk); |
| 280 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 281 | // copyDir(UNIT_TESTS_TMPDIR "/tests/unit/mgmt/.ndn", "/tmp/.ndn"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 282 | // std::cout << "Manually copy contents of /tmp/.ndn into tests/unit/mgmt/.ndn" << std::endl; |
| 283 | // } |
| 284 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 285 | BOOST_AUTO_TEST_CASE(SqliteLabelOrder) |
| 286 | { |
| 287 | // the correctness of our DoE design rely on the ordering of SQLite |
| 288 | // this unit test make sure that our label::isSmallerInLabelOrder |
| 289 | // is the same as the ordering of BLOB in SQLite |
| 290 | |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 291 | auto genRandomString = [] (size_t length) { |
| 292 | static const std::string charset = "0123456789" |
| 293 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 294 | "abcdefghijklmnopqrstuvwxyz"; |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 295 | std::uniform_int_distribution<size_t> dist(0, charset.size() - 1); |
| 296 | |
| 297 | std::string str(length, 0); |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 298 | std::generate_n(str.begin(), length, |
| 299 | [&] { return charset[dist(random::getRandomNumberEngine())]; }); |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 300 | return str; |
| 301 | }; |
| 302 | |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 303 | auto genRandomLabel = [&] { |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 304 | std::uniform_int_distribution<size_t> numberOfLabelsDist(1, 5); |
| 305 | std::uniform_int_distribution<size_t> labelSizeDist(1, 10); |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 306 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 307 | Name nm; |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 308 | size_t length = numberOfLabelsDist(random::getRandomNumberEngine()); |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 309 | for (size_t i = 0; i < length; i++) { |
Davide Pesavento | 948c50c | 2020-12-26 21:30:45 -0500 | [diff] [blame] | 310 | nm.append(genRandomString(labelSizeDist(random::getRandomNumberEngine()))); |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 311 | } |
| 312 | return nm; |
| 313 | }; |
| 314 | |
| 315 | const size_t NGENERATED_LABELS = 10; |
| 316 | |
| 317 | Zone zone = m_tool.createZone("/net/ndnsim", "/net"); |
| 318 | RrsetFactory rrsetFactory(TEST_DATABASE.string(), zone.getName(), |
| 319 | m_keyChain, DEFAULT_CERT); |
| 320 | rrsetFactory.checkZoneKey(); |
| 321 | std::vector<Rrset> rrsets; |
| 322 | std::vector<Name> names; |
| 323 | for (size_t i = 0; i < NGENERATED_LABELS; i++) { |
| 324 | Name randomLabel = genRandomLabel(); |
| 325 | Rrset randomTxt = rrsetFactory.generateTxtRrset(randomLabel, |
| 326 | VERSION_USE_UNIX_TIMESTAMP, |
| 327 | DEFAULT_CACHE_TTL, |
| 328 | {}); |
| 329 | |
| 330 | rrsets.push_back(randomTxt); |
| 331 | m_dbMgr.insert(randomTxt); |
| 332 | names.push_back(randomLabel); |
| 333 | } |
| 334 | |
| 335 | std::sort(rrsets.begin(), rrsets.end()); |
| 336 | |
| 337 | using boost::adaptors::filtered; |
| 338 | using boost::adaptors::transformed; |
| 339 | |
| 340 | std::vector<Rrset> rrsetsFromDb = m_dbMgr.findRrsets(zone); |
| 341 | auto fromDbFiltered = rrsetsFromDb | filtered([] (const Rrset& rrset) { |
| 342 | return rrset.getType() == label::TXT_RR_TYPE; |
| 343 | }); |
| 344 | |
| 345 | auto extractLabel = [] (const Rrset& rr) { |
| 346 | return rr.getLabel(); |
| 347 | }; |
| 348 | auto expected = rrsets | transformed(extractLabel); |
| 349 | auto actual = fromDbFiltered | transformed(extractLabel); |
| 350 | |
| 351 | BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), |
| 352 | actual.begin(), actual.end()); |
| 353 | } |
| 354 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 355 | BOOST_AUTO_TEST_CASE(CreateDeleteRootFixture) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 356 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 357 | // creating root_zone need a rootDkey |
| 358 | BOOST_CHECK_THROW(m_tool.createZone(ROOT_ZONE, ROOT_ZONE, |
| 359 | time::seconds(4600), |
| 360 | time::seconds(4600), |
| 361 | rootKsk, rootDsk), ndns::ManagementTool::Error); |
| 362 | |
| 363 | m_tool.createZone(ROOT_ZONE, ROOT_ZONE, |
| 364 | time::seconds(4600), |
| 365 | time::seconds(4600), |
| 366 | rootKsk, rootDsk, rootDkey); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 367 | |
| 368 | Zone zone(ROOT_ZONE); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 369 | Name zoneIdentityName = Name(ROOT_ZONE).append("NDNS"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 370 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 371 | BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, rootDsk)); |
| 372 | BOOST_CHECK_EQUAL(findCertFromDb(zone, rootDsk).getName(), rootDsk); |
| 373 | BOOST_CHECK_EQUAL(findCertFromDb(zone, rootKsk).getName(), rootKsk); |
| 374 | BOOST_CHECK_EQUAL(findDkeyFromDb(ROOT_ZONE).getName(), rootDkey); |
| 375 | |
| 376 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootDsk).getName(), rootDsk); |
| 377 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, rootKsk).getName(), rootKsk); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 378 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 379 | BOOST_CHECK_NO_THROW(m_tool.deleteZone(ROOT_ZONE)); |
| 380 | BOOST_CHECK_EQUAL(m_dbMgr.find(zone), false); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 381 | } |
| 382 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 383 | BOOST_AUTO_TEST_CASE(CreateDeleteChildFixture) |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 384 | { |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 385 | Name parentZoneName("/ndns-test"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 386 | Name zoneName = Name(parentZoneName).append("child-zone"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 387 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 388 | Zone zone1(zoneName); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 389 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 390 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone1), false); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 391 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 392 | // will generate keys automatically |
| 393 | m_tool.createZone(zoneName, parentZoneName); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 394 | BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 395 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 396 | std::vector<Certificate>&& certs = getCerts(zoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 397 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 398 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 399 | const Name& ksk = certs[0].getName(); |
| 400 | const Name& dsk = certs[1].getName(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 401 | |
| 402 | Zone zone(zoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 403 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 404 | BOOST_REQUIRE_NO_THROW(findCertFromDb(zone, dsk)); |
| 405 | BOOST_CHECK_EQUAL(findCertFromDb(zone, dsk).getName(), dsk); |
| 406 | BOOST_CHECK_EQUAL(findCertFromDb(zone, ksk).getName(), ksk); |
| 407 | |
| 408 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, dsk), findCertFromDb(zone, dsk)); |
| 409 | BOOST_CHECK_EQUAL(findCertFromIdentity(zoneIdentityName, ksk), findCertFromDb(zone, ksk)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 410 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 411 | BOOST_CHECK_NO_THROW(m_tool.deleteZone(zoneName)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 412 | |
| 413 | BOOST_CHECK_THROW(m_tool.deleteZone(zoneName), ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 414 | BOOST_CHECK_THROW(m_tool.deleteZone("/non/existing/zone"), ndns::ManagementTool::Error); |
| 415 | } |
| 416 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 417 | BOOST_AUTO_TEST_CASE(CreateZoneWithFixture) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 418 | { |
| 419 | Name parentZoneName("/ndns-test"); |
| 420 | Name zoneName = Name(parentZoneName).append("child-zone"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 421 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 422 | |
| 423 | m_tool.createZone(zoneName, parentZoneName, time::seconds(4200), time::days(30)); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 424 | BOOST_CHECK_EQUAL(CertHelper::doesIdentityExist(m_keyChain, zoneIdentityName), true); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 425 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 426 | std::vector<Certificate>&& certs = getCerts(zoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 427 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 428 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 429 | const Name& dsk = certs[1].getName(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 430 | |
| 431 | // Check zone ttl |
| 432 | Zone zone(zoneName); |
| 433 | BOOST_REQUIRE_EQUAL(m_dbMgr.find(zone), true); |
| 434 | BOOST_CHECK_EQUAL(zone.getTtl(), time::seconds(4200)); |
| 435 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 436 | // check dkey name |
| 437 | Name dkeyName = Name(parentZoneName).append("NDNS").append(zoneName.getSubName(parentZoneName.size())); |
| 438 | Certificate dkey = findDkeyFromDb(zoneName); |
| 439 | BOOST_CHECK(dkeyName.isPrefixOf(dkey.getName())); |
| 440 | |
| 441 | // TODO: check signing hierarchy |
| 442 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 443 | // Check dsk rrset ttl |
| 444 | Rrset rrset; |
| 445 | BOOST_REQUIRE_NO_THROW(rrset = findRrSet(zone, getLabel(zone, dsk), label::CERT_RR_TYPE)); |
| 446 | BOOST_CHECK_EQUAL(rrset.getTtl(), time::seconds(4200)); |
| 447 | |
| 448 | // Check certificate freshnessPeriod and validity |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 449 | Certificate cert = CertHelper::getCertificate(m_keyChain, zoneIdentityName, dsk); |
Davide Pesavento | 38fd398 | 2022-04-18 22:22:02 -0400 | [diff] [blame] | 450 | auto [beg, end] = cert.getValidityPeriod().getPeriod(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 451 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 452 | BOOST_REQUIRE_NO_THROW(cert = findCertFromDb(zone, dsk)); |
| 453 | BOOST_CHECK_EQUAL(cert.getFreshnessPeriod(), time::seconds(4200)); |
| 454 | BOOST_CHECK_EQUAL(end - beg, time::days(30)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 455 | m_tool.deleteZone(zoneName); |
| 456 | } |
| 457 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 458 | BOOST_AUTO_TEST_CASE(ZoneCreatePreconditions) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 459 | { |
| 460 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net")); |
| 461 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net"), ndns::ManagementTool::Error); |
| 462 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 463 | std::vector<Certificate>&& certs = getCerts("/net/ndnsim"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 464 | BOOST_REQUIRE_EQUAL(certs.size(), 2); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 465 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 466 | const Name& ksk = certs[0].getName(); |
| 467 | const Name& dsk = certs[1].getName(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 468 | |
| 469 | m_tool.deleteZone("/net/ndnsim"); |
| 470 | // identity will still exist after the zone is deleted |
| 471 | |
| 472 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net/ndnsim"), ndns::ManagementTool::Error); |
| 473 | |
| 474 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/com"), ndns::ManagementTool::Error); |
| 475 | |
| 476 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 477 | time::seconds(1), time::days(1), ksk, dsk)); |
| 478 | BOOST_CHECK_EQUAL(getCerts("/net/ndnsim").size(), 2); |
| 479 | m_tool.deleteZone("/net/ndnsim"); |
| 480 | |
| 481 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 482 | time::seconds(1), time::days(1), Name(), dsk)); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 483 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 484 | m_tool.deleteZone("/net/ndnsim"); |
| 485 | |
| 486 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/", |
| 487 | time::seconds(1), time::days(1), ksk, Name())); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 488 | m_tool.deleteZone("/net/ndnsim"); |
| 489 | |
| 490 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
| 491 | time::seconds(1), time::days(1), "/com/ndnsim"), |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 492 | ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 493 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 494 | Identity id = m_keyChain.createIdentity("/net/ndnsim/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 495 | Certificate cert = id.getDefaultKey().getDefaultCertificate(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 496 | BOOST_CHECK_NO_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 497 | time::seconds(1), time::days(1), cert.getName())); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 498 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 499 | id = m_keyChain.createIdentity("/com/ndnsim/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 500 | cert = id.getDefaultKey().getDefaultCertificate(); |
| 501 | |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 502 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 503 | time::seconds(1), time::days(1), cert.getName()), |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 504 | ndns::ManagementTool::Error); |
| 505 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 506 | id = m_keyChain.createIdentity("/net/ndnsim/www/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 507 | cert = id.getDefaultKey().getDefaultCertificate(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 508 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 509 | time::seconds(1), time::days(1), cert.getName()), |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 510 | ndns::ManagementTool::Error); |
| 511 | |
Davide Pesavento | bdd88c1 | 2020-11-26 00:35:08 -0500 | [diff] [blame] | 512 | id = m_keyChain.createIdentity("/net/ndnsim/NDNS"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 513 | cert = id.getDefaultKey().getDefaultCertificate(); |
| 514 | m_keyChain.deleteCertificate(id.getDefaultKey(), cert.getName()); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 515 | BOOST_CHECK_THROW(m_tool.createZone("/net/ndnsim", "/net", |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 516 | time::seconds(1), time::days(1), cert.getName()), |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 517 | ndns::ManagementTool::Error); |
| 518 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 519 | // for root zone special case (requires a valid DKEY to be specified) |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 520 | BOOST_CHECK_THROW(m_tool.createZone("/", "/"), ndns::ManagementTool::Error); |
| 521 | |
| 522 | BOOST_CHECK_NO_THROW(m_tool.createZone("/", "/", time::seconds(1), time::days(1), |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 523 | DEFAULT_CERT, DEFAULT_CERT, rootDkey)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | class OutputTester |
| 527 | { |
| 528 | public: |
| 529 | OutputTester() |
| 530 | : savedBuf(std::clog.rdbuf()) |
| 531 | { |
| 532 | std::cout.rdbuf(buffer.rdbuf()); |
| 533 | } |
| 534 | |
| 535 | ~OutputTester() |
| 536 | { |
| 537 | std::cout.rdbuf(savedBuf); |
| 538 | } |
| 539 | |
| 540 | public: |
| 541 | std::stringstream buffer; |
| 542 | std::streambuf* savedBuf; |
| 543 | }; |
| 544 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 545 | // BOOST_AUTO_TEST_CASE(ExportCertificate) |
| 546 | // { |
| 547 | // std::string outputFile = TEST_CERTDIR.string() + "/ss.cert"; |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 548 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 549 | // BOOST_REQUIRE_THROW(m_tool.exportCertificate("/random/name", outputFile), |
| 550 | // ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 551 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 552 | // BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), false); |
| 553 | // // doesn't check the zone, export from KeyChain directly |
| 554 | // BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile)); |
| 555 | // BOOST_REQUIRE_EQUAL(boost::filesystem::exists(outputFile), true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 556 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 557 | // std::string dskValue = |
| 558 | // "Bv0C3Ac3CAluZG5zLXRlc3QIA0tFWQgRZHNrLTE0MTY5NzQwMDY2NTkIB0lELUNF\n" |
| 559 | // "UlQICf0AAAFJ6jt6DhQDGAECFf0BYTCCAV0wIhgPMTk3MDAxMDEwMDAwMDBaGA8y\n" |
| 560 | // "MDM4MDExOTAzMTQwOFowEzARBgNVBCkTCi9uZG5zLXRlc3QwggEgMA0GCSqGSIb3\n" |
| 561 | // "DQEBAQUAA4IBDQAwggEIAoIBAQDIFUL7Fz8mmxxIT8l3FtWm+CuH9+iQ0Uj/a30P\n" |
| 562 | // "mKe4gWvtxzhb4vIngYbXGv2iUzHswdqYlTVeDdW6eOFKMvyY5p5eVtLqDFZ7EEK0\n" |
| 563 | // "0rpTh648HjCSz+Awgp2nbiYAAVvhP6YF+NxGBH412uPI7kLY6ozypsNmYP+K4SYT\n" |
| 564 | // "oY9ee4xLSjqzXfLMyP1h8OHcN/aNmccRJlyYblCmCDbZPnzu3ttHHwdrYQLeFvb0\n" |
| 565 | // "B5grCAQoPHwkfxkEnzQBA/fbUdvKNdayEkuibPLlIlmj2cBtk5iVk8JCSibP3Zlz\n" |
| 566 | // "36Sks1DAO+1EvCRnjoH5vYmkpMUBFue+6A40IQG4brM2CiIRAgERFjMbAQEcLgcs\n" |
| 567 | // "CAluZG5zLXRlc3QIA0tFWQgRa3NrLTE0MTY5NzQwMDY1NzcIB0lELUNFUlQX/QEA\n" |
| 568 | // "GP2bQqp/7rfb8tShwDbXihWrPojwEFqlfwLibK9aM1RxwpHVqbtRsPYmuWc87LaU\n" |
| 569 | // "OztPOZinHGL80ypFC+wYadVGnE8MPdTkUYUik7mbHDEsYWADoyGMVhoZv+OTJ/5m\n" |
| 570 | // "MUh/kR1FMiqtZcIQtLB3cdCeGlZBl9wm2SvhMKVUym3RsQO46RpnmsEQcCfWMBZg\n" |
| 571 | // "u5U6mhYIpiQPZ/sYyZ9zXstwsIfaF1p0V+1dW5y99PZJXIegVKhkGGU0ibjYoJy7\n" |
| 572 | // "6uUjqBBDX8KMdt6n/Zy1/pGG1eOchMyV0JZ8+MJxWuiTEh5PJeYMFHTV/BVp8aPy\n" |
| 573 | // "8UNqhMpjAZwW6pdvOZADVg==\n"; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 574 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 575 | // { |
| 576 | // std::ifstream ifs(outputFile.c_str()); |
| 577 | // std::string actualValue((std::istreambuf_iterator<char>(ifs)), |
| 578 | // std::istreambuf_iterator<char>()); |
| 579 | // BOOST_CHECK_EQUAL(actualValue, dskValue); |
| 580 | // } |
| 581 | // boost::filesystem::remove(outputFile); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 582 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 583 | // // doesn't check the zone, export from KeyChain directly |
| 584 | // BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherKsk, outputFile)); |
| 585 | // boost::filesystem::remove(outputFile); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 586 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 587 | // Name zoneName("/ndns-test"); |
| 588 | // m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(4200), time::days(30), |
| 589 | // otherKsk, otherDsk); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 590 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 591 | // m_keyChain.deleteCertificate(otherKsk); |
| 592 | // m_keyChain.deleteCertificate(otherDsk); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 593 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 594 | // // retrieve cert from the zone |
| 595 | // BOOST_CHECK_NO_THROW(m_tool.exportCertificate(otherDsk, outputFile)); |
| 596 | // { |
| 597 | // std::ifstream ifs(outputFile.c_str()); |
| 598 | // std::string actualValue((std::istreambuf_iterator<char>(ifs)), |
| 599 | // std::istreambuf_iterator<char>()); |
| 600 | // BOOST_CHECK_EQUAL(actualValue, dskValue); |
| 601 | // } |
| 602 | // boost::filesystem::remove(outputFile); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 603 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 604 | // BOOST_REQUIRE_THROW(m_tool.exportCertificate(otherKsk, outputFile), |
| 605 | // ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 606 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 607 | // // output to std::cout |
| 608 | // std::string acutalOutput; |
| 609 | // { |
| 610 | // OutputTester tester; |
| 611 | // m_tool.exportCertificate(otherDsk, "-"); |
| 612 | // acutalOutput = tester.buffer.str(); |
| 613 | // } |
| 614 | // BOOST_CHECK_EQUAL(acutalOutput, dskValue); |
| 615 | // } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 616 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 617 | BOOST_AUTO_TEST_CASE(AddRrset) |
| 618 | { |
| 619 | Name zoneName("/ndns-test"); |
| 620 | Zone zone(zoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 621 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 622 | time::seconds ttl1(4200); |
| 623 | time::seconds ttl2(4500); |
| 624 | m_tool.createZone(zoneName, ROOT_ZONE, ttl1); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 625 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 626 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 627 | rf.checkZoneKey(); |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame] | 628 | Rrset rrset1 = rf.generateNsRrset("/l1", 7654, ttl2, {}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 629 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 630 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1)); |
| 631 | Rrset rrset2 = findRrSet(zone, "/l1", label::NS_RR_TYPE); |
| 632 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 633 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 634 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 635 | BOOST_AUTO_TEST_CASE(AddMultiLevelLabelRrset) |
| 636 | { |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 637 | Name zoneName("/ndns-test"); |
| 638 | Zone zone(zoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 639 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 640 | time::seconds ttl(4200); |
| 641 | m_tool.createZone(zoneName, ROOT_ZONE, ttl); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 642 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 643 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 644 | rf.checkZoneKey(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 645 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 646 | auto checkRrset = [&zone, &zoneName, this](Name label, |
| 647 | name::Component type, |
| 648 | NdnsContentType contentType) -> void { |
| 649 | Rrset rr1 = findRrSet(zone, label, type); |
| 650 | BOOST_CHECK_EQUAL(Data(rr1.getData()).getContentType(), contentType); |
| 651 | Response response1; |
| 652 | response1.fromData(zoneName, Data(rr1.getData())); |
| 653 | BOOST_CHECK_EQUAL(response1.getRrLabel(), label); |
| 654 | }; |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 655 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 656 | Name labelName("/l1/l2/l3"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 657 | |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame] | 658 | Rrset rrset1 = rf.generateNsRrset(labelName, 7654, ttl, {}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 659 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 660 | //add NS NDNS_AUTH and check user-defined ttl |
| 661 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(rrset1, rf, ttl)); |
| 662 | Rrset rrset2 = findRrSet(zone, labelName, label::NS_RR_TYPE); |
| 663 | BOOST_CHECK_EQUAL(rrset1, rrset2); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 664 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 665 | checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 666 | checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 667 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 668 | // insert a same-name rrset with TXT type |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 669 | Rrset txtRr = rf.generateTxtRrset("/l1/l2/l3", 7654, ttl, std::vector<std::string>()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 670 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(txtRr, rf, ttl)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 671 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 672 | checkRrset("/l1", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 673 | checkRrset("/l1/l2", label::NS_RR_TYPE, ndns::NDNS_AUTH); |
| 674 | checkRrset("/l1/l2/l3", label::TXT_RR_TYPE, ndns::NDNS_RESP); |
| 675 | // check that there is no confliction |
| 676 | checkRrset("/l1/l2/l3", label::NS_RR_TYPE, ndns::NDNS_LINK); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 677 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 678 | // insert a shorter NS, when there are longer NS or TXT |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame] | 679 | Rrset shorterNs = rf.generateNsRrset("/l1/l2", 7654, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 680 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(shorterNs, rf, ttl), |
| 681 | ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 682 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 683 | // insert a longer NS, when there is already a shorter NS |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame] | 684 | Rrset longerNs = rf.generateNsRrset("/l1/l2/l3/l4", 7654, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 685 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(longerNs, rf, ttl), |
| 686 | ndns::ManagementTool::Error); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 687 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 688 | // insert a smaller TXT, when there are longer NS and TXT |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 689 | Rrset shorterTxt = rf.generateTxtRrset("/l1/l2", 7654, ttl, std::vector<std::string>()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 690 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(shorterTxt, rf, ttl)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 691 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 692 | // insert a smaller NS, when there is long TXT |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 693 | Rrset longTxt = rf.generateTxtRrset("/k1/k2/k3", 7654, ttl, std::vector<std::string>()); |
Junxiao Shi | 81e9876 | 2022-01-11 18:17:24 +0000 | [diff] [blame] | 694 | Rrset smallerNs = rf.generateNsRrset("/k1/k2", 7654, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 695 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longTxt, rf, ttl)); |
| 696 | BOOST_CHECK_THROW(m_tool.addMultiLevelLabelRrset(smallerNs, rf, ttl), |
| 697 | ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 698 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 699 | // inserting a longer TXT, when there is shoter TXT |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 700 | Rrset longerTxt = rf.generateTxtRrset("/k1/k2/k3/k4", 7654, ttl, std::vector<std::string>()); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 701 | BOOST_CHECK_NO_THROW(m_tool.addMultiLevelLabelRrset(longerTxt, rf, ttl)); |
| 702 | } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 703 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 704 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertPreConditon) |
| 705 | { |
| 706 | // check pre-condition |
| 707 | Name zoneName("/ndns-test"); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 708 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 709 | // Check: throw if zone not exist |
| 710 | std::string certPath = TEST_CERTDIR.string(); |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 711 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 712 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 713 | m_tool.createZone(zoneName, ROOT_ZONE); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 714 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 715 | // Check: throw if certificate does not match |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 716 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, certPath), ndns::ManagementTool::Error); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 717 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 718 | std::string rightCertPath = TEST_CERTDIR.string() + "/ss.cert"; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 719 | std::vector<Certificate>&& certs = getCerts(zoneName); |
| 720 | const Name& ksk = certs[0].getName(); |
| 721 | m_tool.exportCertificate(ksk, rightCertPath); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 722 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 723 | // Check: throw if it's a duplicated certificate |
| 724 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, rightCertPath), ndns::ManagementTool::Error); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 725 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 726 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 727 | BOOST_AUTO_TEST_CASE(AddRrSetDskCert) |
| 728 | { |
| 729 | Name parentZoneName("/ndns-test"); |
| 730 | Name zoneName("/ndns-test/child-zone"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 731 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 732 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 733 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 734 | m_tool.createZone(zoneName, parentZoneName); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 735 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 736 | Zone zone(zoneName); |
| 737 | Zone parentZone(parentZoneName); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 738 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 739 | Certificate dkey(findDkeyFromDb(zone.getName())); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 740 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 741 | ndn::io::save(dkey, output); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 742 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 743 | BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output)); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 744 | // Check if child zone's d-key could be inserted correctly |
| 745 | BOOST_CHECK_NO_THROW(findRrSet(parentZone, getLabel(parentZone, dkey.getName()), label::CERT_RR_TYPE)); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 746 | } |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 747 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 748 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertUserProvidedCert) |
| 749 | { |
Davide Pesavento | 7f27ec1 | 2022-03-10 20:10:54 -0500 | [diff] [blame] | 750 | // check using user provided certificate |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 751 | Name parentZoneName("/ndns-test"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 752 | Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 753 | Name zoneName("/ndns-test/child-zone"); |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 754 | Name zoneIdentityName = Name(zoneName).append(label::NDNS_ITERATIVE_QUERY); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 755 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 756 | // Name dskName = m_keyChain.generateRsaKeyPair(parentZoneName, false); |
| 757 | Identity id = CertHelper::getIdentity(m_keyChain, parentZoneIdentityName); |
| 758 | Key dsk = m_keyChain.createKey(id); |
| 759 | Certificate dskCert = dsk.getDefaultCertificate(); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 760 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 761 | // check addRrsetFromFile1 |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 762 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 763 | m_tool.createZone(zoneName, parentZoneName); |
| 764 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 765 | Certificate dkey(findDkeyFromDb(zoneName)); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 766 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 767 | ndn::io::save(dkey, output); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 768 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 769 | BOOST_CHECK_NO_THROW(m_tool.addRrsetFromFile(parentZoneName, output, time::seconds(4600), |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 770 | dskCert.getName())); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertInvalidOutput) |
| 774 | { |
Davide Pesavento | 7f27ec1 | 2022-03-10 20:10:54 -0500 | [diff] [blame] | 775 | // check invalid output |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 776 | Name parentZoneName("/ndns-test"); |
| 777 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 778 | m_tool.createZone(zoneName, parentZoneName); |
| 779 | |
| 780 | Name content = "invalid data packet"; |
| 781 | std::string output = TEST_CERTDIR.string() + "/ss.cert"; |
| 782 | ndn::io::save(content, output); |
| 783 | |
Yumin Xia | c5ed63f | 2017-01-26 13:44:38 -0800 | [diff] [blame] | 784 | BOOST_CHECK_THROW(m_tool.addRrsetFromFile(zoneName, output), ndns::ManagementTool::Error); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | BOOST_AUTO_TEST_CASE(AddRrSetVersionControl) |
| 788 | { |
Davide Pesavento | 7f27ec1 | 2022-03-10 20:10:54 -0500 | [diff] [blame] | 789 | // check version control |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 790 | time::seconds ttl(4200); |
| 791 | Name parentZoneName("/ndns-test"); |
| 792 | Name zoneName = Name(parentZoneName).append("child-zone"); |
| 793 | m_tool.createZone(zoneName, parentZoneName); |
| 794 | |
| 795 | Name label("/label"); |
| 796 | uint64_t version = 110; |
| 797 | |
| 798 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 799 | rf.checkZoneKey(); |
| 800 | |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 801 | Rrset rrset1 = rf.generateTxtRrset(label, version, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 802 | |
| 803 | m_tool.addRrset(rrset1); |
| 804 | // throw error when adding duplicated rrset with the same version |
| 805 | BOOST_CHECK_THROW(m_tool.addRrset(rrset1), |
| 806 | ndns::ManagementTool::Error); |
| 807 | version--; |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 808 | Rrset rrset2 = rf.generateTxtRrset(label, version, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 809 | // throw error when adding duplicated rrset with older version |
| 810 | BOOST_CHECK_THROW(m_tool.addRrset(rrset2), |
| 811 | ndns::ManagementTool::Error); |
| 812 | |
| 813 | version++; |
| 814 | version++; |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 815 | Rrset rrset3 = rf.generateTxtRrset(label, version, ttl, {}); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 816 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset3)); |
| 817 | |
| 818 | Zone zone(zoneName); |
| 819 | m_dbMgr.find(zone); |
| 820 | Rrset rrset; |
| 821 | rrset.setZone(&zone); |
| 822 | rrset.setLabel(label); |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 823 | rrset.setType(label::TXT_RR_TYPE); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 824 | m_dbMgr.find(rrset); |
| 825 | |
| 826 | BOOST_CHECK_EQUAL(rrset.getVersion(), name::Component::fromVersion(version)); |
| 827 | } |
| 828 | |
| 829 | BOOST_AUTO_TEST_CASE(AddRrSetDskCertFormat) |
| 830 | { |
Davide Pesavento | 7f27ec1 | 2022-03-10 20:10:54 -0500 | [diff] [blame] | 831 | // check input with different formats |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 832 | Name parentZoneName("/ndns-test"); |
| 833 | Name zoneName = Name(parentZoneName).append("child-zone"); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 834 | Zone parentZone(parentZoneName); |
| 835 | |
| 836 | m_tool.createZone(parentZoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 837 | m_tool.createZone(zoneName, parentZoneName); |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 838 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 839 | Certificate cert(findDkeyFromDb(zoneName)); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 840 | std::string output = TEST_CERTDIR.string() + "/a.cert"; |
Jiewen Tan | d2d2182 | 2015-03-19 15:37:03 -0700 | [diff] [blame] | 841 | |
Yumin Xia | 918343d | 2017-03-17 19:04:55 -0700 | [diff] [blame] | 842 | Name parentZoneIdentityName = Name(parentZoneName).append(label::NDNS_ITERATIVE_QUERY); |
| 843 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 844 | // base64 |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 845 | ndn::io::save(cert, output, ndn::io::BASE64); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 846 | BOOST_CHECK_NO_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 847 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::BASE64)); |
| 848 | m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 849 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 850 | // raw |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 851 | ndn::io::save(cert, output, ndn::io::NO_ENCODING); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 852 | BOOST_CHECK_NO_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 853 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::NO_ENCODING)); |
| 854 | m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 855 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 856 | // hex |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 857 | ndn::io::save(cert, output, ndn::io::HEX); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 858 | BOOST_CHECK_NO_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 859 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, ndn::io::HEX)); |
| 860 | m_tool.removeRrSet(parentZoneName, getLabel(parentZone, cert.getName()), label::CERT_RR_TYPE); |
Jiewen Tan | 8cd35ea | 2015-03-20 00:44:23 -0700 | [diff] [blame] | 861 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 862 | // incorrect encoding input |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 863 | ndn::io::save(cert, output, ndn::io::HEX); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 864 | BOOST_CHECK_THROW( |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 865 | m_tool.addRrsetFromFile(parentZoneName, output, DEFAULT_CACHE_TTL, DEFAULT_CERT, |
| 866 | static_cast<ndn::io::IoEncoding>(127)), |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 867 | ndns::ManagementTool::Error); |
| 868 | } |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 869 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 870 | BOOST_AUTO_TEST_CASE(ListAllZones) |
| 871 | { |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 872 | m_tool.createZone(ROOT_ZONE, ROOT_ZONE, time::seconds(1), time::days(1), rootKsk, rootDsk, rootDkey); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 873 | m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 874 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 875 | Name rootDskName = CertHelper::getCertificate(m_keyChain, "/NDNS/", rootDsk).getKeyName(); |
| 876 | Name otherDskName = CertHelper::getCertificate(m_keyChain, "/ndns-test/NDNS/", otherDsk).getKeyName(); |
| 877 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 878 | std::string expectedValue = |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 879 | "/ ; default-ttl=1 default-key=" + rootDskName.toUri() + " " |
| 880 | "default-certificate=" + rootDsk.toUri() + "\n" |
| 881 | "/ndns-test ; default-ttl=10 default-key=" + otherDskName.toUri() + " " |
| 882 | "default-certificate=" + otherDsk.toUri() + "\n"; |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 883 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 884 | output_test_stream testOutput; |
| 885 | m_tool.listAllZones(testOutput); |
| 886 | BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 887 | } |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 888 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 889 | // Test need to fix values of keys, otherwise it produces different values every time |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 890 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 891 | // BOOST_AUTO_TEST_CASE(ListZone) |
| 892 | // { |
| 893 | // m_tool.createZone("/ndns-test", ROOT_ZONE, time::seconds(10), time::days(1), otherKsk, otherDsk); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 894 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 895 | // RrsetFactory rf(TEST_DATABASE, "/ndns-test", m_keyChain, DEFAULT_CERT); |
| 896 | // rf.checkZoneKey(); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 897 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 898 | // // Add NS with NDNS_RESP |
| 899 | // Delegation del; |
| 900 | // del.preference = 10; |
| 901 | // del.name = Name("/get/link"); |
| 902 | // DelegationList ds = {del}; |
| 903 | // Rrset rrset1 = rf.generateNsRrset("/label1", 100, DEFAULT_RR_TTL, ds); |
| 904 | // m_tool.addRrset(rrset1); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 905 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 906 | // // Add NS with NDNS_AUTH |
| 907 | // Rrset rrset2 = rf.generateAuthRrset("/label2", 100000, DEFAULT_RR_TTL); |
| 908 | // m_tool.addRrset(rrset2); |
Jiewen Tan | 74d745c | 2015-03-20 01:40:41 -0700 | [diff] [blame] | 909 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 910 | // // Add TXT from file |
| 911 | // std::string output = TEST_CERTDIR.string() + "/a.rrset"; |
| 912 | // Response re1; |
| 913 | // re1.setZone("/ndns-test"); |
| 914 | // re1.setQueryType(label::NDNS_ITERATIVE_QUERY); |
| 915 | // re1.setRrLabel("/label2"); |
| 916 | // re1.setRrType(label::TXT_RR_TYPE); |
| 917 | // re1.setContentType(NDNS_RESP); |
| 918 | // re1.setVersion(name::Component::fromVersion(654321)); |
| 919 | // re1.addRr("First RR"); |
| 920 | // re1.addRr("Second RR"); |
| 921 | // re1.addRr("Last RR"); |
| 922 | // shared_ptr<Data> data1 = re1.toData(); |
| 923 | // m_keyChain.sign(*data1, security::signingByCertificate(otherDsk)); |
| 924 | // ndn::io::save(*data1, output); |
| 925 | // m_tool.addRrsetFromFile("/ndns-test", output); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 926 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 927 | // // Add TXT in normal way |
| 928 | // Rrset rrset3 = rf.generateTxtRrset("/label3", 3333, DEFAULT_RR_TTL, {"Hello", "World"}); |
| 929 | // m_tool.addRrset(rrset3); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 930 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 931 | // m_tool.listZone("/ndns-test", std::cout, true); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 932 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 933 | // output_test_stream testOutput; |
| 934 | // m_tool.listZone("/ndns-test", testOutput, true); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 935 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 936 | // std::string expectedValue = |
| 937 | // R"VALUE(; Zone /ndns-test |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 938 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 939 | // ; rrset=/ type=DOE version=%FD%00%00%01b%26e%AE%99 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 940 | // / 3600 DOE Bw0IBmxhYmVsMwgDVFhU |
| 941 | // / 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 942 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 943 | // /KEY/%12%05t%90%3AjvA 10 CERT ; content-type=KEY version=%FD%00%00%01b%26e%AEY signed-by=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
| 944 | // Certificate name: |
| 945 | // /ndns-test/NDNS/KEY/%12%05t%90%3AjvA/CERT/%FD%00%00%01b%26e%AEY |
| 946 | // Validity: |
| 947 | // NotBefore: 20180314T212340 |
| 948 | // NotAfter: 20180324T212340 |
| 949 | // Public key bits: |
| 950 | // MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA |
| 951 | // AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA//// |
| 952 | // ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd |
| 953 | // NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5 |
| 954 | // RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA |
| 955 | // //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABHU62fbCa6KR7G1iyMr6/NtF |
| 956 | // 5oHrAdzttIgh5pk1VS1YcFO1zhpUnpJS43FlduYHVBLrXwYS6tZ15Ge/D3uy1f4= |
| 957 | // Signature Information: |
| 958 | // Signature Type: SignatureSha256WithEcdsa |
| 959 | // Key Locator: Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 960 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 961 | // ; rrset=/KEY/%12%05t%90%3AjvA/CERT type=DOE version=%FD%00%00%01b%26e%AE%91 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 962 | // /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ= |
| 963 | // /KEY/%12%05t%90%3AjvA/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 964 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 965 | // /KEY/%8D%1Dj%1E%BE%B0%2A%E4 10 CERT ; content-type=KEY version=%FD%00%00%01b%26e%AEX signed-by=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
| 966 | // Certificate name: |
| 967 | // /ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT/%FD%00%00%01b%26e%AEX |
| 968 | // Validity: |
| 969 | // NotBefore: 20180314T212340 |
| 970 | // NotAfter: 20180324T212340 |
| 971 | // Public key bits: |
| 972 | // MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA |
| 973 | // AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA//// |
| 974 | // ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd |
| 975 | // NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5 |
| 976 | // RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA |
| 977 | // //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABMRVD/FUfCQVvjcwQLe9k1aS |
| 978 | // 5pZ/xmFndOHn1+a0OYVzxCV1JcxL1eojcij42tCP5mtocrj9DjYyFBv4Atg1RZE= |
| 979 | // Signature Information: |
| 980 | // Signature Type: SignatureSha256WithEcdsa |
| 981 | // Key Locator: Self-Signed Name=/ndns-test/NDNS/KEY/%8D%1Dj%1E%BE%B0%2A%E4 |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 982 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 983 | // ; rrset=/KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT type=DOE version=%FD%00%00%01b%26e%AE%93 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 984 | // /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BxUIA0tFWQgIjR1qHr6wKuQIBENFUlQ= |
| 985 | // /KEY/%8D%1Dj%1E%BE%B0%2A%E4/CERT 3600 DOE BwwIBmxhYmVsMQgCTlM= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 986 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 987 | // ; rrset=/label1 type=NS version=%FDd signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 988 | // /label1 10 NS 10 |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 989 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 990 | // ; rrset=/label1/NS type=DOE version=%FD%00%00%01b%26e%AE%94 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 991 | // /label1/NS 3600 DOE BwwIBmxhYmVsMQgCTlM= |
| 992 | // /label1/NS 3600 DOE BwwIBmxhYmVsMggCTlM= |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 993 | |
Yumin Xia | 55a7cc4 | 2017-05-14 18:43:34 -0700 | [diff] [blame] | 994 | // ; rrset=/label2 type=NS version=%FD%00%01%86%A0 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 995 | // /label2 10 NS NDNS-Auth |
| 996 | |
| 997 | // ; rrset=/label2 type=TXT version=%FD%00%09%FB%F1 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 998 | // /label2 10 TXT First RR |
| 999 | // /label2 10 TXT Second RR |
| 1000 | // /label2 10 TXT Last RR |
| 1001 | |
| 1002 | // ; rrset=/label2/NS type=DOE version=%FD%00%00%01b%26e%AE%96 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1003 | // /label2/NS 3600 DOE BwwIBmxhYmVsMggCTlM= |
| 1004 | // /label2/NS 3600 DOE Bw0IBmxhYmVsMggDVFhU |
| 1005 | |
| 1006 | // ; rrset=/label2/TXT type=DOE version=%FD%00%00%01b%26e%AE%97 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1007 | // /label2/TXT 3600 DOE Bw0IBmxhYmVsMggDVFhU |
| 1008 | // /label2/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU |
| 1009 | |
| 1010 | // ; rrset=/label3 type=TXT version=%FD%0D%05 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1011 | // /label3 10 TXT Hello |
| 1012 | // /label3 10 TXT World |
| 1013 | |
| 1014 | // ; rrset=/label3/TXT type=DOE version=%FD%00%00%01b%26e%AE%98 signed-by=/ndns-test/NDNS/KEY/%12%05t%90%3AjvA |
| 1015 | // /label3/TXT 3600 DOE Bw0IBmxhYmVsMwgDVFhU |
| 1016 | // /label3/TXT 3600 DOE BxUIA0tFWQgIEgV0kDpqdkEIBENFUlQ= |
| 1017 | |
| 1018 | // )VALUE"; |
| 1019 | |
| 1020 | // BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 1021 | // } |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 1022 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1023 | BOOST_FIXTURE_TEST_CASE(GetRrSet, ManagementToolFixture) |
| 1024 | { |
| 1025 | Name zoneName("/ndns-test"); |
| 1026 | m_tool.createZone(zoneName, ROOT_ZONE, time::seconds(1), time::days(1), otherKsk, otherDsk); |
| 1027 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 1028 | rf.checkZoneKey(); |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 1029 | Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {"Value1", "Value2"}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1030 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1031 | m_tool.addRrset(rrset1); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1032 | |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 1033 | std::stringstream os; |
| 1034 | |
| 1035 | using security::transform::base64Encode; |
| 1036 | using security::transform::streamSink; |
| 1037 | using security::transform::bufferSource; |
| 1038 | |
Davide Pesavento | 9802612 | 2022-03-14 22:00:03 -0400 | [diff] [blame] | 1039 | bufferSource(rrset1.getData()) >> base64Encode() >> streamSink(os); |
Yumin Xia | 2c509c2 | 2017-02-09 14:37:36 -0800 | [diff] [blame] | 1040 | |
| 1041 | std::string expectedValue = os.str(); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1042 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1043 | output_test_stream testOutput; |
| 1044 | m_tool.getRrSet(zoneName, "/label",label::TXT_RR_TYPE, testOutput); |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1045 | BOOST_CHECK(testOutput.is_equal(expectedValue)); |
| 1046 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1047 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1048 | BOOST_FIXTURE_TEST_CASE(RemoveRrSet, ManagementToolFixture) |
| 1049 | { |
| 1050 | Name zoneName("/ndns-test"); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1051 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1052 | m_tool.createZone(zoneName, ROOT_ZONE); |
| 1053 | RrsetFactory rf(TEST_DATABASE, zoneName, m_keyChain, DEFAULT_CERT); |
| 1054 | rf.checkZoneKey(); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 1055 | |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 1056 | Rrset rrset1 = rf.generateTxtRrset("/label", 100, DEFAULT_RR_TTL, {}); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1057 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1058 | BOOST_CHECK_NO_THROW(m_tool.addRrset(rrset1)); |
Alexander Afanasyev | d6b3bda | 2014-11-25 17:33:58 -0800 | [diff] [blame] | 1059 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1060 | Zone zone(zoneName); |
Yumin Xia | d4e8ce5 | 2017-03-17 19:56:52 -0700 | [diff] [blame] | 1061 | BOOST_CHECK_NO_THROW(findRrSet(zone, "/label", label::TXT_RR_TYPE)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1062 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1063 | BOOST_CHECK_NO_THROW(m_tool.removeRrSet(zoneName, "/label", label::NS_RR_TYPE)); |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1064 | |
Yumin Xia | 9d110ce | 2016-11-15 14:03:14 -0800 | [diff] [blame] | 1065 | BOOST_CHECK_THROW(findRrSet(zone, "/label", label::NS_RR_TYPE), Error); |
| 1066 | } |
Jiewen Tan | 870b29b | 2014-11-17 19:09:49 -0800 | [diff] [blame] | 1067 | |
| 1068 | BOOST_AUTO_TEST_SUITE_END() |
| 1069 | |
| 1070 | } // namespace tests |
| 1071 | } // namespace ndns |
| 1072 | } // namespace ndn |