Adapt to ndn-cxx security changes
refs: #4090, #4195, #3828
Change-Id: Ie1bf11d604af12d3b26fba24054ed67fe735ae7c
diff --git a/common.hpp b/common.hpp
index 2ddc3d9..ce1f776 100644
--- a/common.hpp
+++ b/common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -84,10 +84,11 @@
namespace tlv {
using namespace ndn::tlv;
-}
+} // namespace tlv
namespace name = ndn::name;
namespace time = ndn::time;
+namespace security = ndn::security;
} // namespace chronosync
diff --git a/src/leaf-container.hpp b/src/leaf-container.hpp
index d116b55..e1d30bd 100644
--- a/src/leaf-container.hpp
+++ b/src/leaf-container.hpp
@@ -28,14 +28,12 @@
#include "mi-tag.hpp"
#include "leaf.hpp"
-#include <ndn-cxx/util/crypto.hpp>
-
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
-
+#include <ndn-cxx/util/sha256.hpp>
namespace chronosync {
@@ -47,7 +45,7 @@
operator()(const Name& prefix) const
{
ndn::ConstBufferPtr buffer =
- ndn::crypto::computeSha256Digest(prefix.wireEncode().wire(), prefix.wireEncode().size());
+ ndn::util::Sha256::computeDigest(prefix.wireEncode().wire(), prefix.wireEncode().size());
BOOST_ASSERT(buffer->size() > sizeof(std::size_t));
diff --git a/src/leaf.hpp b/src/leaf.hpp
index b26b975..4c8223d 100644
--- a/src/leaf.hpp
+++ b/src/leaf.hpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -26,7 +26,7 @@
#define CHRONOSYNC_LEAF_HPP
#include "common.hpp"
-#include <ndn-cxx/util/digest.hpp>
+#include <ndn-cxx/util/sha256.hpp>
namespace chronosync {
diff --git a/src/logic.cpp b/src/logic.cpp
index fc4aa83..df0fcd1 100644
--- a/src/logic.cpp
+++ b/src/logic.cpp
@@ -26,6 +26,8 @@
#include "logic.hpp"
#include "logger.hpp"
+#include <ndn-cxx/util/string-helper.hpp>
+
INIT_LOGGER(Logic);
#ifdef _DEBUG
@@ -94,7 +96,6 @@
, m_syncInterestLifetime(syncInterestLifetime)
, m_syncReplyFreshness(syncReplyFreshness)
, m_recoveryInterestLifetime(recoveryInterestLifetime)
- , m_defaultSigningId(defaultSigningId)
, m_validator(validator)
{
#ifdef _DEBUG
@@ -103,7 +104,7 @@
_LOG_DEBUG_ID(">> Logic::Logic");
- addUserNode(m_defaultUserPrefix, m_defaultSigningId);
+ addUserNode(m_defaultUserPrefix, defaultSigningId);
m_syncReset = m_syncPrefix;
@@ -159,7 +160,6 @@
if (defaultUserPrefix != EMPTY_NAME) {
if (m_nodeList.find(defaultUserPrefix) != m_nodeList.end()) {
m_defaultUserPrefix = defaultUserPrefix;
- m_defaultSigningId = m_nodeList[defaultUserPrefix].signingId;
}
}
}
@@ -171,7 +171,6 @@
return;
if (m_defaultUserPrefix == EMPTY_NAME) {
m_defaultUserPrefix = userPrefix;
- m_defaultSigningId = signingId;
}
if (m_nodeList.find(userPrefix) == m_nodeList.end()) {
m_nodeList[userPrefix].userPrefix = userPrefix;
@@ -193,11 +192,9 @@
if (m_defaultUserPrefix == userPrefix) {
if (!m_nodeList.empty()) {
m_defaultUserPrefix = m_nodeList.begin()->second.userPrefix;
- m_defaultSigningId = m_nodeList.begin()->second.signingId;
}
else {
m_defaultUserPrefix = EMPTY_NAME;
- m_defaultSigningId = DEFAULT_NAME;
}
}
reset(false);
@@ -256,11 +253,7 @@
_LOG_DEBUG_ID("updateSeqNo: not in Reset ");
ndn::ConstBufferPtr previousRoot = m_state.getRootDigest();
{
- using namespace CryptoPP;
-
- std::string hash;
- StringSource(previousRoot->buf(), previousRoot->size(), true,
- new HexEncoder(new StringSink(hash), false));
+ std::string hash = ndn::toHex(previousRoot->buf(), previousRoot->size(), false);
_LOG_DEBUG_ID("Hash: " << hash);
}
@@ -660,7 +653,7 @@
if (m_nodeList[nodePrefix].signingId.empty())
m_keyChain.sign(*syncReply);
else
- m_keyChain.signByIdentity(*syncReply, m_nodeList[nodePrefix].signingId);
+ m_keyChain.sign(*syncReply, security::signingByIdentity(m_nodeList[nodePrefix].signingId));
m_face.put(*syncReply);
@@ -700,11 +693,7 @@
void
Logic::printDigest(ndn::ConstBufferPtr digest)
{
- using namespace CryptoPP;
-
- std::string hash;
- StringSource(digest->buf(), digest->size(), true,
- new HexEncoder(new StringSink(hash), false));
+ std::string hash = ndn::toHex(digest->buf(), digest->size(), false);
_LOG_DEBUG_ID("Hash: " << hash);
}
@@ -811,7 +800,7 @@
if (m_nodeList[nodePrefix].signingId.empty())
m_keyChain.sign(*data);
else
- m_keyChain.signByIdentity(*data, m_nodeList[nodePrefix].signingId);
+ m_keyChain.sign(*data, security::signingByIdentity(m_nodeList[nodePrefix].signingId));
sendExcludeInterest(interest, *data);
diff --git a/src/logic.hpp b/src/logic.hpp
index 4f75085..78080ae 100644
--- a/src/logic.hpp
+++ b/src/logic.hpp
@@ -27,17 +27,18 @@
#define CHRONOSYNC_LOGIC_HPP
#include "boost-header.h"
+#include "diff-state-container.hpp"
+#include "interest-table.hpp"
+
#include <memory>
#include <unordered_map>
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/scheduler.hpp>
#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/validator.hpp>
-#include "interest-table.hpp"
-#include "diff-state-container.hpp"
-
namespace chronosync {
/**
@@ -515,7 +516,6 @@
time::milliseconds m_recoveryInterestLifetime;
// Security
- ndn::Name m_defaultSigningId;
ndn::KeyChain m_keyChain;
std::shared_ptr<ndn::Validator> m_validator;
diff --git a/src/socket.cpp b/src/socket.cpp
index 4a947d7..0fd5707 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -129,7 +129,7 @@
if (m_signingId.empty())
m_keyChain.sign(*data);
else
- m_keyChain.signByIdentity(*data, m_signingId);
+ m_keyChain.sign(*data, security::signingByIdentity(m_signingId));
m_ims.insert(*data);
@@ -152,7 +152,7 @@
if (m_signingId.empty())
m_keyChain.sign(*data);
else
- m_keyChain.signByIdentity(*data, m_signingId);
+ m_keyChain.sign(*data, security::signingByIdentity(m_signingId));
m_ims.insert(*data);
diff --git a/src/socket.hpp b/src/socket.hpp
index 356b212..6ec0aef 100644
--- a/src/socket.hpp
+++ b/src/socket.hpp
@@ -25,12 +25,12 @@
#ifndef CHRONOSYNC_SOCKET_HPP
#define CHRONOSYNC_SOCKET_HPP
-#include <ndn-cxx/face.hpp>
-#include <ndn-cxx/util/in-memory-storage-persistent.hpp>
-#include <unordered_map>
-
#include "logic.hpp"
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/ims/in-memory-storage-persistent.hpp>
+#include <unordered_map>
+
namespace chronosync {
/**
@@ -235,12 +235,12 @@
ndn::Face& m_face;
Logic m_logic;
- ndn::Name m_signingId;
+ Name m_signingId;
ndn::KeyChain m_keyChain;
std::shared_ptr<ndn::Validator> m_validator;
RegisteredPrefixList m_registeredPrefixList;
- ndn::util::InMemoryStoragePersistent m_ims;
+ ndn::InMemoryStoragePersistent m_ims;
};
} // namespace chronosync
diff --git a/src/state.hpp b/src/state.hpp
index 4fa82e9..8713552 100644
--- a/src/state.hpp
+++ b/src/state.hpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -27,7 +27,7 @@
#include "tlv.hpp"
#include "leaf-container.hpp"
-#include <ndn-cxx/util/digest.hpp>
+#include <ndn-cxx/util/sha256.hpp>
namespace chronosync {
diff --git a/tests/unit-tests/test-interest-table.cpp b/tests/unit-tests/test-interest-table.cpp
index 8b1f156..0f0c95d 100644
--- a/tests/unit-tests/test-interest-table.cpp
+++ b/tests/unit-tests/test-interest-table.cpp
@@ -18,12 +18,11 @@
*/
#include "interest-table.hpp"
+#include "boost-test.hpp"
+#include "../unit-test-time-fixture.hpp"
#include <unistd.h>
-#include "../unit-test-time-fixture.hpp"
-#include "boost-test.hpp"
-
namespace chronosync {
namespace test {
@@ -36,19 +35,19 @@
Name prefix("/test/prefix");
Name interestName1;
- digest1 = ndn::crypto::computeSha256Digest(origin, 1);
+ digest1 = ndn::util::Sha256::computeDigest(origin, 1);
interestName1.append(prefix).append(name::Component(digest1));
interest1 = make_shared<Interest>(interestName1);
interest1->setInterestLifetime(time::milliseconds(100));
Name interestName2;
- digest2 = ndn::crypto::computeSha256Digest(origin, 2);
+ digest2 = ndn::util::Sha256::computeDigest(origin, 2);
interestName2.append(prefix).append(name::Component(digest2));
interest2 = make_shared<Interest>(interestName2);
interest2->setInterestLifetime(time::milliseconds(100));
Name interestName3;
- digest3 = ndn::crypto::computeSha256Digest(origin, 3);
+ digest3 = ndn::util::Sha256::computeDigest(origin, 3);
interestName3.append(prefix).append(name::Component(digest3));
interest3 = make_shared<Interest>(interestName3);
interest3->setInterestLifetime(time::milliseconds(100));
diff --git a/tests/unit-tests/test-leaf.cpp b/tests/unit-tests/test-leaf.cpp
index 5553a05..1588514 100644
--- a/tests/unit-tests/test-leaf.cpp
+++ b/tests/unit-tests/test-leaf.cpp
@@ -1,6 +1,6 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
/*
- * Copyright (c) 2012-2014 University of California, Los Angeles
+ * Copyright (c) 2012-2017 University of California, Los Angeles
*
* This file is part of ChronoSync, synchronization library for distributed realtime
* applications for NDN.
@@ -17,13 +17,12 @@
* ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-
#include "leaf.hpp"
-#include "leaf-container.hpp"
-#include <ndn-cxx/encoding/buffer-stream.hpp>
-
#include "boost-test.hpp"
+#include "leaf-container.hpp"
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <ndn-cxx/util/string-helper.hpp>
namespace chronosync {
namespace test {
@@ -49,12 +48,7 @@
BOOST_AUTO_TEST_CASE(LeafDigest)
{
- using namespace CryptoPP;
-
- std::string hexResult = "05fe7f728d3341e9eff82526277b02171044124d0a52e8c4610982261c20de2b";
- ndn::OBufferStream os;
- StringSource(hexResult, true, new HexDecoder(new FileSink(os)));
- ndn::ConstBufferPtr result = os.buf();
+ std::string result = "05fe7f728d3341e9eff82526277b02171044124d0a52e8c4610982261c20de2b";
Name userPrefix("/test/name");
Leaf leaf(userPrefix, 1, 10);
@@ -62,7 +56,7 @@
BOOST_CHECK_NO_THROW(leaf.getDigest());
ndn::ConstBufferPtr digest = leaf.getDigest();
- BOOST_CHECK(*result == *digest);
+ BOOST_CHECK_EQUAL(result, ndn::toHex(digest->buf(), digest->size(), false));
}
BOOST_AUTO_TEST_CASE(Container)
diff --git a/wscript b/wscript
index e3e3b1e..01139df 100644
--- a/wscript
+++ b/wscript
@@ -21,7 +21,7 @@
def configure(conf):
conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
- 'default-compiler-flags', 'boost', 'pch', 'sanitizers', 'coverage',
+ 'default-compiler-flags', 'boost', 'pch', 'coverage',
'doxygen', 'sphinx_build'])
conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
@@ -35,6 +35,8 @@
conf.check_boost(lib=boost_libs, mt=True)
+ conf.load('sanitizers')
+
# If there happens to be a static library, waf will put the corresponding -L flags
# before dynamic library flags. This can result in compilation failure when the
# system has a different version of the ChronoSync library installed.