working on TLV encoding
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 56ab7e2..be44e11 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -22,6 +22,7 @@
#include "challenge-module.hpp"
#include "logging.hpp"
#include "crypto-support/enc-tlv.hpp"
+#include "tlv.hpp"
#include <ndn-cxx/util/io.hpp>
#include <ndn-cxx/security/verification-helpers.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
@@ -119,11 +120,11 @@
CaModule::onInfo(const Interest& request)
{
_LOG_TRACE("Received INFO request");
- JsonSection contentJson = genInfoResponseJson();
+ Block contentTLV = genInfoResponseTLV();
Data result;
result.setName(request.getName());
- result.setContent(dataContentFromJson(contentJson));
+ result.setContent(contentTLV);
result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD);
m_keyChain.sign(result, signingByIdentity(m_config.m_caName));
@@ -551,6 +552,46 @@
return root;
}
+Block
+CaModule::genInfoResponseTLV()
+{
+ Block response;
+ // ca-prefix
+ Name caName = m_config.m_caName;
+ // response = makeStringBlock(CAPrefix, caName.toUri());
+ response = makeNestedBlock(CAPrefix, caName);
+
+ // ca-info
+ const auto& pib = m_keyChain.getPib();
+ const auto& identity = pib.getIdentity(m_config.m_caName);
+ const auto& cert = identity.getDefaultKey().getDefaultCertificate();
+ std::string caInfo = "";
+ if (m_config.m_caInfo == "") {
+ caInfo = "Issued by " + cert.getSignature().getKeyLocator().getName().toUri();
+ }
+ else {
+ caInfo = m_config.m_caInfo;
+ }
+
+ response.push_back(makeStringBlock(CAInfo, caInfo));
+
+
+ // parameter-key (Not implemented yet)
+ for() {
+ response.push_back(makeStringBlock(ParameterKey, ""));
+ }
+
+ // TODO: need to convert from days to seconds
+ response.push_back(makeNonNegativeIntegerBlock(MaxValidityPeriod, m_validityPeriod));
+
+ // certificate
+ response.push_back(makeNestedBlock(CACertificate, cert));
+ response.parse();
+
+ return response;
+}
+
+
JsonSection
CaModule::genNewResponseJson(const std::string& ecdhKey, const std::string& salt,
const CertificateRequest& request,
diff --git a/src/client-config.cpp b/src/client-config.cpp
index 589cd49..9273760 100644
--- a/src/client-config.cpp
+++ b/src/client-config.cpp
@@ -19,6 +19,7 @@
*/
#include "client-config.hpp"
+#include "tlv.hpp"
#include <ndn-cxx/util/io.hpp>
#include <fstream>
@@ -83,17 +84,21 @@
}
ClientCaItem
-ClientConfig::extractCaItem(const JsonSection& configSection)
+ClientConfig::extractCaItem(const Block& contentBlock)
{
ClientCaItem item;
- item.m_caName = Name(configSection.get("ca-prefix", ""));
+ item.m_caName = Name(readString(contentBlock.get(CAPrefix)));
if (item.m_caName.empty()) {
BOOST_THROW_EXCEPTION(Error("Cannot read ca-prefix from the config file"));
}
- item.m_caInfo = configSection.get("ca-info", "");
- item.m_probe = configSection.get("probe", "");
- std::istringstream ss(configSection.get("certificate", ""));
- auto anchor = io::load<security::v2::Certificate>(ss);
+ item.m_caInfo = readString(contentBlock.get(CAInfo));
+ // item.m_probe = configSection.get("probe", "");
+
+ security::v2::Certificate anchor = contentBlock.get(CACertificate);
+
+ //std::istringstream ss(configSection.get("certificate", ""));
+ //auto anchor = io::load<security::v2::Certificate>(ss);
+
if (anchor == nullptr) {
BOOST_THROW_EXCEPTION(Error("Cannot load the certificate from config file"));
}
diff --git a/src/client-module.cpp b/src/client-module.cpp
index bf0ce20..1789632 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -59,11 +59,10 @@
}
bool
-ClientModule::verifyProbeInfoResponse(const Data& reply)
+ClientModule::verifyProbeInfoResponse(const Block& contentBlock)
{
// parse the ca item
- auto contentJson = getJsonFromData(reply);
- auto caItem = ClientConfig::extractCaItem(contentJson);
+ auto caItem = ClientConfig::extractCaItem(contentBlock);
// verify the probe Data's sig
if (!security::verifySignature(reply, caItem.m_anchor)) {
@@ -76,9 +75,10 @@
void
ClientModule::addCaFromProbeInfoResponse(const Data& reply)
{
+ const Block& contentBlock = reply.getContent();
+
// parse the ca item
- auto contentJson = getJsonFromData(reply);
- auto caItem = ClientConfig::extractCaItem(contentJson);
+ auto caItem = ClientConfig::extractCaItem(contentBlock);
// update the local config
bool findItem = false;
diff --git a/tests/unit-tests/bench.t.cpp b/tests/unit-tests/bench.t.cpp
new file mode 100644
index 0000000..91622da
--- /dev/null
+++ b/tests/unit-tests/bench.t.cpp
@@ -0,0 +1,43 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2017-2019, 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 "ca-module.hpp"
+#include "identity-management-fixture.hpp"
+
+#include <ndn-cxx/security/transform/base64-encode.hpp>
+#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/transform/stream-sink.hpp>
+
+namespace ndn {
+namespace ndncert {
+namespace tests {
+
+BOOST_FIXTURE_TEST_SUITE(TestForBenchmark, IdentityManagementFixture)
+
+BOOST_AUTO_TEST_CASE(ReadConfigFile)
+{
+ BOOST_CHECK(true);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
+
+} // namespace tests
+} // namespace ndncert
+} // namespace ndn