add PROBE redirection to protocol detail
Change-Id: I8b38ef87e978d05792197f2be330ec1f97f60b3d
diff --git a/src/challenge-module.hpp b/src/challenge-module.hpp
index bef26b5..1219399 100644
--- a/src/challenge-module.hpp
+++ b/src/challenge-module.hpp
@@ -22,7 +22,6 @@
#define NDNCERT_CHALLENGE_MODULE_HPP
#include "request-state.hpp"
-#include <tuple>
namespace ndn {
namespace ndncert {
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 18b71a0..8d1d397 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -136,15 +136,15 @@
for (const auto item : *redirectionItems) {
auto caPrefixStr = item.second.get(CONFIG_CA_PREFIX, "");
auto caCertStr = item.second.get(CONFIG_CERTIFICATE, "");
- if (caPrefixStr == "" || caCertStr == "") {
+ if (caCertStr == "") {
BOOST_THROW_EXCEPTION(std::runtime_error("Redirect-to item's ca-prefix or certificate cannot be empty."));
}
std::istringstream ss(caCertStr);
auto caCert = io::load<security::v2::Certificate>(ss);
if (!m_redirection) {
- m_redirection = RedirectionItems();
+ m_redirection = std::vector<std::shared_ptr<security::v2::Certificate>>();
}
- m_redirection->push_back(std::make_tuple(Name(caPrefixStr), caCert));
+ m_redirection->push_back(caCert);
}
}
}
diff --git a/src/configuration.hpp b/src/configuration.hpp
index e1706e7..892c056 100644
--- a/src/configuration.hpp
+++ b/src/configuration.hpp
@@ -136,8 +136,7 @@
* Used for CA redirection as specified in
* https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3-PROBE-Extensions#probe-extension-for-redirection
*/
- using RedirectionItems = std::vector<std::tuple<Name, std::shared_ptr<security::v2::Certificate>>>;
- boost::optional<RedirectionItems> m_redirection;
+ boost::optional<std::vector<std::shared_ptr<security::v2::Certificate>>> m_redirection;
/**
* NameAssignmentFunc Callback function
*/
diff --git a/src/ndncert-common.hpp b/src/ndncert-common.hpp
index 43f59d8..c680923 100644
--- a/src/ndncert-common.hpp
+++ b/src/ndncert-common.hpp
@@ -37,6 +37,8 @@
#include <cstddef>
#include <cstdint>
+#include <tuple>
+#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/data.hpp>
#include <ndn-cxx/encoding/block.hpp>
#include <ndn-cxx/face.hpp>
@@ -106,7 +108,8 @@
tlv_error_code = 171,
tlv_error_info = 173,
tlv_authentication_tag = 175,
- tlv_cert_to_revoke = 177
+ tlv_cert_to_revoke = 177,
+ tlv_probe_redirect = 179
};
// Parse CA Configuration file
diff --git a/src/protocol-detail/probe.cpp b/src/protocol-detail/probe.cpp
index c7b72d5..d2f9e7e 100644
--- a/src/protocol-detail/probe.cpp
+++ b/src/protocol-detail/probe.cpp
@@ -20,13 +20,9 @@
#include "probe.hpp"
-#include <boost/throw_exception.hpp>
-#include <ndn-cxx/encoding/tlv.hpp>
-
namespace ndn {
namespace ndncert {
-// For Client
Block
PROBE::encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters)
{
@@ -53,7 +49,8 @@
}
Block
-PROBE::encodeDataContent(const std::vector<Name>& identifiers, boost::optional<size_t> maxSuffixLength)
+PROBE::encodeDataContent(const std::vector<Name>& identifiers, boost::optional<size_t> maxSuffixLength,
+ boost::optional<std::vector<std::shared_ptr<security::v2::Certificate>>> redirectionItems)
{
Block content = makeEmptyBlock(tlv::Content);
for (const auto& name : identifiers) {
@@ -62,21 +59,29 @@
if (maxSuffixLength) {
content.push_back(makeNonNegativeIntegerBlock(tlv_max_suffix_length, *maxSuffixLength));
}
+ if (redirectionItems) {
+ for (const auto& item : *redirectionItems) {
+ content.push_back(makeNestedBlock(tlv_probe_redirect, item->getFullName()));
+ }
+ }
content.encode();
return content;
}
-std::vector<Name>
-PROBE::decodeDataContent(const Block& block)
+void
+PROBE::decodeDataContent(const Block& block,
+ std::vector<Name>& availableNames,
+ std::vector<Name>& availableRedirection)
{
- std::vector<Name> result;
block.parse();
for (const auto& item : block.elements()) {
if (item.type() == tlv_probe_response) {
- result.push_back(Name(item.blockFromValue()));
+ availableNames.push_back(Name(item.blockFromValue()));
+ }
+ if (item.type() == tlv_probe_redirect) {
+ availableRedirection.push_back(Name(item.blockFromValue()));
}
}
- return result;
}
} // namespace ndncert
diff --git a/src/protocol-detail/probe.hpp b/src/protocol-detail/probe.hpp
index 8d08e4b..6e19bab 100644
--- a/src/protocol-detail/probe.hpp
+++ b/src/protocol-detail/probe.hpp
@@ -28,16 +28,19 @@
class PROBE {
public:
- // For CA use
+ // For Client use
static Block
encodeApplicationParameters(std::vector<std::tuple<std::string, std::string>>&& parameters);
- static std::vector<Name>
- decodeDataContent(const Block& block);
+ static void
+ decodeDataContent(const Block& block, std::vector<Name>& availableNames,
+ std::vector<Name>& availableRedirection);
- // For client use
+ // For CA use
static Block
- encodeDataContent(const std::vector<Name>& identifiers, boost::optional<size_t> maxSuffixLength);
+ encodeDataContent(const std::vector<Name>& identifiers,
+ boost::optional<size_t> maxSuffixLength = boost::none,
+ boost::optional<std::vector<std::shared_ptr<security::v2::Certificate>>> redirectionItems = boost::none);
static std::vector<std::tuple<std::string, std::string>>
decodeApplicationParameters(const Block& block);
diff --git a/tests/unit-tests/configuration.t.cpp b/tests/unit-tests/configuration.t.cpp
index 3c73f12..ec47f9d 100644
--- a/tests/unit-tests/configuration.t.cpp
+++ b/tests/unit-tests/configuration.t.cpp
@@ -52,9 +52,7 @@
BOOST_CHECK_EQUAL(config.m_caItem.m_supportedChallenges.back(), "email");
config.load("tests/unit-tests/config-files/config-ca-5");
- BOOST_CHECK_EQUAL(config.m_redirection->size(), 1);
- BOOST_CHECK_EQUAL(std::get<0>(config.m_redirection->at(0)), Name("/ndn/edu/ucla"));
- BOOST_CHECK_EQUAL(std::get<1>(config.m_redirection->at(0))->getName(),
+ BOOST_CHECK_EQUAL(config.m_redirection->at(0)->getName(),
"/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5");
}
@@ -126,24 +124,6 @@
BOOST_CHECK_EQUAL(lastItem.m_caPrefix, "/ndn/edu/ucla/zhiyi");
}
-BOOST_AUTO_TEST_CASE(InfoEncodingDecoding)
-{
- CaConfig config;
- config.load("tests/unit-tests/config-files/config-ca-1");
-
- const auto& identity = addIdentity("/test");
- const auto& cert = identity.getDefaultKey().getDefaultCertificate();
- auto encoded = INFO::encodeDataContent(config.m_caItem, cert);
- auto decoded = INFO::decodeDataContent(encoded);
- BOOST_CHECK_EQUAL(config.m_caItem.m_caPrefix, decoded.m_caPrefix);
- BOOST_CHECK_EQUAL(config.m_caItem.m_caInfo, decoded.m_caInfo);
- BOOST_CHECK_EQUAL(config.m_caItem.m_maxValidityPeriod, decoded.m_maxValidityPeriod);
- BOOST_CHECK_EQUAL(*config.m_caItem.m_maxSuffixLength, *decoded.m_maxSuffixLength);
- BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.size(), decoded.m_probeParameterKeys.size());
- BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.front(), decoded.m_probeParameterKeys.front());
- BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_cert->wireEncode());
-}
-
BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
} // namespace tests
diff --git a/tests/unit-tests/protocol-detail.t.cpp b/tests/unit-tests/protocol-detail.t.cpp
new file mode 100644
index 0000000..881a040
--- /dev/null
+++ b/tests/unit-tests/protocol-detail.t.cpp
@@ -0,0 +1,76 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2017-2020, Regents of the University of California.
+ *
+ * This file is part of ndncert, a certificate management system based on NDN.
+ *
+ * ndncert is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License along with
+ * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndncert authors and contributors.
+ */
+
+#include "protocol-detail/info.hpp"
+#include "protocol-detail/probe.hpp"
+#include "protocol-detail/new-renew-revoke.hpp"
+#include "protocol-detail/challenge.hpp"
+#include "test-common.hpp"
+
+namespace ndn {
+namespace ndncert {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(TestProtocolDetail, IdentityManagementTimeFixture)
+
+BOOST_AUTO_TEST_CASE(TestInfo)
+{
+ CaConfig config;
+ config.load("tests/unit-tests/config-files/config-ca-1");
+
+ const auto& identity = addIdentity("/test");
+ const auto& cert = identity.getDefaultKey().getDefaultCertificate();
+ auto encoded = INFO::encodeDataContent(config.m_caItem, cert);
+ auto decoded = INFO::decodeDataContent(encoded);
+ BOOST_CHECK_EQUAL(config.m_caItem.m_caPrefix, decoded.m_caPrefix);
+ BOOST_CHECK_EQUAL(config.m_caItem.m_caInfo, decoded.m_caInfo);
+ BOOST_CHECK_EQUAL(config.m_caItem.m_maxValidityPeriod, decoded.m_maxValidityPeriod);
+ BOOST_CHECK_EQUAL(*config.m_caItem.m_maxSuffixLength, *decoded.m_maxSuffixLength);
+ BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.size(), decoded.m_probeParameterKeys.size());
+ BOOST_CHECK_EQUAL(config.m_caItem.m_probeParameterKeys.front(), decoded.m_probeParameterKeys.front());
+ BOOST_CHECK_EQUAL(cert.wireEncode(), decoded.m_cert->wireEncode());
+}
+
+BOOST_AUTO_TEST_CASE(TestProbe)
+{
+ std::vector<std::tuple<std::string, std::string>> parameters;
+ parameters.push_back(std::make_tuple("email", "zhiyi@cs.ucla.edu"));
+ auto appParametersTlv = PROBE::encodeApplicationParameters(std::move(parameters));
+ auto decodedParameters = PROBE::decodeApplicationParameters(appParametersTlv);
+ BOOST_CHECK_EQUAL(std::get<0>(decodedParameters[0]), "email");
+ BOOST_CHECK_EQUAL(std::get<1>(decodedParameters[0]), "zhiyi@cs.ucla.edu");
+ BOOST_CHECK_EQUAL(decodedParameters.size(), 1);
+
+ CaConfig config;
+ config.load("tests/unit-tests/config-files/config-ca-5");
+ std::vector<Name> ids;
+ ids.push_back(Name("/example"));
+ auto contentTlv = PROBE::encodeDataContent(ids, 2, config.m_redirection);
+ std::vector<Name> decodedIds, decodedRedirectionItems;
+ PROBE::decodeDataContent(contentTlv, decodedIds, decodedRedirectionItems);
+ BOOST_CHECK_EQUAL(decodedIds[0], Name("/example"));
+ BOOST_CHECK_EQUAL(decodedRedirectionItems[0], config.m_redirection->at(0)->getFullName());
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestProtocolDetail
+
+} // namespace tests
+} // namespace ndncert
+} // namespace ndn