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/.gitignore b/.gitignore
index 4629c34..349ba35 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
build/
VERSION
unit-tests.conf
+.vscode
diff --git a/src/algo/aes.cpp b/src/algo/aes.cpp
index 6a7d2e0..c71946b 100644
--- a/src/algo/aes.cpp
+++ b/src/algo/aes.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California
+ * Copyright (c) 2014-2018, Regents of the University of California
*
* This file is part of gep (Group-based Encryption Protocol for NDN).
* See AUTHORS.md for complete list of gep authors and contributors.
@@ -17,32 +17,27 @@
* gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <ndn-cxx/encoding/buffer-stream.hpp>
#include "aes.hpp"
#include "error.hpp"
+#include <openssl/rand.h>
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <ndn-cxx/security/transform/buffer-source.hpp>
+#include <ndn-cxx/security/transform/stream-sink.hpp>
namespace ndn {
namespace gep {
namespace algo {
-using namespace CryptoPP;
-
-static Buffer
-transform(CipherModeBase* cipher, const uint8_t* data, size_t dataLen)
-{
- OBufferStream obuf;
- StringSource pipe(data, dataLen, true,
- new StreamTransformationFilter(*cipher, new FileSink(obuf)));
- return *(obuf.buf());
-}
-
DecryptKey<Aes>
-Aes::generateKey(RandomNumberGenerator& rng, AesKeyParams& params)
+Aes::generateKey(AesKeyParams& params)
{
- SecByteBlock key(0x00, params.getKeySize() >> 3); // Converting key bit-size to byte-size.
- rng.GenerateBlock(key.data(), key.size());
+ uint8_t key[32];
- DecryptKey<Aes> decryptKey(Buffer(key.data(), key.size()));
+ int result = RAND_bytes(key, sizeof(key));
+ if (result != 1) {
+ BOOST_THROW_EXCEPTION(Error("Cannot generate 32 bytes random AES key"));
+ }
+ DecryptKey<Aes> decryptKey(Buffer(key, sizeof(key)));
return decryptKey;
}
@@ -59,22 +54,19 @@
const uint8_t* payload, size_t payloadLen,
const EncryptParams& params)
{
- switch (params.getAlgorithmType()) {
- case tlv::AlgorithmAesEcb: {
- ECB_Mode<AES>::Decryption ecbDecryption(key, keyLen);
- return transform(&ecbDecryption, payload, payloadLen);
- }
- case tlv::AlgorithmAesCbc: {
- const Buffer& initVector = params.getIV();
- if (initVector.size() != static_cast<size_t>(AES::BLOCKSIZE))
- throw Error("incorrect initial vector size");
-
- CBC_Mode<AES>::Decryption cbcDecryption(key, keyLen, initVector.get());
- return transform(&cbcDecryption, payload, payloadLen);
- }
- default:
- throw Error("unsupported encryption mode");
+ if (params.getAlgorithmType() != tlv::AlgorithmAesCbc) {
+ BOOST_THROW_EXCEPTION(Error("unsupported AES decryption mode"));
}
+
+ const Buffer& initVector = params.getIV();
+ OBufferStream os;
+ security::transform::bufferSource(payload, payloadLen)
+ >> security::transform::blockCipher(BlockCipherAlgorithm::AES_CBC, CipherOperator::DECRYPT,
+ key, keyLen, initVector.data(), initVector.size())
+ >> security::transform::streamSink(os);
+
+ auto result = os.buf();
+ return *result;
}
Buffer
@@ -82,22 +74,20 @@
const uint8_t* payload, size_t payloadLen,
const EncryptParams& params)
{
- switch (params.getAlgorithmType()) {
- case tlv::AlgorithmAesEcb: {
- ECB_Mode<AES>::Encryption ecbEncryption(key, keyLen);
- return transform(&ecbEncryption, payload, payloadLen);
- }
- case tlv::AlgorithmAesCbc: {
- const Buffer& initVector = params.getIV();
- if (initVector.size() != static_cast<size_t>(AES::BLOCKSIZE))
- throw Error("incorrect initial vector size");
-
- CBC_Mode<AES>::Encryption cbcEncryption(key, keyLen, initVector.get());
- return transform(&cbcEncryption, payload, payloadLen);
- }
- default:
- throw Error("unsupported encryption mode");
+ if (params.getAlgorithmType() != tlv::AlgorithmAesCbc) {
+ BOOST_THROW_EXCEPTION(Error("unsupported AES decryption mode"));
}
+
+ const Buffer& initVector = params.getIV();
+ OBufferStream os;
+ security::transform::bufferSource(payload, payloadLen)
+ >> security::transform::blockCipher(BlockCipherAlgorithm::AES_CBC,
+ CipherOperator::ENCRYPT,
+ key, keyLen, initVector.data(), initVector.size())
+ >> security::transform::streamSink(os);
+
+ auto result = os.buf();
+ return *result;
}
} // namespace algo
diff --git a/src/algo/aes.hpp b/src/algo/aes.hpp
index e4363bf..d0fbabd 100644
--- a/src/algo/aes.hpp
+++ b/src/algo/aes.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California
+ * Copyright (c) 2014-2018, Regents of the University of California
*
* This file is part of gep (Group-based Encryption Protocol for NDN).
* See AUTHORS.md for complete list of gep authors and contributors.
@@ -20,11 +20,11 @@
#ifndef NDN_GEP_ALGO_AES_HPP
#define NDN_GEP_ALGO_AES_HPP
-#include <ndn-cxx/security/key-params.hpp>
-#include "../random-number-generator.hpp"
+#include "common.hpp"
#include "encrypt-params.hpp"
#include "../decrypt-key.hpp"
-
+#include <ndn-cxx/security/transform/block-cipher.hpp>
+#include <ndn-cxx/security/key-params.hpp>
namespace ndn {
namespace gep {
@@ -34,7 +34,7 @@
{
public:
static DecryptKey<Aes>
- generateKey(RandomNumberGenerator& rng, AesKeyParams& params);
+ generateKey(AesKeyParams& params);
static EncryptKey<Aes>
deriveEncryptKey(const Buffer& keyBits);
@@ -57,4 +57,4 @@
} // namespace gep
} // namespace ndn
-#endif // NDN_GEP_ALGO_AES_ECB_HPP
+#endif // NDN_GEP_ALGO_AES_HPP
diff --git a/src/algo/encrypt-params.cpp b/src/algo/encrypt-params.cpp
index dd2afcf..91b5588 100644
--- a/src/algo/encrypt-params.cpp
+++ b/src/algo/encrypt-params.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California
+ * Copyright (c) 2014-2018, Regents of the University of California
*
* This file is part of gep (Group-based Encryption Protocol for NDN).
* See AUTHORS.md for complete list of gep authors and contributors.
@@ -17,8 +17,9 @@
* gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "../random-number-generator.hpp"
#include "encrypt-params.hpp"
+#include "error.hpp"
+#include <openssl/rand.h>
namespace ndn {
namespace gep {
@@ -27,10 +28,12 @@
EncryptParams::EncryptParams(tlv::AlgorithmTypeValue algorithm, uint8_t ivLength)
: m_algo(algorithm)
{
- if (ivLength != 0){
- RandomNumberGenerator rng;
+ if (ivLength != 0) {
m_iv.resize(ivLength);
- rng.GenerateBlock(m_iv.buf(), m_iv.size());
+ int result = RAND_bytes(m_iv.data(), m_iv.size());
+ if (result != 1) {
+ BOOST_THROW_EXCEPTION(Error("Cannot generate random IV"));
+ }
}
}
diff --git a/src/algo/encrypt-params.hpp b/src/algo/encrypt-params.hpp
index 0aa03b2..030f443 100644
--- a/src/algo/encrypt-params.hpp
+++ b/src/algo/encrypt-params.hpp
@@ -1,8 +1,27 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2018, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep 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.
+ *
+ * gep 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 a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#ifndef NDN_GEP_ENCRYPT_PARAMS_HPP
#define NDN_GEP_ENCRYPT_PARAMS_HPP
-#include <ndn-cxx/encoding/buffer-stream.hpp>
#include "../tlv.hpp"
+#include <ndn-cxx/encoding/buffer-stream.hpp>
namespace ndn {
namespace gep {
diff --git a/src/algo/encryptor.cpp b/src/algo/encryptor.cpp
index 68b0d82..c9f7745 100644
--- a/src/algo/encryptor.cpp
+++ b/src/algo/encryptor.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -18,19 +18,16 @@
*/
#include "encryptor.hpp"
-#include "../random-number-generator.hpp"
-#include "../encrypted-content.hpp"
#include "aes.hpp"
#include "rsa.hpp"
-
+#include "../encrypted-content.hpp"
#include "error.hpp"
+#include <openssl/rand.h>
namespace ndn {
namespace gep {
namespace algo {
-using namespace CryptoPP;
-
/**
* @brief Helper method for symmetric encryption
*
@@ -39,27 +36,28 @@
* @return An EncryptedContent
*/
static EncryptedContent
-encryptSymmetric(const uint8_t* payload, size_t payloadLen,
- const uint8_t* key, size_t keyLen,
- const Name& keyName, const EncryptParams& params)
+encryptSymmetric(const uint8_t* payload,
+ size_t payloadLen,
+ const uint8_t* key,
+ size_t keyLen,
+ const Name& keyName,
+ const EncryptParams& params)
{
tlv::AlgorithmTypeValue algType = params.getAlgorithmType();
const Buffer& iv = params.getIV();
KeyLocator keyLocator(keyName);
switch (algType) {
- case tlv::AlgorithmAesEcb: {
- const Buffer& encryptedPayload = Aes::encrypt(key, keyLen, payload, payloadLen, params);
- return EncryptedContent(algType, keyLocator, encryptedPayload.buf(), encryptedPayload.size(), iv.buf(), iv.size());
- }
case tlv::AlgorithmAesCbc: {
- BOOST_ASSERT(iv.size() == static_cast<size_t>(AES::BLOCKSIZE));
const Buffer& encryptedPayload = Aes::encrypt(key, keyLen, payload, payloadLen, params);
- return EncryptedContent(algType, keyLocator, encryptedPayload.buf(), encryptedPayload.size(), iv.buf(), iv.size());
+ return EncryptedContent(algType, keyLocator,
+ encryptedPayload.data(),
+ encryptedPayload.size(),
+ iv.data(), iv.size());
}
default: {
BOOST_ASSERT(false);
- throw algo::Error("Unsupported encryption method");
+ BOOST_THROW_EXCEPTION(algo::Error("Unsupported encryption method"));
}
}
}
@@ -75,7 +73,8 @@
static EncryptedContent
encryptAsymmetric(const uint8_t* payload, size_t payloadLen,
const uint8_t* key, size_t keyLen,
- const Name& keyName, const EncryptParams& params)
+ const Name& keyName,
+ const EncryptParams& params)
{
tlv::AlgorithmTypeValue algType = params.getAlgorithmType();
KeyLocator keyLocator(keyName);
@@ -83,12 +82,12 @@
switch (algType) {
case tlv::AlgorithmRsaPkcs:
case tlv::AlgorithmRsaOaep: {
- Buffer encryptedPayload = Rsa::encrypt(key, keyLen, payload, payloadLen, params);
- return EncryptedContent(algType, keyLocator, encryptedPayload.buf(), encryptedPayload.size());
+ Buffer encryptedPayload = Rsa::encrypt(key, keyLen, payload, payloadLen);
+ return EncryptedContent(algType, keyLocator, encryptedPayload.data(), encryptedPayload.size());
}
default: {
BOOST_ASSERT(false);
- throw algo::Error("Unsupported encryption method");
+ BOOST_THROW_EXCEPTION(algo::Error("Unsupported encryption method"));
}
}
}
@@ -101,39 +100,33 @@
Name dataName = data.getName();
dataName.append(NAME_COMPONENT_FOR).append(keyName);
data.setName(dataName);
- switch(params.getAlgorithmType()) {
+ switch (params.getAlgorithmType()) {
case tlv::AlgorithmAesCbc:
case tlv::AlgorithmAesEcb: {
- const EncryptedContent& content = encryptSymmetric(payload, payloadLen, key, keyLen, keyName, params);
+ const EncryptedContent& content =
+ encryptSymmetric(payload, payloadLen, key, keyLen, keyName, params);
data.setContent(content.wireEncode());
break;
}
case tlv::AlgorithmRsaPkcs:
case tlv::AlgorithmRsaOaep: {
- size_t maxPlaintextLength = 0;
- RSA::PublicKey publicKey;
- ByteQueue keyQueue;
-
- keyQueue.LazyPut(key, keyLen);
- publicKey.Load(keyQueue);
- RSAES_PKCS1v15_Encryptor enc(publicKey);
- maxPlaintextLength = enc.FixedMaxPlaintextLength();
-
- if (maxPlaintextLength < payloadLen) {
- RandomNumberGenerator rng;
- SecByteBlock nonceKey(0x00, 16); // 128 bits key.
- rng.GenerateBlock(nonceKey.data(), nonceKey.size());
+ if (payloadLen > keyLen - 11) {
+ uint8_t nonceKey[16];
+ int result = RAND_bytes(nonceKey, sizeof(nonceKey));
+ if (result != 1) {
+ BOOST_THROW_EXCEPTION(Error("Cannot generate 32 bytes random AES key"));
+ }
Name nonceKeyName(keyName);
nonceKeyName.append("nonce");
- EncryptParams symParams(tlv::AlgorithmAesCbc, AES::BLOCKSIZE);
+ EncryptParams symParams(tlv::AlgorithmAesCbc, 16);
const EncryptedContent& nonceContent =
- encryptSymmetric(payload, payloadLen, nonceKey.data(), nonceKey.size(), nonceKeyName, symParams);
+ encryptSymmetric(payload, payloadLen, nonceKey, sizeof(nonceKey), nonceKeyName, symParams);
const EncryptedContent& payloadContent =
- encryptAsymmetric(nonceKey.data(), nonceKey.size(), key, keyLen, keyName, params);
+ encryptAsymmetric(nonceKey, sizeof(nonceKey), key, keyLen, keyName, params);
Block content(tlv::Content);
content.push_back(payloadContent.wireEncode());
@@ -143,13 +136,14 @@
return;
}
else {
- const EncryptedContent& content = encryptAsymmetric(payload, payloadLen, key, keyLen, keyName, params);
+ const EncryptedContent& content =
+ encryptAsymmetric(payload, payloadLen, key, keyLen, keyName, params);
data.setContent(content.wireEncode());
return;
}
}
default:
- throw algo::Error("Unsupported encryption method");
+ BOOST_THROW_EXCEPTION(algo::Error("Unsupported encryption method"));
}
}
diff --git a/src/algo/encryptor.hpp b/src/algo/encryptor.hpp
index 04556b9..4dde07e 100644
--- a/src/algo/encryptor.hpp
+++ b/src/algo/encryptor.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -20,8 +20,8 @@
#ifndef NDN_ENCRYPTOR_HPP
#define NDN_ENCRYPTOR_HPP
-#include <ndn-cxx/data.hpp>
#include "encrypt-params.hpp"
+#include <ndn-cxx/data.hpp>
namespace ndn {
namespace gep {
@@ -39,8 +39,12 @@
* a nonce in the content of @p data.
*/
void
-encryptData(Data& data, const uint8_t* payload, size_t payloadLen,
- const Name& keyName, const uint8_t* key, size_t keyLen,
+encryptData(Data& data,
+ const uint8_t* payload,
+ size_t payloadLen,
+ const Name& keyName,
+ const uint8_t* key,
+ size_t keyLen,
const EncryptParams& params);
} // namespace algo
diff --git a/src/algo/error.hpp b/src/algo/error.hpp
index 4cb46b1..d9abdb2 100644
--- a/src/algo/error.hpp
+++ b/src/algo/error.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California
+ * Copyright (c) 2014-2018, Regents of the University of California
*
* This file is part of gep (Group-based Encryption Protocol for NDN).
* See AUTHORS.md for complete list of gep authors and contributors.
diff --git a/src/algo/rsa.cpp b/src/algo/rsa.cpp
index f5fe848..85f4498 100644
--- a/src/algo/rsa.cpp
+++ b/src/algo/rsa.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California
+ * Copyright (c) 2014-2018, Regents of the University of California
*
* This file is part of gep (Group-based Encryption Protocol for NDN).
* See AUTHORS.md for complete list of gep authors and contributors.
@@ -17,111 +17,66 @@
* gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <ndn-cxx/encoding/buffer-stream.hpp>
#include "rsa.hpp"
#include "error.hpp"
+#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <ndn-cxx/security/transform/private-key.hpp>
+#include <ndn-cxx/security/transform/public-key.hpp>
namespace ndn {
namespace gep {
namespace algo {
-using namespace CryptoPP;
-
-static Buffer
-transform(SimpleProxyFilter* filter, const uint8_t* data, size_t dataLen)
-{
- OBufferStream obuf;
- filter->Attach(new FileSink(obuf));
-
- StringSource pipe(data, dataLen, true, filter);
- return *(obuf.buf());
-}
-
DecryptKey<Rsa>
-Rsa::generateKey(RandomNumberGenerator& rng, RsaKeyParams& params)
+Rsa::generateKey(RsaKeyParams& params)
{
- RSA::PrivateKey privateKey;
- privateKey.GenerateRandomWithKeySize(rng, params.getKeySize());
+ auto privateKey = security::transform::generatePrivateKey(params);
- OBufferStream obuf;
- privateKey.Save(FileSink(obuf).Ref());
+ OBufferStream os;
+ privateKey->savePkcs1(os);
- DecryptKey<Rsa> decryptKey(std::move(*obuf.buf()));
+ DecryptKey<Rsa> decryptKey(std::move(*os.buf()));
return decryptKey;
}
EncryptKey<Rsa>
Rsa::deriveEncryptKey(const Buffer& keyBits)
{
- RSA::PrivateKey privateKey;
+ security::transform::PrivateKey sKey;
+ sKey.loadPkcs1(keyBits.get<uint8_t>(), keyBits.size());
- ByteQueue keyQueue;
- keyQueue.LazyPut(keyBits.get(), keyBits.size());
- privateKey.Load(keyQueue);
+ ConstBufferPtr pKeyBits = sKey.derivePublicKey();
+ security::transform::PublicKey pKey;
+ pKey.loadPkcs8(pKeyBits->data(), pKeyBits->size());
- RSA::PublicKey publicKey(privateKey);
+ OBufferStream os;
+ pKey.savePkcs8(os);
- OBufferStream obuf;
- publicKey.Save(FileSink(obuf).Ref());
-
- EncryptKey<Rsa> encryptKey(std::move(*obuf.buf()));
+ EncryptKey<Rsa> encryptKey(std::move(*os.buf()));
return encryptKey;
}
Buffer
Rsa::decrypt(const uint8_t* key, size_t keyLen,
- const uint8_t* payload, size_t payloadLen,
- const EncryptParams& params)
+ const uint8_t* payload, size_t payloadLen)
{
- AutoSeededRandomPool rng;
- RSA::PrivateKey privateKey;
- ByteQueue keyQueue;
- keyQueue.LazyPut(key, keyLen);
- privateKey.Load(keyQueue);
+ security::transform::PrivateKey sKey;
+ sKey.loadPkcs1(key, keyLen);
- switch (params.getAlgorithmType()) {
- case tlv::AlgorithmRsaPkcs: {
- RSAES_PKCS1v15_Decryptor decryptor_pkcs1v15(privateKey);
- PK_DecryptorFilter* filter_pkcs1v15 = new PK_DecryptorFilter(rng, decryptor_pkcs1v15);
- return transform(filter_pkcs1v15, payload, payloadLen);
- }
- case tlv::AlgorithmRsaOaep: {
- RSAES_OAEP_SHA_Decryptor decryptor_oaep_sha(privateKey);
- PK_DecryptorFilter* filter_oaep_sha = new PK_DecryptorFilter(rng, decryptor_oaep_sha);
- return transform(filter_oaep_sha, payload, payloadLen);
- }
- default:
- throw Error("unsupported padding scheme");
- }
+ auto decrypted = sKey.decrypt(payload, payloadLen);
+ return *decrypted;
}
Buffer
Rsa::encrypt(const uint8_t* key, size_t keyLen,
- const uint8_t* payload, size_t payloadLen,
- const EncryptParams& params)
+ const uint8_t* payload, size_t payloadLen)
{
- AutoSeededRandomPool rng;
- RSA::PublicKey publicKey;
+ security::transform::PublicKey pKey;
+ pKey.loadPkcs8(key, keyLen);
- ByteQueue keyQueue;
- keyQueue.LazyPut(key, keyLen);
- publicKey.Load(keyQueue);
-
- switch (params.getAlgorithmType()) {
- case tlv::AlgorithmRsaPkcs: {
- RSAES_PKCS1v15_Encryptor encryptor_pkcs1v15(publicKey);
- PK_EncryptorFilter* filter_pkcs1v15 = new PK_EncryptorFilter(rng, encryptor_pkcs1v15);
- return transform(filter_pkcs1v15, payload, payloadLen);
- }
- case tlv::AlgorithmRsaOaep: {
- RSAES_OAEP_SHA_Encryptor encryptor_oaep_sha(publicKey);
- PK_EncryptorFilter* filter_oaep_sha = new PK_EncryptorFilter(rng, encryptor_oaep_sha);
- return transform(filter_oaep_sha, payload, payloadLen);
- }
- default:
- throw Error("unsupported padding scheme");
- }
+ auto cipherText = pKey.encrypt(payload, payloadLen);
+ return *cipherText;
}
} // namespace algo
diff --git a/src/algo/rsa.hpp b/src/algo/rsa.hpp
index 3e64688..db44474 100644
--- a/src/algo/rsa.hpp
+++ b/src/algo/rsa.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, Regents of the University of California
+ * Copyright (c) 2014-2018, Regents of the University of California
*
* This file is part of gep (Group-based Encryption Protocol for NDN).
* See AUTHORS.md for complete list of gep authors and contributors.
@@ -20,10 +20,9 @@
#ifndef NDN_GEP_ALGO_RSA_HPP
#define NDN_GEP_ALGO_RSA_HPP
-#include <ndn-cxx/security/key-params.hpp>
-#include "../random-number-generator.hpp"
#include "encrypt-params.hpp"
#include "../decrypt-key.hpp"
+#include <ndn-cxx/security/key-params.hpp>
namespace ndn {
namespace gep {
@@ -33,20 +32,18 @@
{
public:
static DecryptKey<Rsa>
- generateKey(RandomNumberGenerator& rng, RsaKeyParams& params);
+ generateKey(RsaKeyParams& params);
static EncryptKey<Rsa>
deriveEncryptKey(const Buffer& keyBits);
static Buffer
decrypt(const uint8_t* key, size_t keyLen,
- const uint8_t* payload, size_t payloadLen,
- const EncryptParams& params);
+ const uint8_t* payload, size_t payloadLen);
static Buffer
encrypt(const uint8_t* key, size_t keyLen,
- const uint8_t* payload, size_t payloadLen,
- const EncryptParams& params);
+ const uint8_t* payload, size_t payloadLen);
};
typedef DecryptKey<Rsa> RsaPrivateKey;
diff --git a/src/common.hpp b/src/common.hpp
index 8844b72..14bca91 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -46,16 +46,22 @@
#include <cstddef>
#include <list>
#include <map>
-#include <set>
#include <queue>
+#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <ndn-cxx/common.hpp>
-#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/data.hpp>
+#include <ndn-cxx/interest.hpp>
#include <ndn-cxx/util/signal.hpp>
+#include <ndn-cxx/link.hpp>
+
+#include <ndn-cxx/security/v2/validation-callback.hpp>
+#include <ndn-cxx/security/v2/validation-error.hpp>
+#include <ndn-cxx/security/v2/validator.hpp>
+#include <ndn-cxx/security/validator-null.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
@@ -93,6 +99,13 @@
using ndn::Exclude;
using ndn::Block;
+using security::v2::Certificate;
+using ndn::security::v2::Validator;
+using ndn::security::ValidatorNull;
+using security::v2::DataValidationSuccessCallback;
+using security::v2::DataValidationFailureCallback;
+using security::v2::ValidationError;
+
namespace tlv {
using namespace ndn::tlv;
} // namespace tlv
diff --git a/src/consumer-db.cpp b/src/consumer-db.cpp
index e2898ac..661ab04 100644
--- a/src/consumer-db.cpp
+++ b/src/consumer-db.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,29 +16,29 @@
* 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>
*/
#include "consumer-db.hpp"
-
-#include <sqlite3.h>
-#include <boost/filesystem.hpp>
#include <ndn-cxx/util/sqlite3-statement.hpp>
+#include <boost/filesystem.hpp>
+#include <sqlite3.h>
namespace ndn {
namespace gep {
using util::Sqlite3Statement;
-static const std::string INITIALIZATION =
- "CREATE TABLE IF NOT EXISTS \n"
- " decryptionkeys( \n"
- " key_id INTEGER PRIMARY KEY, \n"
- " key_name BLOB NOT NULL, \n"
- " key_buf BLOB NOT NULL \n"
- " ); \n"
- "CREATE UNIQUE INDEX IF NOT EXISTS \n"
- " KeyNameIndex ON decryptionkeys(key_name); \n";
+static const std::string INITIALIZATION = R"_DBTEXT_(
+CREATE TABLE IF NOT EXISTS
+ decryptionkeys(
+ key_id INTEGER PRIMARY KEY,
+ key_name BLOB NOT NULL,
+ key_buf BLOB NOT NULL
+ );
+CREATE UNIQUE INDEX IF NOT EXISTS
+ KeyNameIndex ON decryptionkeys(key_name);
+)_DBTEXT_";
class ConsumerDB::Impl
{
@@ -47,14 +47,10 @@
{
// open Database
- int result = sqlite3_open_v2(dbPath.c_str(), &m_database,
+ int result = sqlite3_open_v2(dbPath.c_str(),
+ &m_database,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
-#ifdef NDN_CXX_DISABLE_SQLITE3_FS_LOCKING
- "unix-dotfile"
-#else
- nullptr
-#endif
- );
+ nullptr);
if (result != SQLITE_OK)
BOOST_THROW_EXCEPTION(Error("GroupManager DB cannot be opened/created: " + dbPath));
@@ -89,8 +85,8 @@
ConsumerDB::getKey(const Name& keyName) const
{
Sqlite3Statement statement(m_impl->m_database,
- "SELECT key_buf FROM decryptionkeys\
- WHERE key_name=?");
+ R"_DBTEXT_(SELECT key_buf FROM decryptionkeys
+ WHERE key_name=?)_DBTEXT_");
statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
Buffer result;
@@ -104,10 +100,10 @@
ConsumerDB::addKey(const Name& keyName, const Buffer& keyBuf)
{
Sqlite3Statement statement(m_impl->m_database,
- "INSERT INTO decryptionkeys(key_name, key_buf)\
- values (?, ?)");
+ R"_DBTEXT_(INSERT INTO decryptionkeys(key_name, key_buf)
+ values (?, ?))_DBTEXT_");
statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
- statement.bind(2, keyBuf.buf(), keyBuf.size(), SQLITE_TRANSIENT);
+ statement.bind(2, keyBuf.data(), keyBuf.size(), SQLITE_TRANSIENT);
if (statement.step() != SQLITE_DONE)
BOOST_THROW_EXCEPTION(Error("Cannot add the key to database"));
@@ -117,7 +113,7 @@
ConsumerDB::deleteKey(const Name& keyName)
{
Sqlite3Statement statement(m_impl->m_database,
- "DELETE FROM decryptionkeys WHERE key_name=?");
+ R"_DBTEXT_(DELETE FROM decryptionkeys WHERE key_name=?)_DBTEXT_");
statement.bind(1, keyName.wireEncode(), SQLITE_TRANSIENT);
statement.step();
}
diff --git a/src/consumer-db.hpp b/src/consumer-db.hpp
index 61646e8..8500b67 100644
--- a/src/consumer-db.hpp
+++ b/src/consumer-db.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
diff --git a/src/consumer.cpp b/src/consumer.cpp
index 1d0477c..4470089 100644
--- a/src/consumer.cpp
+++ b/src/consumer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
@@ -30,7 +30,8 @@
// public
Consumer::Consumer(Face& face,
- const Name& groupName, const Name& consumerName,
+ const Name& groupName,
+ const Name& consumerName,
const std::string& dbPath,
const Link& cKeyLink,
const Link& dKeyLink)
@@ -67,12 +68,11 @@
shared_ptr<Interest> interest = make_shared<Interest>(contentName);
// prepare callback functions
- auto validationCallback =
- [=] (const shared_ptr<const Data>& validData) {
- // decrypt content
- decryptContent(*validData,
- [=] (const Buffer& plainText) { consumptionCallBack(*validData, plainText); },
- errorCallback);
+ auto validationCallback = [=] (const Data& validData) {
+ // decrypt content
+ decryptContent(validData,
+ [=] (const Buffer& plainText) { consumptionCallBack(validData, plainText); },
+ errorCallback);
};
sendInterest(*interest, 1, link, validationCallback, errorCallback);
@@ -93,24 +93,19 @@
case tlv::AlgorithmAesCbc: {
// prepare parameter
algo::EncryptParams decryptParams(tlv::AlgorithmAesCbc);
- decryptParams.setIV(encryptedContent.getInitialVector().buf(),
+ decryptParams.setIV(encryptedContent.getInitialVector().data(),
encryptedContent.getInitialVector().size());
// decrypt content
- Buffer content = algo::Aes::decrypt(keyBits.buf(), keyBits.size(),
- payload.buf(), payload.size(),
- decryptParams);
+ Buffer content = algo::Aes::decrypt(keyBits.data(), keyBits.size(),
+ payload.data(), payload.size(), decryptParams);
plainTextCallBack(content);
break;
}
case tlv::AlgorithmRsaOaep: {
- // prepare parameter
- algo::EncryptParams decryptParams(tlv::AlgorithmRsaOaep);
-
// decrypt content
- Buffer content = algo::Rsa::decrypt(keyBits.buf(), keyBits.size(),
- payload.buf(), payload.size(),
- decryptParams);
+ Buffer content = algo::Rsa::decrypt(keyBits.data(), keyBits.size(),
+ payload.data(), payload.size());
plainTextCallBack(content);
break;
}
@@ -143,10 +138,9 @@
shared_ptr<Interest> interest = make_shared<Interest>(interestName);
// prepare callback functions
- auto validationCallback =
- [=] (const shared_ptr<const Data>& validCKeyData) {
+ DataValidationSuccessCallback validationCallback = [=] (const Data& validCKeyData) {
// decrypt content
- decryptCKey(*validCKeyData,
+ decryptCKey(validCKeyData,
[=] (const Buffer& cKeyBits) {
decrypt(encryptedContent, cKeyBits, plainTextCallBack, errorCallback);
this->m_cKeyMap.insert(std::make_pair(cKeyName, cKeyBits));
@@ -183,10 +177,9 @@
shared_ptr<Interest> interest = make_shared<Interest>(interestName);
// prepare callback functions
- auto validationCallback =
- [=] (const shared_ptr<const Data>& validDKeyData) {
+ DataValidationSuccessCallback validationCallback = [=] (const Data& validDKeyData) {
// decrypt content
- decryptDKey(*validDKeyData,
+ decryptDKey(validDKeyData,
[=] (const Buffer& dKeyBits) {
decrypt(cKeyContent, dKeyBits, plainTextCallBack, errorCallback);
this->m_dKeyMap.insert(std::make_pair(dKeyName, dKeyBits));
@@ -219,8 +212,7 @@
// get consumer decryption key
Buffer consumerKeyBuf = getDecryptionKey(consumerKeyName);
if (consumerKeyBuf.empty()) {
- errorCallback(ErrorCode::NoDecryptKey,
- "No desired consumer decryption key in database");
+ errorCallback(ErrorCode::NoDecryptKey, "No desired consumer decryption key in database");
return;
}
@@ -229,7 +221,8 @@
Block encryptedPayloadBlock = *it;
// decrypt d-key
- decrypt(encryptedNonceBlock, consumerKeyBuf,
+ decrypt(encryptedNonceBlock,
+ consumerKeyBuf,
[&] (const Buffer& nonceKeyBits) {
decrypt(encryptedPayloadBlock, nonceKeyBits, plainTextCallBack, errorCallback);
},
@@ -243,45 +236,52 @@
}
void
-Consumer::sendInterest(const Interest& interest, int nRetrials,
+Consumer::sendInterest(const Interest& interest,
+ int nRetrials,
const Link& link,
- const OnDataValidated& validationCallback,
+ const DataValidationSuccessCallback& validationCallback,
const ErrorCallBack& errorCallback)
{
auto dataCallback = [=] (const Interest& contentInterest, const Data& contentData) {
if (!contentInterest.matchesData(contentData))
return;
-
- this->m_validator->validate(contentData, validationCallback,
- [=] (const shared_ptr<const Data>& d, const std::string& e) {
- errorCallback(ErrorCode::Validation, e);
- });
+ DataValidationFailureCallback onValidationFailure = [=] (const Data& data,
+ const ValidationError& error) {
+ errorCallback(ErrorCode::Validation, error.getInfo());
+ };
+ this->m_validator->validate(contentData, validationCallback, onValidationFailure);
};
// set link object if it is available
Interest request(interest);
- if (!link.getDelegations().empty()) {
- request.setLink(link.wireEncode());
+ if (!link.getDelegationList().empty()) {
+ request.setForwardingHint(link.getDelegationList());
}
m_face.expressInterest(request, dataCallback,
- std::bind(&Consumer::handleNack, this, _1, _2,
- link, validationCallback, errorCallback),
- std::bind(&Consumer::handleTimeout, this, _1, nRetrials,
- link, validationCallback, errorCallback));
+ std::bind(&Consumer::handleNack, this, _1, _2, link,
+ validationCallback, errorCallback),
+ std::bind(&Consumer::handleTimeout, this, _1, nRetrials, link,
+ validationCallback, errorCallback));
}
void
-Consumer::handleNack(const Interest& interest, const lp::Nack& nack, const Link& link,
- const OnDataValidated& callback, const ErrorCallBack& errorCallback)
+Consumer::handleNack(const Interest& interest,
+ const lp::Nack& nack,
+ const Link& link,
+ const DataValidationSuccessCallback& callback,
+ const ErrorCallBack& errorCallback)
{
// we run out of options, report retrieval failure.
errorCallback(ErrorCode::DataRetrievalFailure, interest.getName().toUri());
}
void
-Consumer::handleTimeout(const Interest& interest, int nRetrials, const Link& link,
- const OnDataValidated& callback, const ErrorCallBack& errorCallback)
+Consumer::handleTimeout(const Interest& interest,
+ int nRetrials,
+ const Link& link,
+ const DataValidationSuccessCallback& callback,
+ const ErrorCallBack& errorCallback)
{
if (nRetrials > 0) {
sendInterest(interest, nRetrials - 1, link, callback, errorCallback);
diff --git a/src/consumer.hpp b/src/consumer.hpp
index 4c7ee91..777425d 100644
--- a/src/consumer.hpp
+++ b/src/consumer.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,25 +16,25 @@
* 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>
*/
#ifndef NDN_GEP_CONSUMER_HPP
#define NDN_GEP_CONSUMER_HPP
-#include "algo/rsa.hpp"
-#include "algo/aes.hpp"
+#include "common.hpp"
#include "consumer-db.hpp"
#include "error-code.hpp"
-
-#include <ndn-cxx/security/validator-null.hpp>
+#include "algo/aes.hpp"
+#include "algo/rsa.hpp"
#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/validator-null.hpp>
namespace ndn {
namespace gep {
-typedef function<void (const Data&, const Buffer&)> ConsumptionCallBack;
+typedef function<void(const Data&, const Buffer&)> ConsumptionCallBack;
/**
* @brief Consumer in group-based encryption protocol
@@ -42,7 +42,7 @@
class Consumer
{
private:
- typedef function<void (const Buffer&)> PlainTextCallBack;
+ typedef function<void(const Buffer&)> PlainTextCallBack;
public:
/**
@@ -55,8 +55,12 @@
* @param cKeyLink The link object for C-KEY retrieval
* @param dKeyLink The link object for D-KEY retrieval
*/
- Consumer(Face& face, const Name& groupName, const Name& consumerName, const std::string& dbPath,
- const Link& cKeyLink = NO_LINK, const Link& dKeyLink = NO_LINK);
+ Consumer(Face& face,
+ const Name& groupName,
+ const Name& consumerName,
+ const std::string& dbPath,
+ const Link& cKeyLink = NO_LINK,
+ const Link& dKeyLink = NO_LINK);
/**
* @brief Send out the Interest packet to fetch content packet with @p dataName.
@@ -85,7 +89,6 @@
addDecryptionKey(const Name& keyName, const Buffer& keyBuf);
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
-
/**
* @brief Decrypt @p encryptedBlock using @p keyBits
*
@@ -149,9 +152,10 @@
* @param errorCallback The callback when error happens
*/
void
- sendInterest(const Interest& interest, int nRetrials,
+ sendInterest(const Interest& interest,
+ int nRetrials,
const Link& link,
- const OnDataValidated& validationCallback,
+ const DataValidationSuccessCallback& validationCallback,
const ErrorCallBack& errorCallback);
/**
@@ -167,9 +171,10 @@
* @param errorCallback The callback when error happens
*/
void
- handleNack(const Interest& interest, const lp::Nack& nack,
+ handleNack(const Interest& interest,
+ const lp::Nack& nack,
const Link& link,
- const OnDataValidated& validationCallback,
+ const DataValidationSuccessCallback& validationCallback,
const ErrorCallBack& errorCallback);
/**
@@ -185,9 +190,10 @@
* @param errorCallback The callback when error happens
*/
void
- handleTimeout(const Interest& interest, int nRetrials,
+ handleTimeout(const Interest& interest,
+ int nRetrials,
const Link& link,
- const OnDataValidated& validationCallback,
+ const DataValidationSuccessCallback& validationCallback,
const ErrorCallBack& errorCallback);
public:
diff --git a/src/cryptopp.hpp b/src/cryptopp.hpp
deleted file mode 100644
index a7a1ae8..0000000
--- a/src/cryptopp.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, 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.
- *
- * ndn-group-encrypt 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.
- *
- * ndn-group-encrypt 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 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/>.
- */
-
-#ifndef NDN_GEP_CRYPTOPP_HPP
-#define NDN_GEP_CRYPTOPP_HPP
-
-// suppress CryptoPP warnings
-#pragma GCC system_header
-#pragma clang system_header
-
-#include <cryptopp/asn.h>
-#include <cryptopp/base64.h>
-#include <cryptopp/des.h>
-#include <cryptopp/files.h>
-#include <cryptopp/filters.h>
-#include <cryptopp/hex.h>
-#include <cryptopp/modes.h>
-#include <cryptopp/osrng.h>
-#include <cryptopp/pssr.h>
-#include <cryptopp/pwdbased.h>
-#include <cryptopp/rsa.h>
-#include <cryptopp/sha.h>
-#include <cryptopp/eccrypto.h>
-#include <cryptopp/oids.h>
-#include <cryptopp/dsa.h>
-#include <cryptopp/cryptlib.h>
-
-#endif // NDN_GEP_CRYPTOPP_HPP
diff --git a/src/encrypted-content.cpp b/src/encrypted-content.cpp
index 3e0879f..68d0e9c 100644
--- a/src/encrypted-content.cpp
+++ b/src/encrypted-content.cpp
@@ -1,7 +1,28 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2018, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep 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.
+ *
+ * gep 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 a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Yingdi Yu <yingdi@cs.ucla.edu>
+ * @author Zhiyi Zhang <zhiyi@cs.ucla.edu>
+ */
+
#include "encrypted-content.hpp"
#include <ndn-cxx/encoding/block-helpers.hpp>
#include <ndn-cxx/util/concepts.hpp>
-
#include <boost/lexical_cast.hpp>
namespace ndn {
@@ -19,9 +40,12 @@
{
}
-EncryptedContent::EncryptedContent(tlv::AlgorithmTypeValue type, const KeyLocator& keyLocator,
- const uint8_t* payload, size_t payloadLen,
- const uint8_t* iv, size_t ivLen)
+EncryptedContent::EncryptedContent(tlv::AlgorithmTypeValue type,
+ const KeyLocator& keyLocator,
+ const uint8_t* payload,
+ size_t payloadLen,
+ const uint8_t* iv,
+ size_t ivLen)
: m_type(type)
, m_hasKeyLocator(true)
, m_keyLocator(keyLocator)
@@ -57,7 +81,7 @@
if (m_hasKeyLocator)
return m_keyLocator;
else
- throw Error("KeyLocator does not exist");
+ BOOST_THROW_EXCEPTION(Error("KeyLocator does not exist"));
}
void
@@ -93,23 +117,24 @@
size_t totalLength = 0;
if (m_payload.size() != 0)
- totalLength += block.prependByteArrayBlock(tlv::EncryptedPayload, m_payload.buf(), m_payload.size());
+ totalLength +=
+ block.prependByteArrayBlock(tlv::EncryptedPayload, m_payload.data(), m_payload.size());
else
- throw Error("EncryptedContent does not have a payload");
+ BOOST_THROW_EXCEPTION(Error("EncryptedContent does not have a payload"));
if (m_iv.size() != 0) {
- totalLength += block.prependByteArrayBlock(tlv::InitialVector, m_iv.buf(), m_iv.size());
+ totalLength += block.prependByteArrayBlock(tlv::InitialVector, m_iv.data(), m_iv.size());
}
if (m_type != -1)
totalLength += prependNonNegativeIntegerBlock(block, tlv::EncryptionAlgorithm, m_type);
else
- throw Error("EncryptedContent does not have an encryption algorithm");
+ BOOST_THROW_EXCEPTION(Error("EncryptedContent does not have an encryption algorithm"));
if (m_hasKeyLocator)
totalLength += m_keyLocator.wireEncode(block);
else
- throw Error("EncryptedContent does not have a key locator");
+ BOOST_THROW_EXCEPTION(Error("EncryptedContent does not have a key locator"));
totalLength += block.prependVarNumber(totalLength);
totalLength += block.prependVarNumber(tlv::EncryptedContent);
@@ -136,7 +161,7 @@
EncryptedContent::wireDecode(const Block& wire)
{
if (!wire.hasWire()) {
- throw Error("The supplied block does not contain wire format");
+ BOOST_THROW_EXCEPTION(Error("The supplied block does not contain wire format"));
}
m_hasKeyLocator = false;
@@ -145,7 +170,7 @@
m_wire.parse();
if (m_wire.type() != tlv::EncryptedContent)
- throw Error("Unexpected TLV type when decoding Name");
+ BOOST_THROW_EXCEPTION(Error("Unexpected TLV type when decoding Name"));
Block::element_const_iterator it = m_wire.elements_begin();
@@ -155,14 +180,14 @@
it++;
}
else
- throw Error("EncryptedContent does not have key locator");
+ BOOST_THROW_EXCEPTION(Error("EncryptedContent does not have key locator"));
if (it != m_wire.elements_end() && it->type() == tlv::EncryptionAlgorithm) {
m_type = readNonNegativeInteger(*it);
it++;
}
else
- throw Error("EncryptedContent does not have encryption algorithm");
+ BOOST_THROW_EXCEPTION(Error("EncryptedContent does not have encryption algorithm"));
if (it != m_wire.elements_end() && it->type() == tlv::InitialVector) {
m_iv = Buffer(it->value_begin(), it->value_end());
@@ -176,10 +201,10 @@
it++;
}
else
- throw Error("EncryptedContent has missing payload");
+ BOOST_THROW_EXCEPTION(Error("EncryptedContent has missing payload"));
if (it != m_wire.elements_end()) {
- throw Error("EncryptedContent has extraneous sub-TLVs");
+ BOOST_THROW_EXCEPTION(Error("EncryptedContent has extraneous sub-TLVs"));
}
}
diff --git a/src/encrypted-content.hpp b/src/encrypted-content.hpp
index 2d861a3..8a96fc7 100644
--- a/src/encrypted-content.hpp
+++ b/src/encrypted-content.hpp
@@ -1,11 +1,31 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2018, Regents of the University of California
+ *
+ * This file is part of gep (Group-based Encryption Protocol for NDN).
+ * See AUTHORS.md for complete list of gep authors and contributors.
+ *
+ * gep 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.
+ *
+ * gep 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 a copy of the GNU General Public License along with
+ * gep, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @author Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
#ifndef NDN_ENCRYPTED_CONTENT_HPP
#define NDN_ENCRYPTED_CONTENT_HPP
+#include "tlv.hpp"
+#include <list>
#include <ndn-cxx/encoding/tlv.hpp>
#include <ndn-cxx/key-locator.hpp>
-#include <list>
-
-#include "tlv.hpp"
namespace ndn {
namespace gep {
@@ -15,23 +35,24 @@
public:
class Error : public ndn::tlv::Error
{
- public:
- explicit
- Error(const std::string& what)
+ public:
+ explicit Error(const std::string& what)
: ndn::tlv::Error(what)
- {
- }
+ {
+ }
};
public:
EncryptedContent();
- EncryptedContent(tlv::AlgorithmTypeValue type, const KeyLocator& keyLocator,
- const uint8_t* payload, size_t payloadLen,
- const uint8_t* iv = 0, size_t ivLen = 0);
+ EncryptedContent(tlv::AlgorithmTypeValue type,
+ const KeyLocator& keyLocator,
+ const uint8_t* payload,
+ size_t payloadLen,
+ const uint8_t* iv = 0,
+ size_t ivLen = 0);
- explicit
- EncryptedContent(const Block& block);
+ explicit EncryptedContent(const Block& block);
void
setAlgorithmType(tlv::AlgorithmTypeValue type);
@@ -45,7 +66,7 @@
bool
hasKeyLocator() const
{
- return m_hasKeyLocator;
+ return m_hasKeyLocator;
}
void
diff --git a/src/error-code.hpp b/src/error-code.hpp
index 5ccf820..e070efe 100644
--- a/src/error-code.hpp
+++ b/src/error-code.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
diff --git a/src/group-manager-db.cpp b/src/group-manager-db.cpp
index 6b0eb2d..57a3697 100644
--- a/src/group-manager-db.cpp
+++ b/src/group-manager-db.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2017, 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,55 +16,54 @@
* 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>
*/
#include "group-manager-db.hpp"
#include "algo/rsa.hpp"
-
-#include <sqlite3.h>
-#include <boost/filesystem.hpp>
#include <ndn-cxx/util/sqlite3-statement.hpp>
-#include <ndn-cxx/security/identity-certificate.hpp>
+#include <boost/filesystem.hpp>
+#include <sqlite3.h>
+#include <ndn-cxx/util/string-helper.hpp>
namespace ndn {
namespace gep {
using util::Sqlite3Statement;
-static const std::string INITIALIZATION =
- "CREATE TABLE IF NOT EXISTS \n"
- " schedules( \n"
- " schedule_id INTEGER PRIMARY KEY, \n"
- " schedule_name TEXT NOT NULL, \n"
- " schedule BLOB NOT NULL \n"
- " ); \n"
- "CREATE UNIQUE INDEX IF NOT EXISTS \n"
- " scheduleNameIndex ON schedules(schedule_name); \n"
- " \n"
- "CREATE TABLE IF NOT EXISTS \n"
- " members( \n"
- " member_id INTEGER PRIMARY KEY, \n"
- " schedule_id INTEGER NOT NULL, \n"
- " member_name BLOB NOT NULL, \n"
- " key_name BLOB NOT NULL, \n"
- " pubkey BLOB NOT NULL, \n"
- " FOREIGN KEY(schedule_id) \n"
- " REFERENCES schedules(schedule_id) \n"
- " ON DELETE CASCADE \n"
- " ON UPDATE CASCADE \n"
- " ); \n"
- "CREATE UNIQUE INDEX IF NOT EXISTS \n"
- " memNameIndex ON members(member_name); \n"
- " \n"
- "CREATE TABLE IF NOT EXISTS \n"
- " ekeys( \n"
- " ekey_id INTEGER PRIMARY KEY, \n"
- " ekey_name BLOB NOT NULL, \n"
- " pub_key BLOB NOT NULL \n"
- " ); \n"
- "CREATE UNIQUE INDEX IF NOT EXISTS \n"
- " ekeyNameIndex ON ekeys(ekey_name); \n";
+static const std::string INITIALIZATION = R"_DBTEXT_(
+CREATE TABLE IF NOT EXISTS
+ schedules(
+ schedule_id INTEGER PRIMARY KEY,
+ schedule_name TEXT NOT NULL,
+ schedule BLOB NOT NULL
+ );
+CREATE UNIQUE INDEX IF NOT EXISTS
+ scheduleNameIndex ON schedules(schedule_name);
+
+CREATE TABLE IF NOT EXISTS
+ members(
+ member_id INTEGER PRIMARY KEY,
+ schedule_id INTEGER NOT NULL,
+ member_name BLOB NOT NULL,
+ key_name BLOB NOT NULL,
+ pubkey BLOB NOT NULL,
+ FOREIGN KEY(schedule_id)
+ REFERENCES schedules(schedule_id)
+ ON DELETE CASCADE
+ ON UPDATE CASCADE
+ );
+CREATE UNIQUE INDEX IF NOT EXISTS
+ memNameIndex ON members(member_name);
+
+CREATE TABLE IF NOT EXISTS
+ ekeys(
+ ekey_id INTEGER PRIMARY KEY,
+ ekey_name BLOB NOT NULL,
+ pub_key BLOB NOT NULL
+ );
+CREATE UNIQUE INDEX IF NOT EXISTS
+ ekeyNameIndex ON ekeys(ekey_name);)_DBTEXT_";
class GroupManagerDB::Impl
{
@@ -73,14 +72,10 @@
{
// open Database
- int result = sqlite3_open_v2(dbPath.c_str(), &m_database,
+ int result = sqlite3_open_v2(dbPath.c_str(),
+ &m_database,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
-#ifdef NDN_CXX_DISABLE_SQLITE3_FS_LOCKING
- "unix-dotfile"
-#else
- nullptr
-#endif
- );
+ nullptr);
if (result != SQLITE_OK)
BOOST_THROW_EXCEPTION(Error("GroupManager DB cannot be opened/created: " + dbPath));
@@ -106,7 +101,8 @@
getScheduleId(const std::string& name) const
{
Sqlite3Statement statement(m_database,
- "SELECT schedule_id FROM schedules WHERE schedule_name=?");
+ R"_DBTEXT_(SELECT schedule_id FROM schedules
+ WHERE schedule_name=?)_DBTEXT_");
statement.bind(1, name, SQLITE_TRANSIENT);
int result = -1;
@@ -131,7 +127,8 @@
GroupManagerDB::hasSchedule(const std::string& name) const
{
Sqlite3Statement statement(m_impl->m_database,
- "SELECT schedule_id FROM schedules where schedule_name=?");
+ R"_DBTEXT_(SELECT schedule_id FROM schedules
+ WHERE schedule_name=?)_DBTEXT_");
statement.bind(1, name, SQLITE_TRANSIENT);
return (statement.step() == SQLITE_ROW);
}
@@ -141,7 +138,7 @@
{
std::list<std::string> result;
Sqlite3Statement statement(m_impl->m_database,
- "SELECT schedule_name FROM schedules");
+ R"_DBTEXT_(SELECT schedule_name FROM schedules)_DBTEXT_");
result.clear();
while (statement.step() == SQLITE_ROW) {
@@ -154,7 +151,7 @@
GroupManagerDB::getSchedule(const std::string& name) const
{
Sqlite3Statement statement(m_impl->m_database,
- "SELECT schedule FROM schedules where schedule_name=?");
+ R"_DBTEXT_(SELECT schedule FROM schedules where schedule_name=?)_DBTEXT_");
statement.bind(1, name, SQLITE_TRANSIENT);
Schedule result;
@@ -172,10 +169,10 @@
{
std::map<Name, Buffer> result;
Sqlite3Statement statement(m_impl->m_database,
- "SELECT key_name, pubkey\
- FROM members JOIN schedules\
- ON members.schedule_id=schedules.schedule_id\
- WHERE schedule_name=?");
+ R"_DBTEXT_(SELECT key_name, pubkey
+ FROM members JOIN schedules
+ ON members.schedule_id=schedules.schedule_id
+ WHERE schedule_name=?)_DBTEXT_");
statement.bind(1, name, SQLITE_TRANSIENT);
result.clear();
@@ -195,8 +192,8 @@
BOOST_ASSERT(name.length() != 0);
Sqlite3Statement statement(m_impl->m_database,
- "INSERT INTO schedules (schedule_name, schedule)\
- values (?, ?)");
+ R"_DBTEXT_(INSERT INTO schedules (schedule_name, schedule)
+ values (?, ?))_DBTEXT_");
statement.bind(1, name, SQLITE_TRANSIENT);
statement.bind(2, schedule.wireEncode(), SQLITE_TRANSIENT);
if (statement.step() != SQLITE_DONE)
@@ -207,7 +204,7 @@
GroupManagerDB::deleteSchedule(const std::string& name)
{
Sqlite3Statement statement(m_impl->m_database,
- "DELETE FROM schedules WHERE schedule_name=?");
+ R"_DBTEXT_(DELETE FROM schedules WHERE schedule_name=?)_DBTEXT_");
statement.bind(1, name, SQLITE_TRANSIENT);
statement.step();
}
@@ -218,7 +215,8 @@
BOOST_ASSERT(newName.length() != 0);
Sqlite3Statement statement(m_impl->m_database,
- "UPDATE schedules SET schedule_name=? WHERE schedule_name=?");
+ R"_DBTEXT_(UPDATE schedules SET schedule_name=?
+ WHERE schedule_name=?)_DBTEXT_");
statement.bind(1, newName, SQLITE_TRANSIENT);
statement.bind(2, oldName, SQLITE_TRANSIENT);
if (statement.step() != SQLITE_DONE)
@@ -234,7 +232,8 @@
}
Sqlite3Statement statement(m_impl->m_database,
- "UPDATE schedules SET schedule=? WHERE schedule_name=?");
+ R"_DBTEXT_(UPDATE schedules SET schedule=?
+ WHERE schedule_name=?)_DBTEXT_");
statement.bind(1, schedule.wireEncode(), SQLITE_TRANSIENT);
statement.bind(2, name, SQLITE_TRANSIENT);
statement.step();
@@ -244,7 +243,7 @@
GroupManagerDB::hasMember(const Name& identity) const
{
Sqlite3Statement statement(m_impl->m_database,
- "SELECT member_id FROM members WHERE member_name=?");
+ R"_DBTEXT_(SELECT member_id FROM members WHERE member_name=?)_DBTEXT_");
statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
return (statement.step() == SQLITE_ROW);
}
@@ -254,7 +253,7 @@
{
std::list<Name> result;
Sqlite3Statement statement(m_impl->m_database,
- "SELECT member_name FROM members");
+ R"_DBTEXT_(SELECT member_name FROM members)_DBTEXT_");
result.clear();
while (statement.step() == SQLITE_ROW) {
@@ -267,10 +266,10 @@
GroupManagerDB::getMemberSchedule(const Name& identity) const
{
Sqlite3Statement statement(m_impl->m_database,
- "SELECT schedule_name\
- FROM schedules JOIN members\
- ON schedules.schedule_id = members.schedule_id\
- WHERE member_name=?");
+ R"_DBTEXT_(SELECT schedule_name
+ FROM schedules JOIN members
+ ON schedules.schedule_id = members.schedule_id
+ WHERE member_name=?)_DBTEXT_");
statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
std::string result = "";
@@ -284,8 +283,7 @@
}
void
-GroupManagerDB::addMember(const std::string& scheduleName, const Name& keyName,
- const Buffer& key)
+GroupManagerDB::addMember(const std::string& scheduleName, const Name& keyName, const Buffer& key)
{
int scheduleId = m_impl->getScheduleId(scheduleName);
if (scheduleId == -1)
@@ -295,12 +293,12 @@
Name memberName = keyName.getPrefix(-1);
Sqlite3Statement statement(m_impl->m_database,
- "INSERT INTO members(schedule_id, member_name, key_name, pubkey)\
- values (?, ?, ?, ?)");
+ R"_DBTEXT_(INSERT INTO members(schedule_id, member_name, key_name, pubkey)
+ values (?, ?, ?, ?))_DBTEXT_");
statement.bind(1, scheduleId);
statement.bind(2, memberName.wireEncode(), SQLITE_TRANSIENT);
statement.bind(3, keyName.wireEncode(), SQLITE_TRANSIENT);
- statement.bind(4, key.buf(), key.size(), SQLITE_TRANSIENT);
+ statement.bind(4, key.data(), key.size(), SQLITE_TRANSIENT);
if (statement.step() != SQLITE_DONE)
BOOST_THROW_EXCEPTION(Error("Cannot add the member to database"));
@@ -314,7 +312,8 @@
BOOST_THROW_EXCEPTION(Error("The schedule dose not exist"));
Sqlite3Statement statement(m_impl->m_database,
- "UPDATE members SET schedule_id=? WHERE member_name=?");
+ R"_DBTEXT_(UPDATE members SET schedule_id=?
+ WHERE member_name=?)_DBTEXT_");
statement.bind(1, scheduleId);
statement.bind(2, identity.wireEncode(), SQLITE_TRANSIENT);
statement.step();
@@ -324,7 +323,7 @@
GroupManagerDB::deleteMember(const Name& identity)
{
Sqlite3Statement statement(m_impl->m_database,
- "DELETE FROM members WHERE member_name=?");
+ R"_DBTEXT_(DELETE FROM members WHERE member_name=?)_DBTEXT_");
statement.bind(1, identity.wireEncode(), SQLITE_TRANSIENT);
statement.step();
}
@@ -333,7 +332,7 @@
GroupManagerDB::hasEKey(const Name& eKeyName)
{
Sqlite3Statement statement(m_impl->m_database,
- "SELECT ekey_id FROM ekeys where ekey_name=?");
+ R"_DBTEXT_(SELECT ekey_id FROM ekeys where ekey_name=?)_DBTEXT_");
statement.bind(1, eKeyName.wireEncode(), SQLITE_TRANSIENT);
return (statement.step() == SQLITE_ROW);
}
@@ -342,9 +341,10 @@
GroupManagerDB::addEKey(const Name& eKeyName, const Buffer& pubKey, const Buffer& priKey)
{
Sqlite3Statement statement(m_impl->m_database,
- "INSERT INTO ekeys(ekey_name, pub_key) values (?, ?)");
+ R"_DBTEXT_(INSERT INTO ekeys(ekey_name, pub_key)
+ values (?, ?))_DBTEXT_");
statement.bind(1, eKeyName.wireEncode(), SQLITE_TRANSIENT);
- statement.bind(2, pubKey.buf(), pubKey.size(), SQLITE_TRANSIENT);
+ statement.bind(2, pubKey.data(), pubKey.size(), SQLITE_TRANSIENT);
if (statement.step() != SQLITE_DONE)
BOOST_THROW_EXCEPTION(Error("Cannot add the EKey to database"));
@@ -355,7 +355,7 @@
GroupManagerDB::getEKey(const Name& eKeyName)
{
Sqlite3Statement statement(m_impl->m_database,
- "SELECT * FROM ekeys where ekey_name=?");
+ R"_DBTEXT_(SELECT * FROM ekeys where ekey_name=?)_DBTEXT_");
statement.bind(1, eKeyName.wireEncode(), SQLITE_TRANSIENT);
Buffer pubKey, priKey;
@@ -371,7 +371,8 @@
void
GroupManagerDB::cleanEKeys()
{
- Sqlite3Statement statement(m_impl->m_database, "DELETE FROM ekeys");
+ Sqlite3Statement statement(m_impl->m_database,
+ R"_DBTEXT_(DELETE FROM ekeys)_DBTEXT_");
statement.step();
m_impl->m_priKeyBase.clear();
}
@@ -380,12 +381,14 @@
GroupManagerDB::deleteEKey(const Name& eKeyName)
{
Sqlite3Statement statement(m_impl->m_database,
- "DELETE FROM ekeys WHERE ekey_name=?");
+ R"_DBTEXT_(DELETE FROM ekeys WHERE ekey_name=?)_DBTEXT_");
statement.bind(1, eKeyName.wireEncode(), SQLITE_TRANSIENT);
statement.step();
auto search = m_impl->m_priKeyBase.find(eKeyName);
- m_impl->m_priKeyBase.erase(search);
+ if (search != m_impl->m_priKeyBase.end()) {
+ m_impl->m_priKeyBase.erase(search);
+ }
}
} // namespace gep
diff --git a/src/group-manager-db.hpp b/src/group-manager-db.hpp
index cbf4ecd..a311ecf 100644
--- a/src/group-manager-db.hpp
+++ b/src/group-manager-db.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#ifndef GEP_GROUP_MANAGER_DB_HPP
@@ -38,8 +38,7 @@
class Error : public std::runtime_error
{
public:
- explicit
- Error(const std::string& what)
+ explicit Error(const std::string& what)
: std::runtime_error(what)
{
}
@@ -49,8 +48,7 @@
/**
* @brief Create the database of group manager at path @p dbPath.
*/
- explicit
- GroupManagerDB(const std::string& dbPath);
+ explicit GroupManagerDB(const std::string& dbPath);
~GroupManagerDB();
@@ -147,8 +145,7 @@
* @throw Error if add operation fails, e.g., the added member exists
*/
void
- addMember(const std::string& scheduleName, const Name& keyName,
- const Buffer& key);
+ addMember(const std::string& scheduleName, const Name& keyName, const Buffer& key);
/**
* @brief Change the schedule of a member with name @p identity to a schedule with @p scheduleName
diff --git a/src/group-manager.cpp b/src/group-manager.cpp
index bd5feb0..dfcb260 100644
--- a/src/group-manager.cpp
+++ b/src/group-manager.cpp
@@ -1,35 +1,45 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
+ * 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.
*
- * ndn-group-encrypt 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.
+ * ndn-group-encrypt 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.
*
- * ndn-group-encrypt 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.
+ * ndn-group-encrypt 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 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/>.
+ * 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>
*/
#include "group-manager.hpp"
-#include "algo/encryptor.hpp"
#include "encrypted-content.hpp"
+#include "algo/encryptor.hpp"
+#include <iostream>
#include <map>
+#include <ndn-cxx/util/string-helper.hpp>
+
namespace ndn {
namespace gep {
-GroupManager::GroupManager(const Name& prefix, const Name& dataType, const std::string& dbPath,
- const int paramLength, const int freshPeriod)
+GroupManager::GroupManager(const Name& prefix,
+ const Name& dataType,
+ const std::string& dbPath,
+ const int paramLength,
+ const int freshPeriod)
: m_namespace(prefix)
, m_db(dbPath)
, m_paramLength(paramLength)
@@ -46,8 +56,9 @@
// get time interval
Interval finalInterval = calculateInterval(timeslot, memberKeys);
- if (finalInterval.isValid() == false)
+ if (finalInterval.isValid() == false) {
return result;
+ }
std::string startTs = boost::posix_time::to_iso_string(finalInterval.getStartTime());
std::string endTs = boost::posix_time::to_iso_string(finalInterval.getEndTime());
@@ -109,8 +120,15 @@
void
GroupManager::addMember(const std::string& scheduleName, const Data& memCert)
{
- IdentityCertificate cert(memCert);
- m_db.addMember(scheduleName, cert.getPublicKeyName(), cert.getPublicKeyInfo().get());
+ security::v2::Certificate cert(memCert);
+ Buffer keybits = cert.getPublicKey();
+ m_db.addMember(scheduleName, cert.getKeyName(), keybits);
+}
+
+void
+GroupManager::addMember(const std::string& scheduleName, const Name& keyName, const Buffer& key)
+{
+ m_db.addMember(scheduleName, keyName, key);
}
void
@@ -138,14 +156,13 @@
// get the all intervals from schedules
for (const std::string& scheduleName : m_db.listAllScheduleNames()) {
-
const Schedule& schedule = m_db.getSchedule(scheduleName);
std::tie(isPositive, tempInterval) = schedule.getCoveringInterval(timeslot);
if (isPositive) {
if (!positiveResult.isValid())
positiveResult = tempInterval;
- positiveResult && tempInterval;
+ positiveResult&& tempInterval;
std::map<Name, Buffer> m = m_db.getScheduleMembers(scheduleName);
memberKeys.insert(m.begin(), m.end());
@@ -153,11 +170,12 @@
else {
if (!negativeResult.isValid())
negativeResult = tempInterval;
- negativeResult && tempInterval;
+ negativeResult&& tempInterval;
}
}
if (!positiveResult.isValid()) {
- // return invalid interval when there is no member has interval covering the time slot
+ // return invalid interval when there is no member has interval covering the
+ // time slot
return Interval(false);
}
@@ -173,31 +191,32 @@
void
GroupManager::generateKeyPairs(Buffer& priKeyBuf, Buffer& pubKeyBuf) const
{
- RandomNumberGenerator rng;
RsaKeyParams params(m_paramLength);
- DecryptKey<algo::Rsa> privateKey = algo::Rsa::generateKey(rng, params);
+ DecryptKey<algo::Rsa> privateKey = algo::Rsa::generateKey(params);
priKeyBuf = privateKey.getKeyBits();
EncryptKey<algo::Rsa> publicKey = algo::Rsa::deriveEncryptKey(priKeyBuf);
pubKeyBuf = publicKey.getKeyBits();
}
-
Data
-GroupManager::createEKeyData(const std::string& startTs, const std::string& endTs,
+GroupManager::createEKeyData(const std::string& startTs,
+ const std::string& endTs,
const Buffer& pubKeyBuf)
{
Name name(m_namespace);
name.append(NAME_COMPONENT_E_KEY).append(startTs).append(endTs);
Data data(name);
data.setFreshnessPeriod(time::hours(m_freshPeriod));
- data.setContent(pubKeyBuf.get(), pubKeyBuf.size());
+ data.setContent(pubKeyBuf.data(), pubKeyBuf.size());
m_keyChain.sign(data);
return data;
}
Data
-GroupManager::createDKeyData(const std::string& startTs, const std::string& endTs,
- const Name& keyName, const Buffer& priKeyBuf,
+GroupManager::createDKeyData(const std::string& startTs,
+ const std::string& endTs,
+ const Name& keyName,
+ const Buffer& priKeyBuf,
const Buffer& certKey)
{
Name name(m_namespace);
@@ -206,8 +225,13 @@
Data data = Data(name);
data.setFreshnessPeriod(time::hours(m_freshPeriod));
algo::EncryptParams eparams(tlv::AlgorithmRsaOaep);
- algo::encryptData(data, priKeyBuf.buf(), priKeyBuf.size(), keyName,
- certKey.buf(), certKey.size(), eparams);
+ algo::encryptData(data,
+ priKeyBuf.data(),
+ priKeyBuf.size(),
+ keyName,
+ certKey.data(),
+ certKey.size(),
+ eparams);
m_keyChain.sign(data);
return data;
}
@@ -236,5 +260,5 @@
m_db.cleanEKeys();
}
-} // namespace ndn
+} // namespace gep
} // namespace ndn
diff --git a/src/group-manager.hpp b/src/group-manager.hpp
index 2e19ab1..56feb28 100644
--- a/src/group-manager.hpp
+++ b/src/group-manager.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#ifndef NDN_GEP_GROUP_MANAGER_HPP
@@ -36,8 +36,7 @@
class Error : public std::runtime_error
{
public:
- explicit
- Error(const std::string& what)
+ explicit Error(const std::string& what)
: std::runtime_error(what)
{
}
@@ -53,8 +52,11 @@
* The group key will be an RSA key with @p paramLength bits.
* The FreshnessPeriod of data packet carrying the keys will be set to @p freshPeriod hours.
*/
- GroupManager(const Name& prefix, const Name& dataType, const std::string& dbPath,
- const int paramLength, const int freshPeriod);
+ GroupManager(const Name& prefix,
+ const Name& dataType,
+ const std::string& dbPath,
+ const int paramLength,
+ const int freshPeriod);
/**
* @brief Create a group key for interval which
@@ -90,6 +92,9 @@
void
addMember(const std::string& scheduleName, const Data& memCert);
+ void
+ addMember(const std::string& scheduleName, const Name& keyName, const Buffer& key);
+
/// @brief Remove member with name @p identity from the group.
void
removeMember(const Name& identity);
@@ -99,7 +104,7 @@
updateMemberSchedule(const Name& identity, const std::string& scheduleName);
-PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+PUBLIC_WITH_TESTS_ELSE_PRIVATE :
/**
* @brief Calculate interval that covers @p timeslot
* and fill @p memberKeys with the info of members who is allowed to access the interval.
@@ -117,13 +122,15 @@
/// @brief Create E-KEY data.
Data
- createEKeyData(const std::string& startTs, const std::string& endTs,
- const Buffer& pubKeyBuf);
+ createEKeyData(const std::string& startTs, const std::string& endTs, const Buffer& pubKeyBuf);
/// @brief Create D-KEY data.
Data
- createDKeyData(const std::string& startTs, const std::string& endTs, const Name& keyName,
- const Buffer& priKeyBuf, const Buffer& certKey);
+ createDKeyData(const std::string& startTs,
+ const std::string& endTs,
+ const Name& keyName,
+ const Buffer& priKeyBuf,
+ const Buffer& certKey);
/// @brief Add a EKey to the database
void
diff --git a/src/interval.cpp b/src/interval.cpp
index f5738a1..8d96f77 100644
--- a/src/interval.cpp
+++ b/src/interval.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#include "interval.hpp"
@@ -33,8 +33,7 @@
{
}
-Interval::Interval(const TimeStamp& startTime,
- const TimeStamp& endTime)
+Interval::Interval(const TimeStamp& startTime, const TimeStamp& endTime)
: m_startTime(startTime)
, m_endTime(endTime)
, m_isValid(true)
@@ -53,7 +52,7 @@
}
Interval&
-Interval::operator &&(const Interval& interval)
+Interval::operator&&(const Interval& interval)
{
BOOST_ASSERT(isValid() && interval.isValid());
@@ -80,7 +79,7 @@
}
Interval&
-Interval::operator ||(const Interval& interval)
+Interval::operator||(const Interval& interval)
{
BOOST_ASSERT(this->isValid() && interval.isValid());
diff --git a/src/interval.hpp b/src/interval.hpp
index e2cd23f..6cf6b86 100644
--- a/src/interval.hpp
+++ b/src/interval.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,14 +16,13 @@
* 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>
*/
#ifndef NDN_GEP_INTERVAL_HPP
#define NDN_GEP_INTERVAL_HPP
#include "common.hpp"
-
#include <boost/date_time/posix_time/posix_time.hpp>
namespace ndn {
@@ -38,8 +37,7 @@
class Error : public std::runtime_error
{
public:
- explicit
- Error(const std::string& what)
+ explicit Error(const std::string& what)
: std::runtime_error(what)
{
}
@@ -51,11 +49,9 @@
*
* @param isValid If isValid is true, the created interval is an empty interval
*/
- explicit
- Interval(bool isValid = false);
+ explicit Interval(bool isValid = false);
- Interval(const TimeStamp& startTime,
- const TimeStamp& endTime);
+ Interval(const TimeStamp& startTime, const TimeStamp& endTime);
/**
* @brief Check if the timestamp tp is in the interval
@@ -73,7 +69,7 @@
* Two intervals should all be valid but they can be empty
*/
Interval&
- operator &&(const Interval& interval);
+ operator&&(const Interval& interval);
/**
* @brief Get the union set interval of two intervals
@@ -82,7 +78,7 @@
* Two intervals should all be valid but they can be empty
*/
Interval&
- operator ||(const Interval& interval);
+ operator||(const Interval& interval);
const TimeStamp&
getStartTime() const
diff --git a/src/producer-db.cpp b/src/producer-db.cpp
index c748953..0cde47d 100644
--- a/src/producer-db.cpp
+++ b/src/producer-db.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -20,11 +20,10 @@
*/
#include "producer-db.hpp"
-
-#include <sqlite3.h>
-#include <boost/filesystem.hpp>
#include <ndn-cxx/util/sqlite3-statement.hpp>
-#include <ndn-cxx/security/identity-certificate.hpp>
+#include <iostream>
+#include <boost/filesystem.hpp>
+#include <sqlite3.h>
namespace ndn {
namespace gep {
@@ -32,15 +31,15 @@
using util::Sqlite3Statement;
using time::system_clock;
-static const std::string INITIALIZATION =
- "CREATE TABLE IF NOT EXISTS \n"
- " contentkeys( \n"
- " rowId INTEGER PRIMARY KEY, \n"
- " timeslot INTEGER, \n"
- " key BLOB NOT NULL \n"
- " ); \n"
- "CREATE UNIQUE INDEX IF NOT EXISTS \n"
- " timeslotIndex ON contentkeys(timeslot); \n";
+static const std::string INITIALIZATION =R"_DBTEXT_(
+CREATE TABLE IF NOT EXISTS
+ contentkeys(
+ rowId INTEGER PRIMARY KEY,
+ timeslot INTEGER,
+ key BLOB NOT NULL
+ );
+CREATE UNIQUE INDEX IF NOT EXISTS
+ timeslotIndex ON contentkeys(timeslot);)_DBTEXT_";
class ProducerDB::Impl
{
@@ -49,14 +48,10 @@
{
// open Database
- int result = sqlite3_open_v2(dbPath.c_str(), &m_database,
+ int result = sqlite3_open_v2(dbPath.c_str(),
+ &m_database,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
-#ifdef NDN_CXX_DISABLE_SQLITE3_FS_LOCKING
- "unix-dotfile"
-#else
- nullptr
-#endif
- );
+ nullptr);
if (result != SQLITE_OK)
BOOST_THROW_EXCEPTION(Error("Producer DB cannot be opened/created: " + dbPath));
@@ -90,7 +85,8 @@
ProducerDB::~ProducerDB() = default;
static int32_t
-getFixedTimeslot(const system_clock::TimePoint& timeslot) {
+getFixedTimeslot(const system_clock::TimePoint& timeslot)
+{
return (time::toUnixTimestamp(timeslot)).count() / 3600000;
}
@@ -99,7 +95,7 @@
{
int32_t fixedTimeslot = getFixedTimeslot(timeslot);
Sqlite3Statement statement(m_impl->m_database,
- "SELECT key FROM contentkeys where timeslot=?");
+ R"_DBTEXT_(SELECT key FROM contentkeys where timeslot=?)_DBTEXT_");
statement.bind(1, fixedTimeslot);
return (statement.step() == SQLITE_ROW);
}
@@ -110,7 +106,7 @@
{
int32_t fixedTimeslot = getFixedTimeslot(timeslot);
Sqlite3Statement statement(m_impl->m_database,
- "SELECT key FROM contentkeys where timeslot=?");
+ R"_DBTEXT_(SELECT key FROM contentkeys where timeslot=?)_DBTEXT_");
statement.bind(1, fixedTimeslot);
Buffer result;
@@ -129,12 +125,13 @@
// BOOST_ASSERT(key.length() != 0);
int32_t fixedTimeslot = getFixedTimeslot(timeslot);
Sqlite3Statement statement(m_impl->m_database,
- "INSERT INTO contentkeys (timeslot, key)\
- values (?, ?)");
+ R"_DBTEXT_(INSERT INTO contentkeys (timeslot, key)
+ values (?, ?))_DBTEXT_");
statement.bind(1, fixedTimeslot);
- statement.bind(2, key.buf(), key.size(), SQLITE_TRANSIENT);
- if (statement.step() != SQLITE_DONE)
+ statement.bind(2, key.data(), key.size(), SQLITE_TRANSIENT);
+ if (statement.step() != SQLITE_DONE) {
BOOST_THROW_EXCEPTION(Error("Cannot add the key to database"));
+ }
}
void
@@ -142,7 +139,7 @@
{
int32_t fixedTimeslot = getFixedTimeslot(timeslot);
Sqlite3Statement statement(m_impl->m_database,
- "DELETE FROM contentkeys WHERE timeslot=?");
+ R"_DBTEXT_(DELETE FROM contentkeys WHERE timeslot=?)_DBTEXT_");
statement.bind(1, fixedTimeslot);
statement.step();
}
diff --git a/src/producer-db.hpp b/src/producer-db.hpp
index 4a10d3f..a846901 100644
--- a/src/producer-db.hpp
+++ b/src/producer-db.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -38,16 +38,14 @@
class Error : public std::runtime_error
{
public:
- explicit
- Error(const std::string& what)
+ explicit Error(const std::string& what)
: std::runtime_error(what)
{
}
};
public:
- explicit
- ProducerDB(const std::string& dbPath);
+ explicit ProducerDB(const std::string& dbPath);
~ProducerDB();
diff --git a/src/producer.cpp b/src/producer.cpp
index 88bd5c1..ac9aca0 100644
--- a/src/producer.cpp
+++ b/src/producer.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -18,13 +18,14 @@
*
* @author Prashanth Swaminathan <prashanthsw@gmail.com>
* @author Yingdi Yu <yuyingdi@gmail.com>
+ * @author Zhiyi Zhang <zhiyi@cs.ucla.edu>
*/
#include "producer.hpp"
-#include "random-number-generator.hpp"
-#include "algo/encryptor.hpp"
#include "algo/aes.hpp"
+#include "algo/encryptor.hpp"
#include "algo/error.hpp"
+#include <iostream>
namespace ndn {
namespace gep {
@@ -41,13 +42,15 @@
hour, so that we can store content keys uniformly (by start of the hour).
*/
static const system_clock::TimePoint
-getRoundedTimeslot(const system_clock::TimePoint& timeslot) {
- return time::fromUnixTimestamp(
- (time::toUnixTimestamp(timeslot) / 3600000) * 3600000);
+getRoundedTimeslot(const system_clock::TimePoint& timeslot)
+{
+ return time::fromUnixTimestamp((time::toUnixTimestamp(timeslot) / 3600000) * 3600000);
}
-Producer::Producer(const Name& prefix, const Name& dataType,
- Face& face, const std::string& dbPath,
+Producer::Producer(const Name& prefix,
+ const Name& dataType,
+ Face& face,
+ const std::string& dbPath,
uint8_t repeatAttempts,
const Link& keyRetrievalLink)
: m_face(face)
@@ -99,9 +102,8 @@
}
// We haven't created the content key, create one and add it into the database.
- RandomNumberGenerator rng;
AesKeyParams aesParams(128);
- contentKeyBits = algo::Aes::generateKey(rng, aesParams).getKeyBits();
+ contentKeyBits = algo::Aes::generateKey(aesParams).getKeyBits();
m_db.addContentKey(timeslot, contentKeyBits);
// Now we need to retrieve the E-KEYs for content key encryption.
@@ -119,7 +121,9 @@
// current E-KEY cannot cover the content key, retrieve one.
keyRequest.repeatAttempts[it->first] = 0;
sendKeyInterest(Interest(it->first).setExclude(timeRange).setChildSelector(1),
- timeslot, callback, errorCallback);
+ timeslot,
+ callback,
+ errorCallback);
}
else {
// current E-KEY can cover the content key, encrypt the content key directly.
@@ -140,8 +144,10 @@
}
void
-Producer::produce(Data& data, const system_clock::TimePoint& timeslot,
- const uint8_t* content, size_t contentLen,
+Producer::produce(Data& data,
+ const system_clock::TimePoint& timeslot,
+ const uint8_t* content,
+ size_t contentLen,
const ErrorCallBack& errorCallBack)
{
// Get a content key
@@ -154,7 +160,7 @@
data.setName(dataName);
algo::EncryptParams params(tlv::AlgorithmAesCbc, 16);
algo::encryptData(data, content, contentLen, contentKeyName,
- contentKey.buf(), contentKey.size(), params);
+ contentKey.data(), contentKey.size(), params);
m_keychain.sign(data);
}
@@ -165,8 +171,8 @@
const ErrorCallBack& errorCallback)
{
Interest request(interest);
- if (m_keyRetrievalLink.getDelegations().size() > 0) {
- request.setLink(m_keyRetrievalLink.wireEncode());
+ if (m_keyRetrievalLink.getDelegationList().size() > 0) {
+ request.setForwardingHint(m_keyRetrievalLink.getDelegationList());
}
m_face.expressInterest(request,
std::bind(&Producer::handleCoveringKey, this, _1, _2,
@@ -178,7 +184,8 @@
}
void
-Producer::handleCoveringKey(const Interest& interest, const Data& data,
+Producer::handleCoveringKey(const Interest& interest,
+ const Data& data,
const system_clock::TimePoint& timeslot,
const ProducerEKeyCallback& callback,
const ErrorCallBack& errorCallback)
@@ -200,7 +207,9 @@
timeRange.excludeBefore(keyName.get(START_TS_INDEX));
sendKeyInterest(Interest(interestName).setExclude(timeRange).setChildSelector(1),
- timeslot, callback, errorCallback);
+ timeslot,
+ callback,
+ errorCallback);
}
else {
// if received E-KEY covers the content key, encrypt the content
@@ -221,6 +230,9 @@
const ErrorCallBack& errorCallback)
{
uint64_t timeCount = toUnixTimestamp(timeslot).count();
+ if (m_keyRequests.find(timeCount) == m_keyRequests.end()) {
+ return;
+ }
KeyRequest& keyRequest = m_keyRequests.at(timeCount);
Name interestName = interest.getName();
@@ -244,11 +256,15 @@
{
// we run out of options...
uint64_t timeCount = toUnixTimestamp(timeslot).count();
- updateKeyRequest(m_keyRequests.at(timeCount), timeCount, callback);
+
+ if (m_keyRequests.find(timeCount) != m_keyRequests.end()) {
+ updateKeyRequest(m_keyRequests.at(timeCount), timeCount, callback);
+ }
}
void
-Producer::updateKeyRequest(KeyRequest& keyRequest, uint64_t timeCount,
+Producer::updateKeyRequest(KeyRequest& keyRequest,
+ uint64_t timeCount,
const ProducerEKeyCallback& callback)
{
keyRequest.interestCount--;
@@ -259,12 +275,16 @@
}
bool
-Producer::encryptContentKey(const Buffer& encryptionKey, const Name& eKeyName,
+Producer::encryptContentKey(const Buffer& encryptionKey,
+ const Name& eKeyName,
const system_clock::TimePoint& timeslot,
const ProducerEKeyCallback& callback,
const ErrorCallBack& errorCallBack)
{
uint64_t timeCount = toUnixTimestamp(timeslot).count();
+ if (m_keyRequests.find(timeCount) == m_keyRequests.end()) {
+ return false;
+ }
KeyRequest& keyRequest = m_keyRequests.at(timeCount);
Name keyName = m_namespace;
@@ -272,15 +292,19 @@
keyName.append(time::toIsoString(getRoundedTimeslot(timeslot)));
Buffer contentKey = m_db.getContentKey(timeslot);
-
Data cKeyData;
cKeyData.setName(keyName);
algo::EncryptParams params(tlv::AlgorithmRsaOaep);
try {
- algo::encryptData(cKeyData, contentKey.buf(), contentKey.size(), eKeyName,
- encryptionKey.buf(), encryptionKey.size(), params);
+ algo::encryptData(cKeyData,
+ contentKey.data(),
+ contentKey.size(),
+ eKeyName,
+ encryptionKey.data(),
+ encryptionKey.size(),
+ params);
}
- catch (algo::Error& e) {
+ catch (const algo::Error& e) {
errorCallBack(ErrorCode::EncryptionFailure, e.what());
return false;
}
diff --git a/src/producer.hpp b/src/producer.hpp
index a440581..8724d1b 100644
--- a/src/producer.hpp
+++ b/src/producer.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -23,11 +23,11 @@
#ifndef NDN_GEP_PRODUCER_HPP
#define NDN_GEP_PRODUCER_HPP
-#include "producer-db.hpp"
#include "error-code.hpp"
+#include "producer-db.hpp"
-#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
namespace ndn {
namespace gep {
@@ -41,16 +41,19 @@
class Producer
{
public:
- struct KeyInfo {
+ struct KeyInfo
+ {
time::system_clock::TimePoint beginTimeslot;
time::system_clock::TimePoint endTimeslot;
Buffer keyBits;
};
- struct KeyRequest {
+ struct KeyRequest
+ {
KeyRequest(size_t interests)
- : interestCount(interests)
- {}
+ : interestCount(interests)
+ {
+ }
size_t interestCount;
std::unordered_map<Name, size_t> repeatAttempts;
std::vector<Data> encryptedKeys;
@@ -71,8 +74,10 @@
* @p face, and will re-try for at most @p repeatAttemps times when
* E-KEY retrieval fails.
*/
- Producer(const Name& prefix, const Name& dataType,
- Face& face, const std::string& dbPath,
+ Producer(const Name& prefix,
+ const Name& dataType,
+ Face& face,
+ const std::string& dbPath,
uint8_t repeatAttempts = 3,
const Link& keyRetrievalLink = NO_LINK);
@@ -91,6 +96,7 @@
const ProducerEKeyCallback& callback,
const ErrorCallBack& errorCallBack = Producer::defaultErrorCallBack);
+
/**
* @brief Produce an data packet encrypted using the content key corresponding @p timeslot
*
@@ -99,8 +105,10 @@
* In case of any error, @p errorCallBack will be invoked.
*/
void
- produce(Data& data, const time::system_clock::TimePoint& timeslot,
- const uint8_t* content, size_t contentLen,
+ produce(Data& data,
+ const time::system_clock::TimePoint& timeslot,
+ const uint8_t* content,
+ size_t contentLen,
const ErrorCallBack& errorCallBack = Producer::defaultErrorCallBack);
public:
@@ -114,7 +122,6 @@
defaultErrorCallBack(const ErrorCode& code, const std::string& msg);
private:
-
/**
* @brief Send interest for E-KEY
*
@@ -138,7 +145,8 @@
* of any error, invoke @p errorCallBack.
*/
void
- handleCoveringKey(const Interest& interest, const Data& data,
+ handleCoveringKey(const Interest& interest,
+ const Data& data,
const time::system_clock::TimePoint& timeslot,
const ProducerEKeyCallback& callback,
const ErrorCallBack& errorCallBack = Producer::defaultErrorCallBack);
@@ -176,8 +184,7 @@
* If the count decrease to 0, invoke @p callback.
*/
void
- updateKeyRequest(KeyRequest& keyRequest, uint64_t timeCount,
- const ProducerEKeyCallback& callback);
+ updateKeyRequest(KeyRequest& keyRequest, uint64_t timeCount, const ProducerEKeyCallback& callback);
/**
* @brief Encrypts C-KEY for @p timeslot using @p encryptionKey of @p eKeyName
@@ -188,7 +195,8 @@
* @return true if encryption succeeds, otherwise false.
*/
bool
- encryptContentKey(const Buffer& encryptionKey, const Name& eKeyName,
+ encryptContentKey(const Buffer& encryptionKey,
+ const Name& eKeyName,
const time::system_clock::TimePoint& timeslot,
const ProducerEKeyCallback& callback,
const ErrorCallBack& errorCallback = Producer::defaultErrorCallBack);
diff --git a/src/random-number-generator.hpp b/src/random-number-generator.hpp
deleted file mode 100644
index 0d74f47..0000000
--- a/src/random-number-generator.hpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2015, 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.
- *
- * ndn-group-encrypt 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.
- *
- * ndn-group-encrypt 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 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/>.
- */
-
-#ifndef NDN_GEP_RANDOM_NUMBER_GENERATOR_HPP
-#define NDN_GEP_RANDOM_NUMBER_GENERATOR_HPP
-
-#include "cryptopp.hpp"
-
-namespace ndn {
-namespace gep {
-
-typedef CryptoPP::AutoSeededRandomPool RandomNumberGenerator;
-
-} // namespace gep
-} // namespace ndn
-
-#endif // NDN_GEP_RANDOM_NUMBER_GENERATOR_HPP
diff --git a/src/repetitive-interval.cpp b/src/repetitive-interval.cpp
index a8104d1..fbbe0a9 100644
--- a/src/repetitive-interval.cpp
+++ b/src/repetitive-interval.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,12 +16,11 @@
* 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>
*/
#include "repetitive-interval.hpp"
#include "tlv.hpp"
-
#include <ndn-cxx/encoding/block-helpers.hpp>
#include <ndn-cxx/util/concepts.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -78,15 +77,14 @@
size_t totalLength = 0;
// RepeatUnit
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::RepeatUnit,
- static_cast<size_t>(m_unit));
+ totalLength +=
+ prependNonNegativeIntegerBlock(encoder, tlv::RepeatUnit, static_cast<size_t>(m_unit));
// NRepeat
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::NRepeats, m_nRepeats);
// IntervalEndHour
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::IntervalEndHour, m_intervalEndHour);
// IntervalStartHour
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::IntervalStartHour,
- m_intervalStartHour);
+ totalLength += prependNonNegativeIntegerBlock(encoder, tlv::IntervalStartHour, m_intervalStartHour);
// EndDate
totalLength += prependStringBlock(encoder, tlv::EndDate, to_iso_string(m_endDate));
// StartDate
diff --git a/src/repetitive-interval.hpp b/src/repetitive-interval.hpp
index 6ac5e68..de9b63c 100644
--- a/src/repetitive-interval.hpp
+++ b/src/repetitive-interval.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#ifndef NDN_GEP_REPETITIVE_INTERVAL_HPP
@@ -32,7 +32,8 @@
class RepetitiveInterval
{
public:
- enum class RepeatUnit{
+ enum class
+ RepeatUnit {
NONE = 0,
DAY = 1,
MONTH = 2,
diff --git a/src/schedule.cpp b/src/schedule.cpp
index 14635b4..797467a 100644
--- a/src/schedule.cpp
+++ b/src/schedule.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#include "schedule.hpp"
@@ -36,8 +36,10 @@
* @p negativeR The negative result
*/
static void
-calIntervalResult(const std::set<RepetitiveInterval>& list, const TimeStamp& ts,
- Interval& positiveR, Interval& negativeR)
+calIntervalResult(const std::set<RepetitiveInterval>& list,
+ const TimeStamp& ts,
+ Interval& positiveR,
+ Interval& negativeR)
{
Interval tempInterval;
bool isPositive;
@@ -51,7 +53,7 @@
if (!negativeR.isValid())
negativeR = tempInterval;
else
- negativeR && tempInterval;
+ negativeR&& tempInterval;
}
}
}
@@ -176,22 +178,21 @@
Interval whiteNegativeResult;
// get the blackResult
- calIntervalResult(m_blackIntervalList, ts,
- blackPositiveResult, blackNegativeResult);
+ calIntervalResult(m_blackIntervalList, ts, blackPositiveResult, blackNegativeResult);
// if black positive result is not empty, the result must be false
if (!blackPositiveResult.isEmpty())
return std::make_tuple(false, blackPositiveResult);
// get the whiteResult
- calIntervalResult(m_whiteIntervalList, ts,
- whitePositiveResult, whiteNegativeResult);
+ calIntervalResult(m_whiteIntervalList, ts, whitePositiveResult, whiteNegativeResult);
if (whitePositiveResult.isEmpty() && !whiteNegativeResult.isValid()) {
// there is no white interval covering the timestamp
// return false and a 24-hour interval
- return std::make_tuple(false, Interval(TimeStamp(ts.date(), boost::posix_time::hours(0)),
- TimeStamp(ts.date(), boost::posix_time::hours(24))));
+ return std::make_tuple(false,
+ Interval(TimeStamp(ts.date(), boost::posix_time::hours(0)),
+ TimeStamp(ts.date(), boost::posix_time::hours(24))));
}
if (!whitePositiveResult.isEmpty()) {
diff --git a/src/schedule.hpp b/src/schedule.hpp
index e11b221..a919767 100644
--- a/src/schedule.hpp
+++ b/src/schedule.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,11 +16,11 @@
* 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>
*/
-#ifndef NDN_GEP_SECHEDULE_HPP
-#define NDN_GEP_SECHEDULE_HPP
+#ifndef NDN_GEP_SCHEDULE_HPP
+#define NDN_GEP_SCHEDULE_HPP
#include "common.hpp"
#include "repetitive-interval.hpp"
@@ -39,8 +39,7 @@
public:
Schedule();
- explicit
- Schedule(const Block& block);
+ explicit Schedule(const Block& block);
public:
template<encoding::Tag TAG>
@@ -82,4 +81,4 @@
} // namespace gep
} // namespace ndn
-#endif // NDN_GROUP_ENCRYPT_SECHEDULE_HPP
+#endif // NDN_GEP_SCHEDULE_HPP
diff --git a/tests/boost-test.hpp b/tests/boost-test.hpp
index f1b30b8..de1cfa2 100644
--- a/tests/boost-test.hpp
+++ b/tests/boost-test.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -24,8 +24,8 @@
#pragma GCC system_header
#pragma clang system_header
-#include <boost/test/unit_test.hpp>
#include <boost/concept_check.hpp>
#include <boost/test/output_test_stream.hpp>
+#include <boost/test/unit_test.hpp>
#endif // NDN_GEP_TESTS_BOOST_TEST_HPP
diff --git a/tests/unit-tests/algo/aes.t.cpp b/tests/unit-tests/algo/aes.t.cpp
index 740855e..a2bf151 100644
--- a/tests/unit-tests/algo/aes.t.cpp
+++ b/tests/unit-tests/algo/aes.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -27,65 +27,64 @@
namespace algo {
namespace tests {
-const uint8_t key[] = {
- 0xdd, 0x60, 0x77, 0xec, 0xa9, 0x6b, 0x23, 0x1b,
- 0x40, 0x6b, 0x5a, 0xf8, 0x7d, 0x3d, 0x55, 0x32
-};
+const uint8_t key[] = {0xdd, 0x60, 0x77, 0xec, 0xa9, 0x6b, 0x23, 0x1b,
+ 0x40, 0x6b, 0x5a, 0xf8, 0x7d, 0x3d, 0x55, 0x32};
-const uint8_t plaintext[] = { // plaintext: AES-Encrypt-Test
- 0x41, 0x45, 0x53, 0x2d, 0x45, 0x6e, 0x63, 0x72,
- 0x79, 0x70, 0x74, 0x2d, 0x54, 0x65, 0x73, 0x74
-};
+// plaintext: AES-Encrypt-Test
+const uint8_t plaintext[] = { 0x41, 0x45, 0x53, 0x2d, 0x45, 0x6e, 0x63, 0x72,
+ 0x79, 0x70, 0x74, 0x2d, 0x54, 0x65, 0x73, 0x74};
-const uint8_t ciphertext_ecb[] = {
- 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
-};
+// const uint8_t ciphertext_ecb[] = {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};
-const uint8_t initvector[] = {
- 0x6f, 0x53, 0x7a, 0x65, 0x58, 0x6c, 0x65, 0x75,
- 0x44, 0x4c, 0x77, 0x35, 0x58, 0x63, 0x78, 0x6e
-};
+const uint8_t initvector[] = {0x6f, 0x53, 0x7a, 0x65, 0x58, 0x6c, 0x65, 0x75,
+ 0x44, 0x4c, 0x77, 0x35, 0x58, 0x63, 0x78, 0x6e};
-const uint8_t ciphertext_cbc_iv[] = {
- 0xb7, 0x19, 0x5a, 0xbb, 0x23, 0xbf, 0x92, 0xb0,
- 0x95, 0xae, 0x74, 0xe9, 0xad, 0x72, 0x7c, 0x28,
- 0x6e, 0xc6, 0x73, 0xb5, 0x0b, 0x1a, 0x9e, 0xb9,
- 0x4d, 0xc5, 0xbd, 0x8b, 0x47, 0x1f, 0x43, 0x00
-};
+const uint8_t ciphertext_cbc_iv[] = {0xb7, 0x19, 0x5a, 0xbb, 0x23, 0xbf, 0x92, 0xb0,
+ 0x95, 0xae, 0x74, 0xe9, 0xad, 0x72, 0x7c, 0x28,
+ 0x6e, 0xc6, 0x73, 0xb5, 0x0b, 0x1a, 0x9e, 0xb9,
+ 0x4d, 0xc5, 0xbd, 0x8b, 0x47, 0x1f, 0x43, 0x00};
BOOST_AUTO_TEST_SUITE(TestAesAlgorithm)
BOOST_AUTO_TEST_CASE(EncryptionDecryption)
{
- RandomNumberGenerator rng;
AesKeyParams params;
-
EncryptParams eparams(tlv::AlgorithmAesEcb, 16);
DecryptKey<Aes> decryptKey(Buffer(key, sizeof(key)));
EncryptKey<Aes> encryptKey = Aes::deriveEncryptKey(decryptKey.getKeyBits());
// check if loading key and key derivation
- BOOST_CHECK_EQUAL_COLLECTIONS(encryptKey.getKeyBits().begin(), encryptKey.getKeyBits().end(), key, key + sizeof(key));
- BOOST_CHECK_EQUAL_COLLECTIONS(decryptKey.getKeyBits().begin(), decryptKey.getKeyBits().end(), key, key + sizeof(key));
+ BOOST_CHECK_EQUAL_COLLECTIONS(encryptKey.getKeyBits().begin(),
+ encryptKey.getKeyBits().end(),
+ key, key + sizeof(key));
+ BOOST_CHECK_EQUAL_COLLECTIONS(decryptKey.getKeyBits().begin(),
+ decryptKey.getKeyBits().end(),
+ key, key + sizeof(key));
- // encrypt data in AES_ECB
- Buffer cipherBuf = Aes::encrypt(key, sizeof(key), plaintext, sizeof(plaintext), eparams);
- BOOST_CHECK_EQUAL_COLLECTIONS(cipherBuf.begin(), cipherBuf.end(),
- ciphertext_ecb, ciphertext_ecb + sizeof(ciphertext_ecb));
+ // Comment out the test of AES_ECB because NAC no longer supports CBC.
+ // Compared with ECB, CBC is more secure.
- // decrypt data in AES_ECB
- Buffer recvBuf = Aes::decrypt(key, sizeof(key), cipherBuf.buf(), cipherBuf.size(), eparams);
- BOOST_CHECK_EQUAL_COLLECTIONS(recvBuf.begin(), recvBuf.end(),
- plaintext, plaintext + sizeof(plaintext));
+ // // encrypt data in AES_ECB
+ // Buffer cipherBuf = Aes::encrypt(key, sizeof(key), plaintext, sizeof(plaintext), eparams);
+ // BOOST_CHECK_EQUAL_COLLECTIONS(cipherBuf.begin(),
+ // cipherBuf.end(),
+ // ciphertext_ecb,
+ // ciphertext_ecb + sizeof(ciphertext_ecb));
+
+ // // decrypt data in AES_ECB
+ // Buffer recvBuf = Aes::decrypt(key, sizeof(key), cipherBuf.data(), cipherBuf.size(), eparams);
+ // BOOST_CHECK_EQUAL_COLLECTIONS(recvBuf.begin(),
+ // recvBuf.end(),
+ // plaintext,
+ // plaintext + sizeof(plaintext));
// encrypt/decrypt data in AES_CBC with auto-generated IV
eparams.setAlgorithmType(tlv::AlgorithmAesCbc);
- cipherBuf = Aes::encrypt(key, sizeof(key), plaintext, sizeof(plaintext), eparams);
- recvBuf = Aes::decrypt(key, sizeof(key), cipherBuf.buf(), cipherBuf.size(), eparams);
+ Buffer cipherBuf = Aes::encrypt(key, sizeof(key), plaintext, sizeof(plaintext), eparams);
+ Buffer recvBuf = Aes::decrypt(key, sizeof(key), cipherBuf.data(), cipherBuf.size(), eparams);
BOOST_CHECK_EQUAL_COLLECTIONS(recvBuf.begin(), recvBuf.end(),
plaintext, plaintext + sizeof(plaintext));
@@ -96,7 +95,7 @@
ciphertext_cbc_iv, ciphertext_cbc_iv + sizeof(ciphertext_cbc_iv));
// decrypt data in AES_CBC with specified IV
- recvBuf = Aes::decrypt(key, sizeof(key), cipherBuf.buf(), cipherBuf.size(), eparams);
+ recvBuf = Aes::decrypt(key, sizeof(key), cipherBuf.data(), cipherBuf.size(), eparams);
BOOST_CHECK_EQUAL_COLLECTIONS(recvBuf.begin(), recvBuf.end(),
plaintext, plaintext + sizeof(plaintext));
}
diff --git a/tests/unit-tests/algo/encryptor.t.cpp b/tests/unit-tests/algo/encryptor.t.cpp
index d6c0451..59a3d5b 100644
--- a/tests/unit-tests/algo/encryptor.t.cpp
+++ b/tests/unit-tests/algo/encryptor.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -17,14 +17,13 @@
* ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "random-number-generator.hpp"
-#include "encrypted-content.hpp"
#include "algo/encryptor.hpp"
-#include "algo/rsa.hpp"
+#include "encrypted-content.hpp"
#include "algo/aes.hpp"
+#include "algo/rsa.hpp"
-#include <boost/mpl/list.hpp>
#include "boost-test.hpp"
+#include <boost/mpl/list.hpp>
#include <algorithm>
namespace ndn {
@@ -34,51 +33,6 @@
BOOST_AUTO_TEST_SUITE(TestEncryptor)
-class TestDataAesEcb
-{
-public:
- TestDataAesEcb()
- : keyName("/test")
- , encryptParams(tlv::AlgorithmAesEcb)
- {
- const uint8_t raw_content[] = {
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
- 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73
- };
- plainText = Buffer(raw_content, sizeof(raw_content));
-
- const uint8_t aes_key[] = {
- 0xdd, 0x60, 0x77, 0xec, 0xa9, 0x6b, 0x23, 0x1b,
- 0x40, 0x6b, 0x5a, 0xf8, 0x7d, 0x3d, 0x55, 0x32
- };
- key = Buffer(aes_key, sizeof(aes_key));
-
- const uint8_t encrypted_content[] = {
- 0x15, 0x31,
- 0x82, 0x2f,
- 0x1c, 0x08,
- 0x07, 0x06,
- 0x08, 0x04, 0x74, 0x65, 0x73, 0x74,
- 0x83, 0x01,
- 0x00,
- 0x84, 0x20,
- 0x13, 0x80, 0x1a, 0xc0, 0x4c, 0x75, 0xa7, 0x7f,
- 0x43, 0x5e, 0xd7, 0xa6, 0x3f, 0xd3, 0x68, 0x94,
- 0xe2, 0xcf, 0x54, 0xb1, 0xc2, 0xce, 0xad, 0x9b,
- 0x56, 0x6e, 0x1c, 0xe6, 0x55, 0x1d, 0x79, 0x04
- };
- encryptedContent = Buffer(encrypted_content, sizeof(encrypted_content));
- }
-
-public:
- Buffer plainText;
- Buffer key;
- Name keyName;
- EncryptParams encryptParams;
- Buffer encryptedContent;
-};
-
class TestDataAesCbc
{
public:
@@ -134,29 +88,39 @@
Buffer encryptedContent;
};
-typedef boost::mpl::list<TestDataAesCbc,
- TestDataAesEcb> EncryptorAesTestInputs;
+typedef boost::mpl::list<TestDataAesCbc> EncryptorAesTestInputs;
BOOST_AUTO_TEST_CASE_TEMPLATE(ContentSymmetricEncrypt, T, EncryptorAesTestInputs)
{
T input;
Data data;
- encryptData(data, input.plainText.buf(), input.plainText.size(),
- input.keyName, input.key.buf(), input.key.size(), input.encryptParams);
+ encryptData(data,
+ input.plainText.data(),
+ input.plainText.size(),
+ input.keyName,
+ input.key.data(),
+ input.key.size(),
+ input.encryptParams);
BOOST_CHECK_EQUAL(data.getName(), Name("/FOR").append(input.keyName));
- BOOST_CHECK_EQUAL_COLLECTIONS(input.encryptedContent.begin(), input.encryptedContent.end(),
- data.getContent().wire(), data.getContent().wire() + data.getContent().size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(input.encryptedContent.begin(),
+ input.encryptedContent.end(),
+ data.getContent().wire(),
+ data.getContent().wire() + data.getContent().size());
EncryptedContent content(data.getContent().blockFromValue());
- const Buffer& decryptedOutput = Aes::decrypt(input.key.buf(), input.key.size(),
- content.getPayload().buf(), content.getPayload().size(),
+ const Buffer& decryptedOutput = Aes::decrypt(input.key.data(),
+ input.key.size(),
+ content.getPayload().data(),
+ content.getPayload().size(),
input.encryptParams);
- BOOST_CHECK_EQUAL_COLLECTIONS(input.plainText.begin(), input.plainText.end(),
- decryptedOutput.begin(), decryptedOutput.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(input.plainText.begin(),
+ input.plainText.end(),
+ decryptedOutput.begin(),
+ decryptedOutput.end());
}
class TestDataRsaOaep
@@ -166,6 +130,7 @@
: type(tlv::AlgorithmRsaOaep)
{
}
+
public:
tlv::AlgorithmTypeValue type;
};
@@ -177,30 +142,27 @@
: type(tlv::AlgorithmRsaPkcs)
{
}
+
public:
tlv::AlgorithmTypeValue type;
};
-typedef boost::mpl::list<TestDataRsaOaep,
- TestDataRsaPkcs> EncryptorRsaTestInputs;
+typedef boost::mpl::list<TestDataRsaOaep, TestDataRsaPkcs> EncryptorRsaTestInputs;
BOOST_AUTO_TEST_CASE_TEMPLATE(ContentAsymmetricEncryptSmall, T, EncryptorRsaTestInputs)
{
T type;
- const uint8_t raw_content[] = {
- 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
- 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
- 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73
- };
+ const uint8_t raw_content[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
+ 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
+ 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73};
Data data;
- RandomNumberGenerator rng;
RsaKeyParams rsaParams(1024);
Name keyName("test");
- DecryptKey<Rsa> decryptKey = Rsa::generateKey(rng, rsaParams);
+ DecryptKey<Rsa> decryptKey = Rsa::generateKey(rsaParams);
EncryptKey<Rsa> encryptKey = Rsa::deriveEncryptKey(decryptKey.getKeyBits());
Buffer eKey = encryptKey.getKeyBits();
@@ -208,8 +170,7 @@
EncryptParams encryptParams(type.type);
- encryptData(data, raw_content, sizeof(raw_content),
- keyName, eKey.buf(), eKey.size(), encryptParams);
+ encryptData(data, raw_content, sizeof(raw_content), keyName, eKey.data(), eKey.size(), encryptParams);
BOOST_CHECK_EQUAL(data.getName(), Name("/FOR").append(keyName));
@@ -223,69 +184,53 @@
BOOST_CHECK_EQUAL(extractContent.getAlgorithmType(), type.type);
const Buffer& recovered = extractContent.getPayload();
- Buffer decrypted = Rsa::decrypt(dKey.buf(), dKey.size(), recovered.buf(), recovered.size(), encryptParams);
- BOOST_CHECK_EQUAL_COLLECTIONS(raw_content, raw_content + sizeof(raw_content),
- decrypted.begin(), decrypted.end());
+ Buffer decrypted =
+ Rsa::decrypt(dKey.data(), dKey.size(), recovered.data(), recovered.size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(raw_content,
+ raw_content + sizeof(raw_content),
+ decrypted.begin(),
+ decrypted.end());
}
BOOST_AUTO_TEST_CASE_TEMPLATE(ContentAsymmetricEncryptLarge, T, EncryptorRsaTestInputs)
{
T type;
- const uint8_t large_content[] = {
- 0x73, 0x5a, 0xbd, 0x47, 0x0c, 0xfe, 0xf8, 0x7d,
- 0x2e, 0x17, 0xaa, 0x11, 0x6f, 0x23, 0xc5, 0x10,
- 0x23, 0x36, 0x88, 0xc4, 0x2a, 0x0f, 0x9a, 0x72,
- 0x54, 0x31, 0xa8, 0xb3, 0x51, 0x18, 0x9f, 0x0e,
- 0x1b, 0x93, 0x62, 0xd9, 0xc4, 0xf5, 0xf4, 0x3d,
- 0x61, 0x9a, 0xca, 0x05, 0x65, 0x6b, 0xc6, 0x41,
- 0xf9, 0xd5, 0x1c, 0x67, 0xc1, 0xd0, 0xd5, 0x6f,
- 0x7b, 0x70, 0xb8, 0x8f, 0xdb, 0x19, 0x68, 0x7c,
- 0xe0, 0x2d, 0x04, 0x49, 0xa9, 0xa2, 0x77, 0x4e,
- 0xfc, 0x60, 0x0d, 0x7c, 0x1b, 0x93, 0x6c, 0xd2,
- 0x61, 0xc4, 0x6b, 0x01, 0xe9, 0x12, 0x28, 0x6d,
- 0xf5, 0x78, 0xe9, 0x99, 0x0b, 0x9c, 0x4f, 0x90,
- 0x34, 0x3e, 0x06, 0x92, 0x57, 0xe3, 0x7a, 0x8f,
- 0x13, 0xc7, 0xf3, 0xfe, 0xf0, 0xe2, 0x59, 0x48,
- 0x15, 0xb9, 0xdb, 0x77, 0x07, 0x1d, 0x6d, 0xb5,
- 0x65, 0x17, 0xdf, 0x76, 0x6f, 0xb5, 0x43, 0xde,
- 0x71, 0xac, 0xf1, 0x22, 0xbf, 0xb2, 0xe5, 0xd9,
- 0x22, 0xf1, 0x67, 0x76, 0x71, 0x0c, 0xff, 0x99,
- 0x7b, 0x94, 0x9b, 0x24, 0x20, 0x80, 0xe3, 0xcc,
- 0x06, 0x4a, 0xed, 0xdf, 0xec, 0x50, 0xd5, 0x87,
- 0x3d, 0xa0, 0x7d, 0x9c, 0xe5, 0x13, 0x10, 0x98,
- 0x14, 0xc3, 0x90, 0x10, 0xd9, 0x25, 0x9a, 0x59,
- 0xe9, 0x37, 0x26, 0xfd, 0x87, 0xd7, 0xf4, 0xf9,
- 0x11, 0x91, 0xad, 0x5c, 0x00, 0x95, 0xf5, 0x2b,
- 0x37, 0xf7, 0x4e, 0xb4, 0x4b, 0x42, 0x7c, 0xb3,
- 0xad, 0xd6, 0x33, 0x5f, 0x0b, 0x84, 0x57, 0x7f,
- 0xa7, 0x07, 0x73, 0x37, 0x4b, 0xab, 0x2e, 0xfb,
- 0xfe, 0x1e, 0xcb, 0xb6, 0x4a, 0xc1, 0x21, 0x5f,
- 0xec, 0x92, 0xb7, 0xac, 0x97, 0x75, 0x20, 0xc9,
- 0xd8, 0x9e, 0x93, 0xd5, 0x12, 0x7a, 0x64, 0xb9,
- 0x4c, 0xed, 0x49, 0x87, 0x44, 0x5b, 0x4f, 0x90,
- 0x34, 0x3e, 0x06, 0x92, 0x57, 0xe3, 0x7a, 0x8f,
- 0x13, 0xc7, 0xf3, 0xfe, 0xf0, 0xe2, 0x59, 0x48,
- 0x15, 0xb9, 0xdb, 0x77, 0x07, 0x1d, 0x6d, 0xb5,
- 0x65, 0x17, 0xdf, 0x76, 0x6f, 0xb5, 0x43, 0xde,
- 0x71, 0xac, 0xf1, 0x22, 0xbf, 0xb2, 0xe5, 0xd9
- };
+ const uint8_t large_content[] =
+ {0x73, 0x5a, 0xbd, 0x47, 0x0c, 0xfe, 0xf8, 0x7d, 0x2e, 0x17, 0xaa, 0x11, 0x6f, 0x23, 0xc5,
+ 0x10, 0x23, 0x36, 0x88, 0xc4, 0x2a, 0x0f, 0x9a, 0x72, 0x54, 0x31, 0xa8, 0xb3, 0x51, 0x18,
+ 0x9f, 0x0e, 0x1b, 0x93, 0x62, 0xd9, 0xc4, 0xf5, 0xf4, 0x3d, 0x61, 0x9a, 0xca, 0x05, 0x65,
+ 0x6b, 0xc6, 0x41, 0xf9, 0xd5, 0x1c, 0x67, 0xc1, 0xd0, 0xd5, 0x6f, 0x7b, 0x70, 0xb8, 0x8f,
+ 0xdb, 0x19, 0x68, 0x7c, 0xe0, 0x2d, 0x04, 0x49, 0xa9, 0xa2, 0x77, 0x4e, 0xfc, 0x60, 0x0d,
+ 0x7c, 0x1b, 0x93, 0x6c, 0xd2, 0x61, 0xc4, 0x6b, 0x01, 0xe9, 0x12, 0x28, 0x6d, 0xf5, 0x78,
+ 0xe9, 0x99, 0x0b, 0x9c, 0x4f, 0x90, 0x34, 0x3e, 0x06, 0x92, 0x57, 0xe3, 0x7a, 0x8f, 0x13,
+ 0xc7, 0xf3, 0xfe, 0xf0, 0xe2, 0x59, 0x48, 0x15, 0xb9, 0xdb, 0x77, 0x07, 0x1d, 0x6d, 0xb5,
+ 0x65, 0x17, 0xdf, 0x76, 0x6f, 0xb5, 0x43, 0xde, 0x71, 0xac, 0xf1, 0x22, 0xbf, 0xb2, 0xe5,
+ 0xd9, 0x22, 0xf1, 0x67, 0x76, 0x71, 0x0c, 0xff, 0x99, 0x7b, 0x94, 0x9b, 0x24, 0x20, 0x80,
+ 0xe3, 0xcc, 0x06, 0x4a, 0xed, 0xdf, 0xec, 0x50, 0xd5, 0x87, 0x3d, 0xa0, 0x7d, 0x9c, 0xe5,
+ 0x13, 0x10, 0x98, 0x14, 0xc3, 0x90, 0x10, 0xd9, 0x25, 0x9a, 0x59, 0xe9, 0x37, 0x26, 0xfd,
+ 0x87, 0xd7, 0xf4, 0xf9, 0x11, 0x91, 0xad, 0x5c, 0x00, 0x95, 0xf5, 0x2b, 0x37, 0xf7, 0x4e,
+ 0xb4, 0x4b, 0x42, 0x7c, 0xb3, 0xad, 0xd6, 0x33, 0x5f, 0x0b, 0x84, 0x57, 0x7f, 0xa7, 0x07,
+ 0x73, 0x37, 0x4b, 0xab, 0x2e, 0xfb, 0xfe, 0x1e, 0xcb, 0xb6, 0x4a, 0xc1, 0x21, 0x5f, 0xec,
+ 0x92, 0xb7, 0xac, 0x97, 0x75, 0x20, 0xc9, 0xd8, 0x9e, 0x93, 0xd5, 0x12, 0x7a, 0x64, 0xb9,
+ 0x4c, 0xed, 0x49, 0x87, 0x44, 0x5b, 0x4f, 0x90, 0x34, 0x3e, 0x06, 0x92, 0x57, 0xe3, 0x7a,
+ 0x8f, 0x13, 0xc7, 0xf3, 0xfe, 0xf0, 0xe2, 0x59, 0x48, 0x15, 0xb9, 0xdb, 0x77, 0x07, 0x1d,
+ 0x6d, 0xb5, 0x65, 0x17, 0xdf, 0x76, 0x6f, 0xb5, 0x43, 0xde, 0x71, 0xac, 0xf1, 0x22, 0xbf,
+ 0xb2, 0xe5, 0xd9};
Data data;
- RandomNumberGenerator rng;
RsaKeyParams rsaParams(1024);
Name keyName("test");
- DecryptKey<Rsa> decryptKey = Rsa::generateKey(rng, rsaParams);
+ DecryptKey<Rsa> decryptKey = Rsa::generateKey(rsaParams);
EncryptKey<Rsa> encryptKey = Rsa::deriveEncryptKey(decryptKey.getKeyBits());
Buffer eKey = encryptKey.getKeyBits();
Buffer dKey = decryptKey.getKeyBits();
EncryptParams encryptParams(type.type);
- encryptData(data, large_content, sizeof(large_content),
- keyName, eKey.buf(), eKey.size(), encryptParams);
+ encryptData(data, large_content, sizeof(large_content), keyName, eKey.data(), eKey.size(), encryptParams);
BOOST_CHECK_EQUAL(data.getName(), Name("/FOR").append(keyName));
@@ -317,20 +262,25 @@
BOOST_CHECK(it == largeDataContent.elements_end());
const Buffer& bufferNonce = encryptedNonce.getPayload();
- Buffer nonce = Rsa::decrypt(dKey.buf(), dKey.size(), bufferNonce.buf(), bufferNonce.size(), encryptParams);
+ Buffer nonce =
+ Rsa::decrypt(dKey.data(), dKey.size(), bufferNonce.data(), bufferNonce.size());
encryptParams.setAlgorithmType(tlv::AlgorithmAesCbc);
- encryptParams.setIV(encryptedPayload.getInitialVector().buf(), encryptedPayload.getInitialVector().size());
+ encryptParams.setIV(encryptedPayload.getInitialVector().data(),
+ encryptedPayload.getInitialVector().size());
const Buffer& bufferPayload = encryptedPayload.getPayload();
- Buffer largePayload = Aes::decrypt(nonce.buf(), nonce.size(), bufferPayload.buf(), bufferPayload.size(), encryptParams);
+ Buffer largePayload =
+ Aes::decrypt(nonce.data(), nonce.size(), bufferPayload.data(), bufferPayload.size(), encryptParams);
- BOOST_CHECK_EQUAL_COLLECTIONS(large_content, large_content + sizeof(large_content),
- largePayload.begin(), largePayload.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(large_content,
+ large_content + sizeof(large_content),
+ largePayload.begin(),
+ largePayload.end());
}
BOOST_AUTO_TEST_SUITE_END()
-} // namespace algo
} // namespace tests
+} // namespace algo
} // namespace gep
} // namespace ndn
diff --git a/tests/unit-tests/algo/rsa.t.cpp b/tests/unit-tests/algo/rsa.t.cpp
index d9ee899..6b7bbcb 100644
--- a/tests/unit-tests/algo/rsa.t.cpp
+++ b/tests/unit-tests/algo/rsa.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -17,109 +17,53 @@
* ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <ndn-cxx/encoding/buffer-stream.hpp>
-#include "algo/encrypt-params.hpp"
#include "algo/rsa.hpp"
-
+#include "algo/encrypt-params.hpp"
#include "boost-test.hpp"
+#include <ndn-cxx/security/key-params.hpp>
+#include <ndn-cxx/security/transform/private-key.hpp>
+#include <ndn-cxx/security/transform/public-key.hpp>
+#include <ndn-cxx/encoding/buffer-stream.hpp>
#include <algorithm>
#include <string>
-using namespace CryptoPP;
-
namespace ndn {
namespace gep {
namespace algo {
namespace tests {
-const std::string privateKey = {
- "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMLY2w1PmsuZNvZ4"
- "rJs1pESLrxF1Xlk9Zg4Sc0r2HIEn/eme8f7cOxXq8OtxIjowEfjceHGvfc7YG1Nw"
- "LDh+ka4Jh6QtYqPEL9GHfrBeufynd0g2PAPVXySBvOJr/Isk+4/Fsj5ihrIPgrQ5"
- "wTBBuLYjDgwPppC/+vddsr5wu5bbAgMBAAECgYBYmRLB8riIa5q6aBTUXofbQ0jP"
- "v3avTWPicjFKnK5JbE3gtQ2Evc+AH9x8smzF2KXTayy5RPsH2uxR/GefKK5EkWbB"
- "mLwWDJ5/QPlLK1STxPs8B/89mp8sZkZ1AxnSHhV/a3dRcK1rVamVcqPMdFyM5PfX"
- "/apL3MlL6bsq2FipAQJBAOp7EJuEs/qAjh8hgyV2acLdsokUEwXH4gCK6+KQW8XS"
- "xFWAG4IbbLfq1HwEpHC2hJSzifCQGoPAxYBRgSK+h6sCQQDUuqF04o06+Qpe4A/W"
- "pWCBGE33+CD4lBtaeoIagsAs/lgcFmXiJZ4+4PhyIORmwFgql9ZDFHSpl8rAYsfk"
- "dz2RAkEAtUKpFe/BybYzJ3Galg0xuMf0ye7QvblExjKeIqiBqS1DRO0hVrSomIxZ"
- "8f0MuWz+lI0t5t8fABa3FnjrINa0vQJBAJeZKNaTXPJZ5/oU0zS0RkG5gFbmjRiY"
- "86VXCMC7zRhDaacajyDKjithR6yNpDdVe39fFWJYgYsakXLo8mruTwECQGqywoy9"
- "epf1flKx4YCCrw+qRKmbkcXWcpFV32EG2K2D1GsxkuXv/b3qO67Uxx1Arxp9o8dl"
- "k34WfzApRjNjho0="
-};
-
-const std::string publicKey = {
- "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC2NsNT5rLmTb2eKybNaREi68R"
- "dV5ZPWYOEnNK9hyBJ/3pnvH+3DsV6vDrcSI6MBH43Hhxr33O2BtTcCw4fpGuCYek"
- "LWKjxC/Rh36wXrn8p3dINjwD1V8kgbzia/yLJPuPxbI+YoayD4K0OcEwQbi2Iw4M"
- "D6aQv/r3XbK+cLuW2wIDAQAB"
-};
-
-const uint8_t plaintext[] = { // plaintext: RSA-Encrypt-Test
- 0x52, 0x53, 0x41, 0x2d, 0x45, 0x6e, 0x63, 0x72,
- 0x79, 0x70, 0x74, 0x2d, 0x54, 0x65, 0x73, 0x74
-};
-
-const uint8_t ciphertext[] = {
- 0x33, 0xfb, 0x32, 0xd4, 0x2d, 0x45, 0x75, 0x3f, 0x34, 0xde, 0x3b,
- 0xaa, 0x80, 0x5f, 0x74, 0x6f, 0xf0, 0x3f, 0x01, 0x31, 0xdd, 0x2b,
- 0x85, 0x02, 0x1b, 0xed, 0x2d, 0x16, 0x1b, 0x96, 0xe5, 0x77, 0xde,
- 0xcd, 0x44, 0xe5, 0x3c, 0x32, 0xb6, 0x9a, 0xa9, 0x5d, 0xaa, 0x4b,
- 0x94, 0xe2, 0xac, 0x4a, 0x4e, 0xf5, 0x35, 0x21, 0xd0, 0x03, 0x4a,
- 0xa7, 0x53, 0xae, 0x13, 0x08, 0x63, 0x38, 0x2c, 0x92, 0xe3, 0x44,
- 0x64, 0xbf, 0x33, 0x84, 0x8e, 0x51, 0x9d, 0xb9, 0x85, 0x83, 0xf6,
- 0x8e, 0x09, 0xc1, 0x72, 0xb9, 0x90, 0x5d, 0x48, 0x63, 0xec, 0xd0,
- 0xcc, 0xfa, 0xab, 0x44, 0x2b, 0xaa, 0xa6, 0xb6, 0xca, 0xec, 0x2b,
- 0x5f, 0xbe, 0x77, 0xa5, 0x52, 0xeb, 0x0a, 0xaa, 0xf2, 0x2a, 0x19,
- 0x62, 0x80, 0x14, 0x87, 0x42, 0x35, 0xd0, 0xb6, 0xa3, 0x47, 0x4e,
- 0xb6, 0x1a, 0x88, 0xa3, 0x16, 0xb2, 0x19
-};
+// plaintext: RSA-Encrypt-Test
+const uint8_t plainText[] = { 0x52, 0x53, 0x41, 0x2d, 0x45, 0x6e, 0x63, 0x72,
+ 0x79, 0x70, 0x74, 0x2d, 0x54, 0x65, 0x73, 0x74};
BOOST_AUTO_TEST_SUITE(TestRsaAlgorithm)
+BOOST_AUTO_TEST_CASE(TransformEncryptionDecryption)
+{
+ RsaKeyParams params;
+ auto sKey = security::transform::generatePrivateKey(params);
+ security::transform::PublicKey pKey;
+ ConstBufferPtr pKeyBits = sKey->derivePublicKey();
+ pKey.loadPkcs8(pKeyBits->data(), pKeyBits->size());
+
+ auto cipherText = pKey.encrypt(plainText, sizeof(plainText));
+ auto decrypted = sKey->decrypt(cipherText->data(), cipherText->size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(plainText, plainText + sizeof(plainText),
+ decrypted->begin(), decrypted->end());
+}
+
BOOST_AUTO_TEST_CASE(EncryptionDecryption)
{
- RandomNumberGenerator rng;
RsaKeyParams params;
- EncryptParams eparams(tlv::AlgorithmRsaOaep);
+ DecryptKey<Rsa> sKey = Rsa::generateKey(params);
+ EncryptKey<Rsa> pKey = Rsa::deriveEncryptKey(sKey.getKeyBits());
- OBufferStream privateKeyBuffer, publicKeyBuffer;
- StringSource privPipe(privateKey, true,
- new Base64Decoder(new FileSink(privateKeyBuffer)));
- StringSource publPipe(publicKey, true,
- new Base64Decoder(new FileSink(publicKeyBuffer)));
-
- DecryptKey<Rsa> decryptKey(std::move(*(privateKeyBuffer.buf())));
- EncryptKey<Rsa> encryptKey = Rsa::deriveEncryptKey(decryptKey.getKeyBits());
-
- const Buffer& encodedPublicKey = *(publicKeyBuffer.buf());
- const Buffer& derivedPublicKey = encryptKey.getKeyBits();
- const Buffer& encodedPrivateKey = *(privateKeyBuffer.buf());
- const Buffer& derivedPrivateKey = decryptKey.getKeyBits();
-
- BOOST_CHECK_EQUAL_COLLECTIONS(encodedPublicKey.begin(),
- encodedPublicKey.end(),
- derivedPublicKey.begin(),
- derivedPublicKey.end());
-
- const Buffer& encryptBuf = Rsa::encrypt(encodedPublicKey.buf(), encodedPublicKey.size(),
- plaintext, sizeof(plaintext),
- eparams);
-
- const Buffer& recvBuf = Rsa::decrypt(encodedPrivateKey.buf(), encodedPrivateKey.size(),
- encryptBuf.buf(), encryptBuf.size(),
- eparams);
-
- BOOST_CHECK_EQUAL_COLLECTIONS(plaintext, plaintext + sizeof(plaintext),
- recvBuf.begin(), recvBuf.end());
-
- const Buffer& convBuf = Rsa::decrypt(derivedPrivateKey.buf(), derivedPrivateKey.size(),
- ciphertext, sizeof(ciphertext),
- eparams);
-
- BOOST_CHECK_EQUAL_COLLECTIONS(plaintext, plaintext + sizeof(plaintext),
- convBuf.begin(), convBuf.end());
+ auto cipherText = Rsa::encrypt(pKey.getKeyBits().data(), pKey.getKeyBits().size(),
+ plainText, sizeof(plainText));
+ auto decrypted = Rsa::decrypt(sKey.getKeyBits().data(), sKey.getKeyBits().size(),
+ cipherText.data(), cipherText.size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(plainText, plainText + sizeof(plainText),
+ decrypted.begin(), decrypted.end());
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit-tests/consumer-db.t.cpp b/tests/unit-tests/consumer-db.t.cpp
index bad6213..67c33ce 100644
--- a/tests/unit-tests/consumer-db.t.cpp
+++ b/tests/unit-tests/consumer-db.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,13 +16,13 @@
* 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>
*/
#include "consumer-db.hpp"
-#include "algo/rsa.hpp"
-#include "algo/aes.hpp"
#include "boost-test.hpp"
+#include "algo/aes.hpp"
+#include "algo/rsa.hpp"
#include <boost/filesystem.hpp>
@@ -47,9 +47,8 @@
void
generateRsaKey(Buffer& encryptionKeyBuf, Buffer& decryptionKeyBuf)
{
- RandomNumberGenerator rng;
RsaKeyParams params;
- DecryptKey<algo::Rsa> dKey = algo::Rsa::generateKey(rng, params);
+ DecryptKey<algo::Rsa> dKey = algo::Rsa::generateKey(params);
decryptionKeyBuf = dKey.getKeyBits();
EncryptKey<algo::Rsa> eKey = algo::Rsa::deriveEncryptKey(decryptionKeyBuf);
encryptionKeyBuf = eKey.getKeyBits();
@@ -58,9 +57,8 @@
void
generateAesKey(Buffer& encryptionKeyBuf, Buffer& decryptionKeyBuf)
{
- RandomNumberGenerator rng;
AesKeyParams params;
- DecryptKey<algo::Aes> memberDecryptKey = algo::Aes::generateKey(rng, params);
+ DecryptKey<algo::Aes> memberDecryptKey = algo::Aes::generateKey(params);
decryptionKeyBuf = memberDecryptKey.getKeyBits();
EncryptKey<algo::Aes> memberEncryptKey = algo::Aes::deriveEncryptKey(decryptionKeyBuf);
encryptionKeyBuf = memberEncryptKey.getKeyBits();
@@ -89,8 +87,7 @@
db.addKey(keyName, dKeyBuf);
Buffer resultBuf = db.getKey(keyName);
- BOOST_CHECK_EQUAL_COLLECTIONS(dKeyBuf.begin(), dKeyBuf.end(),
- resultBuf.begin(), resultBuf.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(dKeyBuf.begin(), dKeyBuf.end(), resultBuf.begin(), resultBuf.end());
db.deleteKey(keyName);
resultBuf = db.getKey(keyName);
@@ -115,8 +112,7 @@
db.addKey(keyName, dKeyBuf);
Buffer resultBuf = db.getKey(keyName);
- BOOST_CHECK_EQUAL_COLLECTIONS(dKeyBuf.begin(), dKeyBuf.end(),
- resultBuf.begin(), resultBuf.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(dKeyBuf.begin(), dKeyBuf.end(), resultBuf.begin(), resultBuf.end());
db.deleteKey(keyName);
resultBuf = db.getKey(keyName);
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
diff --git a/tests/unit-tests/encrypted-content.t.cpp b/tests/unit-tests/encrypted-content.t.cpp
index f6877fc..413fad9 100644
--- a/tests/unit-tests/encrypted-content.t.cpp
+++ b/tests/unit-tests/encrypted-content.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
diff --git a/tests/unit-tests/group-manager-db.t.cpp b/tests/unit-tests/group-manager-db.t.cpp
index 16a2c81..0800af3 100644
--- a/tests/unit-tests/group-manager-db.t.cpp
+++ b/tests/unit-tests/group-manager-db.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,13 +16,12 @@
* 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>
*/
#include "group-manager-db.hpp"
-#include "algo/rsa.hpp"
#include "boost-test.hpp"
-
+#include "algo/rsa.hpp"
#include <boost/filesystem.hpp>
namespace ndn {
@@ -136,9 +135,8 @@
Schedule schedule(scheduleBlock);
// create member
- RandomNumberGenerator rng;
RsaKeyParams params;
- DecryptKey<algo::Rsa> decryptKey = algo::Rsa::generateKey(rng, params);
+ DecryptKey<algo::Rsa> decryptKey = algo::Rsa::generateKey(params);
EncryptKey<algo::Rsa> encryptKey = algo::Rsa::deriveEncryptKey(decryptKey.getKeyBits());
Buffer keyBuf = encryptKey.getKeyBits();
diff --git a/tests/unit-tests/group-manager.t.cpp b/tests/unit-tests/group-manager.t.cpp
index dc64eda..5994d66 100644
--- a/tests/unit-tests/group-manager.t.cpp
+++ b/tests/unit-tests/group-manager.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,17 +16,16 @@
* 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>
*/
#include "group-manager.hpp"
#include "boost-test.hpp"
-#include "algo/rsa.hpp"
-#include "algo/aes.hpp"
#include "encrypted-content.hpp"
-
-#include <boost/filesystem.hpp>
+#include "algo/aes.hpp"
+#include "algo/rsa.hpp"
#include <ndn-cxx/encoding/buffer-stream.hpp>
+#include <boost/filesystem.hpp>
#include <string>
namespace ndn {
@@ -35,33 +34,25 @@
using namespace boost::posix_time;
-const uint8_t SIG_INFO[] = {
- 0x16, 0x1b, // SignatureInfo
- 0x1b, 0x01, // SignatureType
- 0x01,
- 0x1c, 0x16, // KeyLocator
- 0x07, 0x14, // Name
- 0x08, 0x04,
- 0x74, 0x65, 0x73, 0x74,
- 0x08, 0x03,
- 0x6b, 0x65, 0x79,
- 0x08, 0x07,
- 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72
-};
+const uint8_t SIG_INFO[] = {0x16, 0x1b, // SignatureInfo
+ 0x1b, 0x01, // SignatureType
+ 0x01, 0x1c, 0x16, // KeyLocator
+ 0x07, 0x14, // Name
+ 0x08, 0x04, 0x74, 0x65, 0x73, 0x74, 0x08, 0x03, 0x6b, 0x65,
+ 0x79, 0x08, 0x07, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x6f, 0x72};
-const uint8_t SIG_VALUE[] = {
- 0x17, 0x80, // SignatureValue
- 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31, 0xec,
- 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9, 0xb3, 0xc6,
- 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8, 0xb3, 0x6a, 0x38,
- 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6, 0x4d, 0x10, 0x1d, 0xdc,
- 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96, 0x5e, 0xc0, 0x62, 0x0b, 0xcf,
- 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41, 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9,
- 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d, 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8,
- 0x55, 0xf6, 0x1c, 0x19, 0x0b, 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7,
- 0xaa, 0x0d, 0x14, 0x58, 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3,
- 0xfc, 0x90, 0x7a, 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1
-};
+const uint8_t SIG_VALUE[] = {0x17, 0x80, // SignatureValue
+ 0x2f, 0xd6, 0xf1, 0x6e, 0x80, 0x6f, 0x10, 0xbe, 0xb1, 0x6f, 0x3e, 0x31,
+ 0xec, 0xe3, 0xb9, 0xea, 0x83, 0x30, 0x40, 0x03, 0xfc, 0xa0, 0x13, 0xd9,
+ 0xb3, 0xc6, 0x25, 0x16, 0x2d, 0xa6, 0x58, 0x41, 0x69, 0x62, 0x56, 0xd8,
+ 0xb3, 0x6a, 0x38, 0x76, 0x56, 0xea, 0x61, 0xb2, 0x32, 0x70, 0x1c, 0xb6,
+ 0x4d, 0x10, 0x1d, 0xdc, 0x92, 0x8e, 0x52, 0xa5, 0x8a, 0x1d, 0xd9, 0x96,
+ 0x5e, 0xc0, 0x62, 0x0b, 0xcf, 0x3a, 0x9d, 0x7f, 0xca, 0xbe, 0xa1, 0x41,
+ 0x71, 0x85, 0x7a, 0x8b, 0x5d, 0xa9, 0x64, 0xd6, 0x66, 0xb4, 0xe9, 0x8d,
+ 0x0c, 0x28, 0x43, 0xee, 0xa6, 0x64, 0xe8, 0x55, 0xf6, 0x1c, 0x19, 0x0b,
+ 0xef, 0x99, 0x25, 0x1e, 0xdc, 0x78, 0xb3, 0xa7, 0xaa, 0x0d, 0x14, 0x58,
+ 0x30, 0xe5, 0x37, 0x6a, 0x6d, 0xdb, 0x56, 0xac, 0xa3, 0xfc, 0x90, 0x7a,
+ 0xb8, 0x66, 0x9c, 0x0e, 0xf6, 0xb7, 0x64, 0xd1};
class GroupManagerFixture
{
@@ -72,18 +63,15 @@
boost::filesystem::create_directories(tmpPath);
// generate the certificate public key
- RandomNumberGenerator rng;
RsaKeyParams params;
- DecryptKey<algo::Rsa> memberDecryptKey = algo::Rsa::generateKey(rng, params);
+ DecryptKey<algo::Rsa> memberDecryptKey = algo::Rsa::generateKey(params);
decryptKeyBuf = memberDecryptKey.getKeyBits();
EncryptKey<algo::Rsa> memberEncryptKey = algo::Rsa::deriveEncryptKey(decryptKeyBuf);
encryptKeyBuf = memberEncryptKey.getKeyBits();
// generate certificate
cert.setName(Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"));
- PublicKey contentPubKey(encryptKeyBuf.buf(), encryptKeyBuf.size());
- cert.setPublicKeyInfo(contentPubKey);
- cert.encode();
+ cert.setContent(encryptKeyBuf.data(), encryptKeyBuf.size());
Block sigInfoBlock(SIG_INFO, sizeof(SIG_INFO));
Block sigValueBlock(SIG_VALUE, sizeof(SIG_VALUE));
@@ -101,13 +89,20 @@
Schedule schedule1;
RepetitiveInterval interval11(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval12(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 6, 8, 1, RepetitiveInterval::RepeatUnit::DAY);
+ 6,
+ 8,
+ 1,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval13(from_iso_string("20150827T000000"),
from_iso_string("20150827T000000"),
- 7, 8);
+ 7,
+ 8);
schedule1.addWhiteInterval(interval11);
schedule1.addWhiteInterval(interval12);
schedule1.addBlackInterval(interval13);
@@ -116,13 +111,18 @@
Schedule schedule2;
RepetitiveInterval interval21(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 9, 12, 1, RepetitiveInterval::RepeatUnit::DAY);
+ 9,
+ 12,
+ 1,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval22(from_iso_string("20150827T000000"),
from_iso_string("20150827T000000"),
- 6, 8);
+ 6,
+ 8);
RepetitiveInterval interval23(from_iso_string("20150827T000000"),
from_iso_string("20150827T000000"),
- 2, 4);
+ 2,
+ 4);
schedule2.addWhiteInterval(interval21);
schedule2.addWhiteInterval(interval22);
schedule2.addBlackInterval(interval23);
@@ -156,7 +156,7 @@
boost::filesystem::path tmpPath;
Buffer decryptKeyBuf;
Buffer encryptKeyBuf;
- IdentityCertificate cert;
+ Certificate cert;
};
BOOST_FIXTURE_TEST_SUITE(TestGroupManager, GroupManagerFixture)
@@ -169,11 +169,15 @@
GroupManager manager(Name("Alice"), Name("data_type"), dbDir, 2048, 1);
Block newCertBlock = cert.wireEncode();
- IdentityCertificate newCert(newCertBlock);
+ Certificate newCert(newCertBlock);
// encrypt D-KEY
- Data data = manager.createDKeyData("20150825T000000", "20150827T000000", Name("/ndn/memberA/KEY"),
- decryptKeyBuf, newCert.getPublicKeyInfo().get());
+ Data data = manager.createDKeyData("20150825T000000",
+ "20150827T000000",
+ Name("/ndn/memberA/KEY"),
+ decryptKeyBuf,
+ Buffer(newCert.getContent().value(),
+ newCert.getContent().value_size()));
// verify encrypted D-KEY
Block dataContent = data.getContent();
@@ -189,9 +193,10 @@
BOOST_CHECK_EQUAL(encryptedNonce.getAlgorithmType(), tlv::AlgorithmRsaOaep);
const Buffer& bufferNonce = encryptedNonce.getPayload();
- algo::EncryptParams decryptParams(tlv::AlgorithmRsaOaep);
- Buffer nonce = algo::Rsa::decrypt(decryptKeyBuf.buf(), decryptKeyBuf.size(),
- bufferNonce.buf(), bufferNonce.size(), decryptParams);
+ Buffer nonce = algo::Rsa::decrypt(decryptKeyBuf.data(),
+ decryptKeyBuf.size(),
+ bufferNonce.data(),
+ bufferNonce.size());
// get D-KEY
contentIterator++;
@@ -201,16 +206,20 @@
BOOST_CHECK_EQUAL(encryptedPayload.getInitialVector().size(), 16);
BOOST_CHECK_EQUAL(encryptedPayload.getAlgorithmType(), tlv::AlgorithmAesCbc);
- decryptParams.setAlgorithmType(tlv::AlgorithmAesCbc);
- decryptParams.setIV(encryptedPayload.getInitialVector().buf(),
+ algo::EncryptParams decryptParams(tlv::AlgorithmAesCbc);
+ decryptParams.setIV(encryptedPayload.getInitialVector().data(),
encryptedPayload.getInitialVector().size());
const Buffer& bufferPayload = encryptedPayload.getPayload();
- Buffer largePayload = algo::Aes::decrypt(nonce.buf(), nonce.size(),
- bufferPayload.buf(), bufferPayload.size(),
+ Buffer largePayload = algo::Aes::decrypt(nonce.data(),
+ nonce.size(),
+ bufferPayload.data(),
+ bufferPayload.size(),
decryptParams);
- BOOST_CHECK_EQUAL_COLLECTIONS(largePayload.begin(), largePayload.end(),
- decryptKeyBuf.begin(), decryptKeyBuf.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(largePayload.begin(),
+ largePayload.end(),
+ decryptKeyBuf.begin(),
+ decryptKeyBuf.end());
}
BOOST_AUTO_TEST_CASE(CreateEKeyData)
@@ -228,9 +237,10 @@
"/Alice/READ/data_type/E-KEY/20150825T090000/20150825T110000");
Buffer contentBuf(data.getContent().value(), data.getContent().value_size());
- BOOST_CHECK_EQUAL_COLLECTIONS(encryptKeyBuf.begin(), encryptKeyBuf.end(),
- contentBuf.begin(), contentBuf.end());
-
+ BOOST_CHECK_EQUAL_COLLECTIONS(encryptKeyBuf.begin(),
+ encryptKeyBuf.end(),
+ contentBuf.begin(),
+ contentBuf.end());
}
BOOST_AUTO_TEST_CASE(CalculateInterval)
@@ -286,13 +296,14 @@
std::list<Data>::iterator dataIterator = result.begin();
BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
"/Alice/READ/data_type/E-KEY/20150825T090000/20150825T100000");
- EncryptKey<algo::Rsa> groupEKey(Buffer(dataIterator->getContent().value(),
- dataIterator->getContent().value_size()));
+
+ EncryptKey<algo::Rsa> groupEKey(
+ Buffer(dataIterator->getContent().value(), dataIterator->getContent().value_size()));
// second data and decrypt
dataIterator++;
BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
- "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/ksk-123");
+ "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/KEY/ksk-123");
//////////////////////////////////////////////////////////////////////// start decryption
Block dataContent = dataIterator->getContent();
@@ -308,11 +319,12 @@
BOOST_CHECK_EQUAL(encryptedNonce.getInitialVector().size(), 0);
BOOST_CHECK_EQUAL(encryptedNonce.getAlgorithmType(), tlv::AlgorithmRsaOaep);
- algo::EncryptParams decryptParams(tlv::AlgorithmRsaOaep);
const Buffer& bufferNonce = encryptedNonce.getPayload();
- Buffer nonce = algo::Rsa::decrypt(decryptKeyBuf.buf(), decryptKeyBuf.size(),
- bufferNonce.buf(), bufferNonce.size(), decryptParams);
+ Buffer nonce = algo::Rsa::decrypt(decryptKeyBuf.data(),
+ decryptKeyBuf.size(),
+ bufferNonce.data(),
+ bufferNonce.size());
// get buffer payload
contentIterator++;
Block payloadContent(*contentIterator);
@@ -321,34 +333,37 @@
BOOST_CHECK_EQUAL(encryptedPayload.getInitialVector().size(), 16);
BOOST_CHECK_EQUAL(encryptedPayload.getAlgorithmType(), tlv::AlgorithmAesCbc);
- decryptParams.setAlgorithmType(tlv::AlgorithmAesCbc);
- decryptParams.setIV(encryptedPayload.getInitialVector().buf(),
+ algo::EncryptParams decryptParams(tlv::AlgorithmAesCbc);
+ decryptParams.setIV(encryptedPayload.getInitialVector().data(),
encryptedPayload.getInitialVector().size());
const Buffer& bufferPayload = encryptedPayload.getPayload();
- Buffer largePayload = algo::Aes::decrypt(nonce.buf(), nonce.size(),
- bufferPayload.buf(), bufferPayload.size(),
+ Buffer largePayload = algo::Aes::decrypt(nonce.data(),
+ nonce.size(),
+ bufferPayload.data(),
+ bufferPayload.size(),
decryptParams);
// get group D-KEY
- DecryptKey<algo::Rsa> groupDKey(Buffer(largePayload.buf(), largePayload.size()));
+ DecryptKey<algo::Rsa> groupDKey(Buffer(largePayload.data(), largePayload.size()));
/////////////////////////////////////////////////////////////////////// end decryption
// check the D-KEY
EncryptKey<algo::Rsa> derivedGroupEKey = algo::Rsa::deriveEncryptKey(groupDKey.getKeyBits());
- BOOST_CHECK_EQUAL_COLLECTIONS(groupEKey.getKeyBits().begin(), groupEKey.getKeyBits().end(),
+ BOOST_CHECK_EQUAL_COLLECTIONS(groupEKey.getKeyBits().begin(),
+ groupEKey.getKeyBits().end(),
derivedGroupEKey.getKeyBits().begin(),
derivedGroupEKey.getKeyBits().end());
// third data and decrypt
dataIterator++;
BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
- "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberB/ksk-123");
+ "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberB/KEY/ksk-123");
// second data and decrypt
dataIterator++;
BOOST_CHECK_EQUAL(dataIterator->getName().toUri(),
- "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberC/ksk-123");
+ "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberC/KEY/ksk-123");
// invalid time stamp to get group key
TimeStamp tp2(from_iso_string("20150826T083000"));
@@ -378,13 +393,13 @@
std::list<Data>::iterator dataIterator1 = result1.begin();
BOOST_CHECK_EQUAL(dataIterator1->getName().toUri(),
"/Alice/READ/data_type/E-KEY/20150825T090000/20150825T100000");
- EncryptKey<algo::Rsa> groupEKey1(Buffer(dataIterator1->getContent().value(),
- dataIterator1->getContent().value_size()));
+ EncryptKey<algo::Rsa> groupEKey1(
+ Buffer(dataIterator1->getContent().value(), dataIterator1->getContent().value_size()));
// second data
dataIterator1++;
BOOST_CHECK_EQUAL(dataIterator1->getName().toUri(),
- "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/ksk-123");
+ "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/KEY/ksk-123");
// add new members to the database
Block dataBlock = cert.wireEncode();
@@ -399,19 +414,21 @@
std::list<Data>::iterator dataIterator2 = result2.begin();
BOOST_CHECK_EQUAL(dataIterator2->getName().toUri(),
"/Alice/READ/data_type/E-KEY/20150825T090000/20150825T100000");
- EncryptKey<algo::Rsa> groupEKey2(Buffer(dataIterator2->getContent().value(),
- dataIterator2->getContent().value_size()));
- BOOST_CHECK_EQUAL_COLLECTIONS(groupEKey1.getKeyBits().begin(), groupEKey1.getKeyBits().end(),
- groupEKey2.getKeyBits().begin(), groupEKey2.getKeyBits().end());
+ EncryptKey<algo::Rsa> groupEKey2(
+ Buffer(dataIterator2->getContent().value(), dataIterator2->getContent().value_size()));
+ BOOST_CHECK_EQUAL_COLLECTIONS(groupEKey1.getKeyBits().begin(),
+ groupEKey1.getKeyBits().end(),
+ groupEKey2.getKeyBits().begin(),
+ groupEKey2.getKeyBits().end());
// second data
dataIterator2++;
BOOST_CHECK_EQUAL(dataIterator2->getName().toUri(),
- "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/ksk-123");
+ "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/KEY/ksk-123");
}
BOOST_AUTO_TEST_SUITE_END()
-} // namespace test
+} // namespace tests
} // namespace gep
} // namespace ndn
diff --git a/tests/unit-tests/interval.t.cpp b/tests/unit-tests/interval.t.cpp
index e9cf6d9..c50384a 100644
--- a/tests/unit-tests/interval.t.cpp
+++ b/tests/unit-tests/interval.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#include "interval.hpp"
@@ -33,8 +33,7 @@
BOOST_AUTO_TEST_CASE(Construction)
{
// construct with the right parameters
- Interval interval1(from_iso_string("20150825T120000"),
- from_iso_string("20150825T160000"));
+ Interval interval1(from_iso_string("20150825T120000"), from_iso_string("20150825T160000"));
BOOST_CHECK_EQUAL(to_iso_string(interval1.getStartTime()), "20150825T120000");
BOOST_CHECK_EQUAL(to_iso_string(interval1.getEndTime()), "20150825T160000");
BOOST_CHECK_EQUAL(interval1.isValid(), true);
@@ -51,8 +50,7 @@
BOOST_AUTO_TEST_CASE(CoverTimePoint)
{
- Interval interval(from_iso_string("20150825T120000"),
- from_iso_string("20150825T160000"));
+ Interval interval(from_iso_string("20150825T120000"), from_iso_string("20150825T160000"));
TimeStamp tp1 = from_iso_string("20150825T120000");
TimeStamp tp2 = from_iso_string("20150825T130000");
@@ -67,23 +65,17 @@
BOOST_AUTO_TEST_CASE(IntersectionAndUnion)
{
- Interval interval1(from_iso_string("20150825T030000"),
- from_iso_string("20150825T050000"));
+ Interval interval1(from_iso_string("20150825T030000"), from_iso_string("20150825T050000"));
// no intersection
- Interval interval2(from_iso_string("20150825T050000"),
- from_iso_string("20150825T070000"));
+ Interval interval2(from_iso_string("20150825T050000"), from_iso_string("20150825T070000"));
// no intersection
- Interval interval3(from_iso_string("20150825T060000"),
- from_iso_string("20150825T070000"));
+ Interval interval3(from_iso_string("20150825T060000"), from_iso_string("20150825T070000"));
// there's an intersection
- Interval interval4(from_iso_string("20150825T010000"),
- from_iso_string("20150825T040000"));
+ Interval interval4(from_iso_string("20150825T010000"), from_iso_string("20150825T040000"));
// right in the interval1, there's an intersection
- Interval interval5(from_iso_string("20150825T030000"),
- from_iso_string("20150825T040000"));
+ Interval interval5(from_iso_string("20150825T030000"), from_iso_string("20150825T040000"));
// wrap the interval1, there's an intersection
- Interval interval6(from_iso_string("20150825T010000"),
- from_iso_string("20150825T050000"));
+ Interval interval6(from_iso_string("20150825T010000"), from_iso_string("20150825T050000"));
// empty interval
Interval interval7(true);
diff --git a/tests/unit-tests/producer-db.t.cpp b/tests/unit-tests/producer-db.t.cpp
index bcf09e0..881f40e 100644
--- a/tests/unit-tests/producer-db.t.cpp
+++ b/tests/unit-tests/producer-db.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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.
@@ -20,8 +20,8 @@
*/
#include "producer-db.hpp"
-#include "algo/aes.hpp"
#include "boost-test.hpp"
+#include "algo/aes.hpp"
#include <boost/filesystem.hpp>
@@ -59,10 +59,9 @@
ProducerDB db(dbDir);
// create member
- RandomNumberGenerator rng;
AesKeyParams params(128);
- Buffer keyBuf1 = algo::Aes::generateKey(rng, params).getKeyBits();
- Buffer keyBuf2 = algo::Aes::generateKey(rng, params).getKeyBits();
+ Buffer keyBuf1 = algo::Aes::generateKey(params).getKeyBits();
+ Buffer keyBuf2 = algo::Aes::generateKey(params).getKeyBits();
system_clock::TimePoint point1(time::fromIsoString("20150101T100000"));
system_clock::TimePoint point2(time::fromIsoString("20150102T100000"));
@@ -85,16 +84,10 @@
// get content key
Buffer keyResult = db.getContentKey(point1);
- BOOST_CHECK_EQUAL_COLLECTIONS(keyResult.begin(),
- keyResult.end(),
- keyBuf1.begin(),
- keyBuf1.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(keyResult.begin(), keyResult.end(), keyBuf1.begin(), keyBuf1.end());
keyResult = db.getContentKey(point3);
- BOOST_CHECK_EQUAL_COLLECTIONS(keyResult.begin(),
- keyResult.end(),
- keyBuf2.begin(),
- keyBuf2.end());
+ BOOST_CHECK_EQUAL_COLLECTIONS(keyResult.begin(), keyResult.end(), keyBuf2.begin(), keyBuf2.end());
// throw exception when there is no such timeslot in database
BOOST_CHECK_THROW(db.getContentKey(point4), ProducerDB::Error);
diff --git a/tests/unit-tests/producer.t.cpp b/tests/unit-tests/producer.t.cpp
old mode 100755
new mode 100644
index 37d08d2..87bddaa
--- a/tests/unit-tests/producer.t.cpp
+++ b/tests/unit-tests/producer.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.
@@ -18,16 +18,13 @@
*/
#include "producer.hpp"
-#include "algo/encryptor.hpp"
-#include "algo/rsa.hpp"
-#include "algo/aes.hpp"
#include "encrypted-content.hpp"
#include "unit-test-time-fixture.hpp"
-#include "random-number-generator.hpp"
-
-#include <ndn-cxx/util/dummy-client-face.hpp>
-
+#include "algo/aes.hpp"
+#include "algo/encryptor.hpp"
+#include "algo/rsa.hpp"
#include "boost-test.hpp"
+#include <ndn-cxx/util/dummy-client-face.hpp>
#include <boost/asio.hpp>
#include <boost/filesystem.hpp>
@@ -35,12 +32,10 @@
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};
class ProducerFixture : public UnitTestTimeFixture
{
@@ -65,16 +60,15 @@
void
createEncryptionKey(Name eKeyName, const Name& timeMarker)
{
- RandomNumberGenerator rng;
RsaKeyParams params;
eKeyName.append(timeMarker);
- Buffer dKeyBuf = algo::Rsa::generateKey(rng, params).getKeyBits();
+ Buffer dKeyBuf = algo::Rsa::generateKey(params).getKeyBits();
Buffer eKeyBuf = algo::Rsa::deriveEncryptKey(dKeyBuf).getKeyBits();
decryptionKeys[eKeyName] = dKeyBuf;
shared_ptr<Data> keyData = make_shared<Data>(eKeyName);
- keyData->setContent(eKeyBuf.buf(), eKeyBuf.size());
+ keyData->setContent(eKeyBuf.data(), eKeyBuf.size());
keyChain.sign(*keyData);
encryptionKeys[eKeyName] = keyData;
}
@@ -156,16 +150,17 @@
}
face2.setInterestFilter(prefix,
- [&] (const InterestFilter&, const Interest& i) {
- Name interestName = i.getName();
- interestName.append(timeMarker);
- BOOST_REQUIRE_EQUAL(encryptionKeys.find(interestName) !=
- encryptionKeys.end(), true);
- face2.put(*(encryptionKeys[interestName]));
- return;
- },
- RegisterPrefixSuccessCallback(),
- [] (const Name&, const std::string& e) { });
+ [&] (const InterestFilter&, const Interest& i) {
+ Name interestName = i.getName();
+ interestName.append(timeMarker);
+ BOOST_REQUIRE_EQUAL(encryptionKeys.find(interestName) !=
+ encryptionKeys.end(),
+ true);
+ face2.put(*(encryptionKeys[interestName]));
+ return;
+ },
+ RegisterPrefixSuccessCallback(),
+ [] (const Name&, const std::string& e) {});
do {
advanceClocks(time::milliseconds(10), 20);
@@ -177,50 +172,46 @@
ProducerDB testDb(dbDir);
Buffer contentKey;
- auto checkEncryptionKeys =
- [&](const std::vector<Data>& result,
- const time::system_clock::TimePoint& testTime,
- const name::Component& roundedTime) {
- BOOST_CHECK_EQUAL(testDb.hasContentKey(testTime), true);
- contentKey = testDb.getContentKey(testTime);
+ auto checkEncryptionKeys = [&] (const std::vector<Data>& result,
+ const time::system_clock::TimePoint& testTime,
+ const name::Component& roundedTime) {
+ BOOST_CHECK_EQUAL(testDb.hasContentKey(testTime), true);
+ contentKey = testDb.getContentKey(testTime);
- algo::EncryptParams params(tlv::AlgorithmRsaOaep);
- std::vector<Data>::const_iterator it;
- for (it = result.begin(); it != result.end(); ++it) {
- Name keyName = it->getName();
- BOOST_CHECK_EQUAL(keyName.getSubName(0,6), cKeyName);
- BOOST_CHECK_EQUAL(keyName.get(6), roundedTime);
- BOOST_CHECK_EQUAL(keyName.get(7), NAME_COMPONENT_FOR);
- BOOST_CHECK_EQUAL(decryptionKeys.find(keyName.getSubName(8)) !=
- decryptionKeys.end(), true);
- Name testName = it->getName().getSubName(-8);
- Buffer decryptionKey;
+ std::vector<Data>::const_iterator it;
+ for (it = result.begin(); it != result.end(); ++it) {
+ Name keyName = it->getName();
+ BOOST_CHECK_EQUAL(keyName.getSubName(0, 6), cKeyName);
+ BOOST_CHECK_EQUAL(keyName.get(6), roundedTime);
+ BOOST_CHECK_EQUAL(keyName.get(7), NAME_COMPONENT_FOR);
+ BOOST_CHECK_EQUAL(decryptionKeys.find(keyName.getSubName(8)) != decryptionKeys.end(), true);
+ Name testName = it->getName().getSubName(-8);
+ Buffer decryptionKey;
- decryptionKey = decryptionKeys.at(keyName.getSubName(8));
- BOOST_CHECK_EQUAL(decryptionKey.size() != 0, true);
- Block encryptedKeyBlock = it->getContent();
- encryptedKeyBlock.parse();
+ decryptionKey = decryptionKeys.at(keyName.getSubName(8));
+ BOOST_CHECK_EQUAL(decryptionKey.size() != 0, true);
+ Block encryptedKeyBlock = it->getContent();
+ encryptedKeyBlock.parse();
- EncryptedContent content(*(encryptedKeyBlock.elements_begin()));
- const Buffer& encryptedKey = content.getPayload();
- Buffer retrievedKey = algo::Rsa::decrypt(decryptionKey.buf(),
- decryptionKey.size(),
- encryptedKey.buf(),
- encryptedKey.size(),
- params);
+ EncryptedContent content(*(encryptedKeyBlock.elements_begin()));
+ const Buffer& encryptedKey = content.getPayload();
+ Buffer retrievedKey = algo::Rsa::decrypt(decryptionKey.data(),
+ decryptionKey.size(),
+ encryptedKey.data(),
+ encryptedKey.size());
- BOOST_CHECK_EQUAL_COLLECTIONS(contentKey.begin(),
- contentKey.end(),
- retrievedKey.begin(),
- retrievedKey.end());
- }
- BOOST_CHECK_EQUAL(result.size(), 3);
- };
+ BOOST_CHECK_EQUAL_COLLECTIONS(contentKey.begin(),
+ contentKey.end(),
+ retrievedKey.begin(),
+ retrievedKey.end());
+ }
+ BOOST_CHECK_EQUAL(result.size(), 3);
+ };
// Initial test to confirm that keys are created for this timeslot
Name contentKeyName1 =
- producer.createContentKey(testTime1,
- std::bind(checkEncryptionKeys, _1, testTime1, testTimeRounded1));
+ producer.createContentKey(testTime1,
+ std::bind(checkEncryptionKeys, _1, testTime1, testTimeRounded1));
do {
advanceClocks(time::milliseconds(10), 20);
@@ -228,8 +219,8 @@
// Verify that we do not repeat the search for e-keys, don't advance clock
Name contentKeyName2 =
- producer.createContentKey(testTime2,
- std::bind(checkEncryptionKeys, _1, testTime2, testTimeRounded2));
+ producer.createContentKey(testTime2,
+ std::bind(checkEncryptionKeys, _1, testTime2, testTimeRounded2));
// Confirm content key names are correct
BOOST_CHECK_EQUAL(contentKeyName1.getPrefix(-1), cKeyName);
@@ -242,10 +233,10 @@
producer.produce(testData, testTime2, DATA_CONTEN, sizeof(DATA_CONTEN));
Name producedName = testData.getName();
- BOOST_CHECK_EQUAL(producedName.getSubName(0,5), cKeyName.getPrefix(-1));
+ BOOST_CHECK_EQUAL(producedName.getSubName(0, 5), cKeyName.getPrefix(-1));
BOOST_CHECK_EQUAL(producedName.get(5), testTimeComponent2);
BOOST_CHECK_EQUAL(producedName.get(6), NAME_COMPONENT_FOR);
- BOOST_CHECK_EQUAL(producedName.getSubName(7,6), cKeyName);
+ BOOST_CHECK_EQUAL(producedName.getSubName(7, 6), cKeyName);
BOOST_CHECK_EQUAL(producedName.get(13), testTimeRounded2);
Block dataBlock = testData.getContent();
@@ -256,9 +247,9 @@
const Buffer& iv = dataContent.getInitialVector();
algo::EncryptParams params(tlv::AlgorithmAesCbc, 16);
- params.setIV(iv.buf(), iv.size());
- Buffer decryptTest = algo::Aes::decrypt(contentKey.buf(), contentKey.size(),
- encData.buf(), encData.size(), params);
+ params.setIV(iv.data(), iv.size());
+ Buffer decryptTest =
+ algo::Aes::decrypt(contentKey.data(), contentKey.size(), encData.data(), encData.size(), params);
BOOST_CHECK_EQUAL_COLLECTIONS(decryptTest.begin(),
decryptTest.end(),
DATA_CONTEN,
@@ -295,31 +286,31 @@
size_t requestCount = 0;
face2.setInterestFilter(prefix,
- [&] (const InterestFilter&, const Interest& i) {
- BOOST_REQUIRE_EQUAL(i.getName(), expectedInterest);
- Name interestName = i.getName();
- switch(requestCount) {
- case 0:
- interestName.append(timeMarkerFirstHop);
- break;
+ [&] (const InterestFilter&, const Interest& i) {
+ BOOST_REQUIRE_EQUAL(i.getName(), expectedInterest);
+ Name interestName = i.getName();
+ switch (requestCount) {
+ case 0:
+ interestName.append(timeMarkerFirstHop);
+ break;
- case 1:
- interestName.append(timeMarkerSecondHop);
- break;
+ case 1:
+ interestName.append(timeMarkerSecondHop);
+ break;
- case 2:
- interestName.append(timeMarkerThirdHop);
- break;
+ case 2:
+ interestName.append(timeMarkerThirdHop);
+ break;
- default:
- break;
- }
- face2.put(*(encryptionKeys[interestName]));
- requestCount++;
- return;
- },
- RegisterPrefixSuccessCallback(),
- [] (const Name&, const std::string& e) { });
+ default:
+ break;
+ }
+ face2.put(*(encryptionKeys[interestName]));
+ requestCount++;
+ return;
+ },
+ RegisterPrefixSuccessCallback(),
+ [] (const Name&, const std::string& e) {});
do {
advanceClocks(time::milliseconds(10), 20);
@@ -328,19 +319,17 @@
// Verify that if a key is found, but not within the right timeslot, the search
// is refined until a valid timeslot is found.
Producer producer(prefix, suffix, face1, dbDir);
- producer.createContentKey(testTime,
- [&](const std::vector<Data>& result){
- BOOST_CHECK_EQUAL(requestCount, 3);
- BOOST_CHECK_EQUAL(result.size(), 1);
+ producer.createContentKey(testTime, [&] (const std::vector<Data>& result) {
+ BOOST_CHECK_EQUAL(requestCount, 3);
+ BOOST_CHECK_EQUAL(result.size(), 1);
- Data keyData = result[0];
- Name keyName = keyData.getName();
- BOOST_CHECK_EQUAL(keyName.getSubName(0,4), cKeyName);
- BOOST_CHECK_EQUAL(keyName.get(4), timeMarkerThirdHop[0]);
- BOOST_CHECK_EQUAL(keyName.get(5), NAME_COMPONENT_FOR);
- BOOST_CHECK_EQUAL(keyName.getSubName(6),
- expectedInterest.append(timeMarkerThirdHop));
- });
+ Data keyData = result[0];
+ Name keyName = keyData.getName();
+ BOOST_CHECK_EQUAL(keyName.getSubName(0, 4), cKeyName);
+ BOOST_CHECK_EQUAL(keyName.get(4), timeMarkerThirdHop[0]);
+ BOOST_CHECK_EQUAL(keyName.get(5), NAME_COMPONENT_FOR);
+ BOOST_CHECK_EQUAL(keyName.getSubName(6), expectedInterest.append(timeMarkerThirdHop));
+ });
do {
advanceClocks(time::milliseconds(10), 20);
} while (passPacket());
@@ -362,13 +351,13 @@
size_t timeoutCount = 0;
face2.setInterestFilter(prefix,
- [&] (const InterestFilter&, const Interest& i) {
- BOOST_CHECK_EQUAL(i.getName(), expectedInterest);
- timeoutCount++;
- return;
- },
- RegisterPrefixSuccessCallback(),
- [] (const Name&, const std::string& e) { });
+ [&] (const InterestFilter&, const Interest& i) {
+ BOOST_CHECK_EQUAL(i.getName(), expectedInterest);
+ timeoutCount++;
+ return;
+ },
+ RegisterPrefixSuccessCallback(),
+ [] (const Name&, const std::string& e) {});
do {
advanceClocks(time::milliseconds(10), 20);
@@ -377,11 +366,10 @@
// Verify that if no response is received, the producer appropriately times out.
// The result vector should not contain elements that have timed out.
Producer producer(prefix, suffix, face1, dbDir);
- producer.createContentKey(testTime,
- [&](const std::vector<Data>& result){
- BOOST_CHECK_EQUAL(timeoutCount, 4);
- BOOST_CHECK_EQUAL(result.size(), 0);
- });
+ producer.createContentKey(testTime, [&] (const std::vector<Data>& result) {
+ BOOST_CHECK_EQUAL(timeoutCount, 4);
+ BOOST_CHECK_EQUAL(result.size(), 0);
+ });
do {
advanceClocks(time::milliseconds(10), 500);
@@ -404,14 +392,14 @@
size_t timeoutCount = 0;
face2.setInterestFilter(prefix,
- [&] (const InterestFilter&, const Interest& i) {
- BOOST_CHECK_EQUAL(i.getName(), expectedInterest);
- BOOST_CHECK(i.getLink().getDelegations().size() == 3);
- timeoutCount++;
- return;
- },
- RegisterPrefixSuccessCallback(),
- [] (const Name&, const std::string& e) { });
+ [&] (const InterestFilter&, const Interest& i) {
+ BOOST_CHECK_EQUAL(i.getName(), expectedInterest);
+ BOOST_CHECK(i.getForwardingHint().size() == 3);
+ timeoutCount++;
+ return;
+ },
+ RegisterPrefixSuccessCallback(),
+ [] (const Name&, const std::string& e) {});
do {
advanceClocks(time::milliseconds(10), 20);
@@ -422,11 +410,10 @@
Link link("test", {{10, "/test1"}, {20, "/test2"}, {100, "/test3"}});
keyChain.sign(link);
Producer producer(prefix, suffix, face1, dbDir, 3, link);
- producer.createContentKey(testTime,
- [&](const std::vector<Data>& result){
- BOOST_CHECK_EQUAL(timeoutCount, 4);
- BOOST_CHECK_EQUAL(result.size(), 0);
- });
+ producer.createContentKey(testTime, [&] (const std::vector<Data>& result) {
+ BOOST_CHECK_EQUAL(timeoutCount, 4);
+ BOOST_CHECK_EQUAL(result.size(), 0);
+ });
do {
advanceClocks(time::milliseconds(10), 800);
diff --git a/tests/unit-tests/repetitive-interval.t.cpp b/tests/unit-tests/repetitive-interval.t.cpp
index 51abdf8..d5baa21 100644
--- a/tests/unit-tests/repetitive-interval.t.cpp
+++ b/tests/unit-tests/repetitive-interval.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#include "repetitive-interval.hpp"
@@ -34,7 +34,8 @@
{
RepetitiveInterval repetitiveInterval1(from_iso_string("20150825T000000"),
from_iso_string("20150825T000000"),
- 5, 10);
+ 5,
+ 10);
BOOST_CHECK_EQUAL(to_iso_string(repetitiveInterval1.getStartDate()), "20150825T000000");
BOOST_CHECK_EQUAL(to_iso_string(repetitiveInterval1.getEndDate()), "20150825T000000");
@@ -43,21 +44,30 @@
RepetitiveInterval repetitiveInterval2(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 5, 10, 1, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 1,
+ RepetitiveInterval::RepeatUnit::DAY);
BOOST_CHECK_EQUAL(repetitiveInterval2.getNRepeats(), 1);
BOOST_CHECK(repetitiveInterval2.getRepeatUnit() == RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval repetitiveInterval3(from_iso_string("20150825T000000"),
from_iso_string("20151227T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::MONTH);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::MONTH);
BOOST_CHECK_EQUAL(repetitiveInterval3.getNRepeats(), 2);
BOOST_CHECK(repetitiveInterval3.getRepeatUnit() == RepetitiveInterval::RepeatUnit::MONTH);
RepetitiveInterval repetitiveInterval4(from_iso_string("20150825T000000"),
from_iso_string("20301227T000000"),
- 5, 10, 5, RepetitiveInterval::RepeatUnit::YEAR);
+ 5,
+ 10,
+ 5,
+ RepetitiveInterval::RepeatUnit::YEAR);
BOOST_CHECK_EQUAL(repetitiveInterval4.getNRepeats(), 5);
BOOST_CHECK(repetitiveInterval4.getRepeatUnit() == RepetitiveInterval::RepeatUnit::YEAR);
@@ -74,20 +84,23 @@
RepetitiveInterval repetitiveInterval1(from_iso_string("20150825T000000"),
from_iso_string("20150925T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY);
Interval resultInterval;
bool isPositive = false;
TimeStamp tp1 = from_iso_string("20150825T050000");
- std::tie(isPositive,resultInterval) = repetitiveInterval1.getInterval(tp1);
+ std::tie(isPositive, resultInterval) = repetitiveInterval1.getInterval(tp1);
BOOST_CHECK_EQUAL(isPositive, true);
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T050000");
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
TimeStamp tp2 = from_iso_string("20150902T060000");
- std::tie(isPositive,resultInterval) = repetitiveInterval1.getInterval(tp2);
+ std::tie(isPositive, resultInterval) = repetitiveInterval1.getInterval(tp2);
BOOST_CHECK_EQUAL(isPositive, true);
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150902T050000");
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150902T100000");
@@ -100,21 +113,24 @@
RepetitiveInterval repetitiveInterval2(from_iso_string("20150825T000000"),
from_iso_string("20160825T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::MONTH);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::MONTH);
TimeStamp tp4 = from_iso_string("20150825T050000");
- std::tie(isPositive,resultInterval) = repetitiveInterval2.getInterval(tp4);
+ std::tie(isPositive, resultInterval) = repetitiveInterval2.getInterval(tp4);
BOOST_CHECK_EQUAL(isPositive, true);
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T050000");
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
TimeStamp tp5 = from_iso_string("20151025T060000");
- std::tie(isPositive,resultInterval) = repetitiveInterval2.getInterval(tp5);
+ std::tie(isPositive, resultInterval) = repetitiveInterval2.getInterval(tp5);
BOOST_CHECK_EQUAL(isPositive, true);
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20151025T050000");
- BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20151025T100000");
+ BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20151025T100000");
TimeStamp tp6 = from_iso_string("20151226T050000");
@@ -128,18 +144,21 @@
RepetitiveInterval repetitiveInterval3(from_iso_string("20150825T000000"),
from_iso_string("20300825T000000"),
- 5, 10, 3, RepetitiveInterval::RepeatUnit::YEAR);
+ 5,
+ 10,
+ 3,
+ RepetitiveInterval::RepeatUnit::YEAR);
TimeStamp tp8 = from_iso_string("20150825T050000");
- std::tie(isPositive,resultInterval) = repetitiveInterval3.getInterval(tp8);
+ std::tie(isPositive, resultInterval) = repetitiveInterval3.getInterval(tp8);
BOOST_CHECK_EQUAL(isPositive, true);
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20150825T050000");
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20150825T100000");
TimeStamp tp9 = from_iso_string("20180825T060000");
- std::tie(isPositive,resultInterval) = repetitiveInterval3.getInterval(tp9);
+ std::tie(isPositive, resultInterval) = repetitiveInterval3.getInterval(tp9);
BOOST_CHECK_EQUAL(isPositive, true);
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getStartTime()), "20180825T050000");
BOOST_CHECK_EQUAL(to_iso_string(resultInterval.getEndTime()), "20180825T100000");
@@ -154,27 +173,21 @@
BOOST_CHECK(std::get<0>(repetitiveInterval3.getInterval(tp12)) == false);
}
-const uint8_t REPETITIVE_INTERVAL[] = {
- 0x8c, 0x2e, // RepetitiveInterval
- 0x86, 0x0f,
- 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
- 0x87, 0x0f,
- 0x32, 0x30, 0x31, 0x35, 0x30, 0x39, 0x32, 0x31, 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
- 0x88, 0x01,
- 0x05,
- 0x89, 0x01,
- 0x0a,
- 0x8a, 0x01,
- 0x04,
- 0x8b, 0x01,
- 0x01
-};
+const uint8_t REPETITIVE_INTERVAL[] = {0x8c, 0x2e, // RepetitiveInterval
+ 0x86, 0x0f, 0x32, 0x30, 0x31, 0x35, 0x30, 0x38, 0x32, 0x35,
+ 0x54, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x87, 0x0f, 0x32,
+ 0x30, 0x31, 0x35, 0x30, 0x39, 0x32, 0x31, 0x54, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x88, 0x01, 0x05, 0x89, 0x01, 0x0a,
+ 0x8a, 0x01, 0x04, 0x8b, 0x01, 0x01};
BOOST_AUTO_TEST_CASE(EncodeAndDecode)
{
RepetitiveInterval repetitiveInterval1(from_iso_string("20150825T000000"),
from_iso_string("20150921T000000"),
- 5, 10, 4, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 4,
+ RepetitiveInterval::RepeatUnit::DAY);
Block block1 = repetitiveInterval1.wireEncode();
Block block2(REPETITIVE_INTERVAL, sizeof(REPETITIVE_INTERVAL));
@@ -203,45 +216,75 @@
static bool
check(const RepetitiveInterval& small, const RepetitiveInterval& big)
{
- return (small < big && !(big < small));
+ return (small < big && !(big < small));
}
BOOST_AUTO_TEST_CASE(Comparison)
{
BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY),
RepetitiveInterval(from_iso_string("20150826T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY)));
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY)));
BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY),
RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 6, 10, 2, RepetitiveInterval::RepeatUnit::DAY)));
+ 6,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY)));
BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY),
RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 11, 2, RepetitiveInterval::RepeatUnit::DAY)));
+ 5,
+ 11,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY)));
BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY),
RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 3, RepetitiveInterval::RepeatUnit::DAY)));
+ 5,
+ 10,
+ 3,
+ RepetitiveInterval::RepeatUnit::DAY)));
BOOST_CHECK(check(RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY),
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY),
RepetitiveInterval(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::MONTH)));
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::MONTH)));
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit-tests/schedule.t.cpp b/tests/unit-tests/schedule.t.cpp
index 1d86787..64c0024 100644
--- a/tests/unit-tests/schedule.t.cpp
+++ b/tests/unit-tests/schedule.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2014-2015, 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,7 +16,7 @@
* 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>
*/
#include "schedule.hpp"
@@ -35,16 +35,24 @@
Schedule schedule;
RepetitiveInterval interval1(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval2(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 6, 8, 1, RepetitiveInterval::RepeatUnit::DAY);
+ 6,
+ 8,
+ 1,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval3(from_iso_string("20150827T000000"),
from_iso_string("20150827T000000"),
- 7, 8);
+ 7,
+ 8);
RepetitiveInterval interval4(from_iso_string("20150825T000000"),
from_iso_string("20150825T000000"),
- 4, 7);
+ 4,
+ 7);
schedule.addWhiteInterval(interval1);
schedule.addWhiteInterval(interval2);
@@ -104,13 +112,20 @@
Schedule schedule;
RepetitiveInterval interval1(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval2(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 6, 8, 1, RepetitiveInterval::RepeatUnit::DAY);
+ 6,
+ 8,
+ 1,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval3(from_iso_string("20150825T000000"),
from_iso_string("20150825T000000"),
- 4, 7);
+ 4,
+ 7);
schedule.addWhiteInterval(interval1);
schedule.addWhiteInterval(interval2);
@@ -162,10 +177,16 @@
Schedule schedule;
RepetitiveInterval interval1(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval2(from_iso_string("20150825T000000"),
from_iso_string("20150827T000000"),
- 6, 8, 1, RepetitiveInterval::RepeatUnit::DAY);
+ 6,
+ 8,
+ 1,
+ RepetitiveInterval::RepeatUnit::DAY);
schedule.addBlackInterval(interval1);
schedule.addBlackInterval(interval2);
@@ -259,16 +280,24 @@
RepetitiveInterval interval1(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 5, 10, 2, RepetitiveInterval::RepeatUnit::DAY);
+ 5,
+ 10,
+ 2,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval2(from_iso_string("20150825T000000"),
from_iso_string("20150828T000000"),
- 6, 8, 1, RepetitiveInterval::RepeatUnit::DAY);
+ 6,
+ 8,
+ 1,
+ RepetitiveInterval::RepeatUnit::DAY);
RepetitiveInterval interval3(from_iso_string("20150827T000000"),
from_iso_string("20150827T000000"),
- 7, 8);
+ 7,
+ 8);
RepetitiveInterval interval4(from_iso_string("20150825T000000"),
from_iso_string("20150825T000000"),
- 4, 7);
+ 4,
+ 7);
schedule.addWhiteInterval(interval1);
schedule.addWhiteInterval(interval2);
diff --git a/wscript b/wscript
index b11e7bd..8d1d61f 100644
--- a/wscript
+++ b/wscript
@@ -63,7 +63,7 @@
# vnum = "0.0.1",
features=['cxx', 'cxxshlib'],
source = bld.path.ant_glob(['src/**/*.cpp']),
- use = 'BOOST NDN_CXX',
+ use = 'BOOST NDN_CXX CRYPTOPP',
includes = ['src', '.'],
export_includes=['src', '.'],
)
@@ -78,7 +78,7 @@
cwd = bld.path.find_dir("src"),
relative_trick = True,
)
-
+
bld.install_files(
dest = "%s/ndn-group-encrypt" % bld.env['INCLUDEDIR'],