port NAC to security v2
This commit is based on Lei Pi's commit, which changed certificate version from v1 to v2.
The later changes fix some bugs and refactor algo part of the library to get rid of cryptopp.
Change-Id: I3be7e0341fe85ee69f1b5f1c3ed7421a6c61d0b5
diff --git a/tests/unit-tests/consumer.t.cpp b/tests/unit-tests/consumer.t.cpp
index 15ede8b..174e247 100644
--- a/tests/unit-tests/consumer.t.cpp
+++ b/tests/unit-tests/consumer.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2016, Regents of the University of California
+ * Copyright (c) 2014-2018, Regents of the University of California
*
* This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
* See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
@@ -16,41 +16,35 @@
* You should have received a copy of the GNU General Public License along with
* ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*
- * @author Zhiyi Zhang <dreamerbarrychang@gmail.com>
+ * @author Zhiyi Zhang <zhiyi@cs.ucla.edu>
* @author Yingdi Yu <yingdi@cs.ucla.edu>
*/
#include "consumer.hpp"
#include "boost-test.hpp"
-#include "algo/encryptor.hpp"
#include "unit-test-time-fixture.hpp"
+#include "algo/encryptor.hpp"
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/util/dummy-client-face.hpp>
#include <ndn-cxx/util/time-unit-test-clock.hpp>
-#include <boost/filesystem.hpp>
#include <boost/asio.hpp>
+#include <boost/filesystem.hpp>
namespace ndn {
namespace gep {
namespace tests {
-static const uint8_t DATA_CONTEN[] = {
- 0xcb, 0xe5, 0x6a, 0x80, 0x41, 0x24, 0x58, 0x23,
- 0x84, 0x14, 0x15, 0x61, 0x80, 0xb9, 0x5e, 0xbd,
- 0xce, 0x32, 0xb4, 0xbe, 0xbc, 0x91, 0x31, 0xd6,
- 0x19, 0x00, 0x80, 0x8b, 0xfa, 0x00, 0x05, 0x9c
-};
+static const uint8_t DATA_CONTEN[] = {0xcb, 0xe5, 0x6a, 0x80, 0x41, 0x24, 0x58, 0x23,
+ 0x84, 0x14, 0x15, 0x61, 0x80, 0xb9, 0x5e, 0xbd,
+ 0xce, 0x32, 0xb4, 0xbe, 0xbc, 0x91, 0x31, 0xd6,
+ 0x19, 0x00, 0x80, 0x8b, 0xfa, 0x00, 0x05, 0x9c};
-static const uint8_t AES_KEY[] = {
- 0xdd, 0x60, 0x77, 0xec, 0xa9, 0x6b, 0x23, 0x1b,
- 0x40, 0x6b, 0x5a, 0xf8, 0x7d, 0x3d, 0x55, 0x32
-};
+static const uint8_t AES_KEY[] =
+ {0xdd, 0x60, 0x77, 0xec, 0xa9, 0x6b, 0x23, 0x1b, 0x40, 0x6b, 0x5a, 0xf8, 0x7d, 0x3d, 0x55, 0x32};
-static const uint8_t IV[] = {
- 0x73, 0x6f, 0x6d, 0x65, 0x72, 0x61, 0x6e, 0x64,
- 0x6f, 0x6d, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72
-};
+static const uint8_t IV[] =
+ {0x73, 0x6f, 0x6d, 0x65, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72};
class ConsumerFixture : public UnitTestTimeFixture
{
@@ -74,13 +68,12 @@
boost::filesystem::create_directories(tmpPath);
// generate e/d key
- RandomNumberGenerator rng;
RsaKeyParams params;
- fixtureDKeyBuf = algo::Rsa::generateKey(rng, params).getKeyBits();
+ fixtureDKeyBuf = algo::Rsa::generateKey(params).getKeyBits();
fixtureEKeyBuf = algo::Rsa::deriveEncryptKey(fixtureDKeyBuf).getKeyBits();
// generate user key
- fixtureUDKeyBuf = algo::Rsa::generateKey(rng, params).getKeyBits();
+ fixtureUDKeyBuf = algo::Rsa::generateKey(params).getKeyBits();
fixtureUEKeyBuf = algo::Rsa::deriveEncryptKey(fixtureUDKeyBuf).getKeyBits();
// load C-KEY
@@ -98,8 +91,13 @@
shared_ptr<Data> contentData = make_shared<Data>(contentName);
algo::EncryptParams eparams(tlv::AlgorithmAesCbc);
eparams.setIV(IV, sizeof(IV));
- algo::encryptData(*contentData, DATA_CONTEN, sizeof(DATA_CONTEN), cKeyName,
- fixtureCKeyBuf.buf(), fixtureCKeyBuf.size(), eparams);
+ algo::encryptData(*contentData,
+ DATA_CONTEN,
+ sizeof(DATA_CONTEN),
+ cKeyName,
+ fixtureCKeyBuf.data(),
+ fixtureCKeyBuf.size(),
+ eparams);
keyChain.sign(*contentData);
return contentData;
}
@@ -109,8 +107,13 @@
{
shared_ptr<Data> cKeyData = make_shared<Data>(cKeyName);
algo::EncryptParams eparams(tlv::AlgorithmRsaOaep);
- algo::encryptData(*cKeyData, fixtureCKeyBuf.buf(), fixtureCKeyBuf.size(), dKeyName,
- fixtureEKeyBuf.buf(), fixtureEKeyBuf.size(), eparams);
+ algo::encryptData(*cKeyData,
+ fixtureCKeyBuf.data(),
+ fixtureCKeyBuf.size(),
+ dKeyName,
+ fixtureEKeyBuf.data(),
+ fixtureEKeyBuf.size(),
+ eparams);
keyChain.sign(*cKeyData);
return cKeyData;
}
@@ -120,8 +123,13 @@
{
shared_ptr<Data> dKeyData = make_shared<Data>(dKeyName);
algo::EncryptParams eparams(tlv::AlgorithmRsaOaep);
- algo::encryptData(*dKeyData, fixtureDKeyBuf.buf(), fixtureDKeyBuf.size(), uKeyName,
- fixtureUEKeyBuf.buf(), fixtureUEKeyBuf.size(), eparams);
+ algo::encryptData(*dKeyData,
+ fixtureDKeyBuf.data(),
+ fixtureDKeyBuf.size(),
+ uKeyName,
+ fixtureUEKeyBuf.data(),
+ fixtureUEKeyBuf.size(),
+ eparams);
keyChain.sign(*dKeyData);
return dKeyData;
}
@@ -202,26 +210,24 @@
// decrypt
consumer.decrypt(cKeyData->getContent().blockFromValue(),
fixtureDKeyBuf,
- [=](const Buffer& result){
- BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(),
+ [=] (const Buffer& result) {
+ BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(),
+ result.end(),
aesKeyBuf.begin(),
aesKeyBuf.end());
},
- [=](const ErrorCode&, const std::string&){
- BOOST_CHECK(false);
- });
+ [=] (const ErrorCode&, const std::string&) { BOOST_CHECK(false); });
// decrypt
consumer.decrypt(contentData->getContent().blockFromValue(),
fixtureCKeyBuf,
- [=](const Buffer& result){
- BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(),
+ [=] (const Buffer& result) {
+ BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(),
+ result.end(),
DATA_CONTEN,
DATA_CONTEN + sizeof(DATA_CONTEN));
},
- [=](const ErrorCode&, const std::string&){
- BOOST_CHECK(false);
- });
+ [=] (const ErrorCode&, const std::string&) { BOOST_CHECK(false); });
}
BOOST_AUTO_TEST_CASE(Consume)
@@ -256,7 +262,7 @@
return;
},
RegisterPrefixSuccessCallback(),
- [] (const Name&, const std::string& e) { });
+ [] (const Name&, const std::string& e) {});
do {
advanceClocks(time::milliseconds(10), 20);
@@ -270,15 +276,14 @@
int finalCount = 0;
consumer.consume(contentName,
- [&](const Data& data, const Buffer& result){
+ [&] (const Data& data, const Buffer& result) {
finalCount = 1;
- BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(), result.end(),
+ BOOST_CHECK_EQUAL_COLLECTIONS(result.begin(),
+ result.end(),
DATA_CONTEN,
DATA_CONTEN + sizeof(DATA_CONTEN));
},
- [&](const ErrorCode& code, const std::string& str){
- BOOST_CHECK(false);
- });
+ [&] (const ErrorCode& code, const std::string& str) { BOOST_CHECK(false); });
do {
advanceClocks(time::milliseconds(10), 20);
@@ -305,7 +310,7 @@
// prepare face1
face1.setInterestFilter(prefix,
[&] (const InterestFilter&, const Interest& i) {
- BOOST_CHECK(i.getLink().getDelegations().size() == 3);
+ BOOST_CHECK(i.getForwardingHint().size() == 3);
if (i.matchesData(*contentData)) {
contentCount++;
face1.put(*contentData);
@@ -324,7 +329,7 @@
return;
},
RegisterPrefixSuccessCallback(),
- [] (const Name&, const std::string& e) { });
+ [] (const Name&, const std::string& e) {});
do {
advanceClocks(time::milliseconds(10), 20);
@@ -345,13 +350,11 @@
consumer.addDecryptionKey(uKeyName, fixtureUDKeyBuf);
consumer.consume(contentName,
- [&](const Data& data, const Buffer& result){
+ [&] (const Data& data, const Buffer& result) {
BOOST_CHECK(true);
resultCount++;
},
- [](const ErrorCode& code, const std::string& str){
- BOOST_CHECK(false);
- },
+ [] (const ErrorCode& code, const std::string& str) { BOOST_CHECK(false); },
datalink);
do {
@@ -366,6 +369,6 @@
BOOST_AUTO_TEST_SUITE_END()
-} // namespace test
+} // namespace tests
} // namespace gep
} // namespace ndn