Reduce namespace nesting (ndn::ndncert -> ndncert)
Change-Id: I5b69a2c3673cccdf07ea0ba3a0e7181894328f47
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index cd28b94..c2072dd 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -35,7 +35,6 @@
#include <ndn-cxx/util/random.hpp>
#include <ndn-cxx/util/string-helper.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -44,7 +43,7 @@
NDN_LOG_INIT(ndncert.ca);
-CaModule::CaModule(Face& face, security::KeyChain& keyChain,
+CaModule::CaModule(ndn::Face& face, ndn::KeyChain& keyChain,
const std::string& configPath, const std::string& storageType)
: m_face(face)
, m_keyChain(keyChain)
@@ -52,7 +51,7 @@
// load the config and create storage
m_config.load(configPath);
m_storage = CaStorage::createCaStorage(storageType, m_config.caProfile.caPrefix, "");
- random::generateSecureBytes(m_requestIdGenKey, 32);
+ ndn::random::generateSecureBytes(m_requestIdGenKey, 32);
if (m_config.nameAssignmentFuncs.size() == 0) {
m_config.nameAssignmentFuncs.push_back(NameAssignmentFunc::createNameAssignmentFunc("random"));
}
@@ -80,7 +79,7 @@
prefix,
[&] (const Name& name) {
// register INFO RDR metadata prefix
- name::Component metaDataComp(32, reinterpret_cast<const uint8_t*>("metadata"), std::strlen("metadata"));
+ ndn::name::Component metaDataComp(32, reinterpret_cast<const uint8_t*>("metadata"), std::strlen("metadata"));
auto filterId = m_face.setInterestFilter(Name(name).append("INFO").append(metaDataComp),
[this] (auto&&, const auto& i) { onCaProfileDiscovery(i); });
m_interestFilterHandles.push_back(filterId);
@@ -126,36 +125,29 @@
const auto& cert = identity.getDefaultKey().getDefaultCertificate();
Block contentTLV = infotlv::encodeDataContent(m_config.caProfile, cert);
- // set naming convention to be typed
- auto convention = name::getConventionEncoding();
- name::setConventionEncoding(name::Convention::TYPED);
-
Name infoPacketName(m_config.caProfile.caPrefix);
- auto segmentComp = name::Component::fromSegment(0);
+ auto segmentComp = ndn::name::Component::fromSegment(0);
infoPacketName.append("CA").append("INFO").appendVersion().append(segmentComp);
m_profileData = std::make_unique<Data>(infoPacketName);
m_profileData->setFinalBlock(segmentComp);
m_profileData->setContent(contentTLV);
m_profileData->setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD);
m_keyChain.sign(*m_profileData, signingByIdentity(m_config.caProfile.caPrefix));
-
- // set back the convention
- name::setConventionEncoding(convention);
}
return *m_profileData;
}
void
-CaModule::onCaProfileDiscovery(const Interest& request)
+CaModule::onCaProfileDiscovery(const Interest&)
{
NDN_LOG_TRACE("Received CA Profile MetaData discovery Interest");
if (m_profileData == nullptr) {
m_profileData = std::make_unique<Data>(getCaProfileData());
}
- MetadataObject metadata;
+ ndn::MetadataObject metadata;
metadata.setVersionedName(m_profileData->getName().getPrefix(-1));
Name discoveryInterestName(m_profileData->getName().getPrefix(-2));
- name::Component metadataComponent(32, reinterpret_cast<const uint8_t*>("metadata"), std::strlen("metadata"));
+ ndn::name::Component metadataComponent(32, reinterpret_cast<const uint8_t*>("metadata"), std::strlen("metadata"));
discoveryInterestName.append(metadataComponent);
m_face.put(metadata.makeData(discoveryInterestName, m_keyChain, signingByIdentity(m_config.caProfile.caPrefix)));
}
@@ -168,7 +160,7 @@
// process PROBE requests: collect probe parameters
auto parameters = probetlv::decodeApplicationParameters(request.getApplicationParameters());
- std::vector <PartialName> availableComponents;
+ std::vector<ndn::PartialName> availableComponents;
for (auto& item : m_config.nameAssignmentFuncs) {
auto names = item->assignName(parameters);
availableComponents.insert(availableComponents.end(), names.begin(), names.end());
@@ -216,7 +208,7 @@
// get ECDH pub key and cert request
const auto& parameterTLV = request.getApplicationParameters();
std::vector <uint8_t> ecdhPub;
- shared_ptr <security::Certificate> clientCert;
+ std::shared_ptr<Certificate> clientCert;
try {
requesttlv::decodeApplicationParameters(parameterTLV, requestType, ecdhPub, clientCert);
}
@@ -256,7 +248,7 @@
// verify identity name
if (!m_config.caProfile.caPrefix.isPrefixOf(clientCert->getIdentity())
- || !security::Certificate::isValidName(clientCert->getName())
+ || !Certificate::isValidName(clientCert->getName())
|| clientCert->getIdentity().size() <= m_config.caProfile.caPrefix.size()) {
NDN_LOG_ERROR("An invalid certificate name is being requested " << clientCert->getName());
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::NAME_NOT_ALLOWED,
@@ -286,13 +278,13 @@
}
// verify signature
- if (!security::verifySignature(*clientCert, *clientCert)) {
+ if (!ndn::security::verifySignature(*clientCert, *clientCert)) {
NDN_LOG_ERROR("Invalid signature in the self-signed certificate.");
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::BAD_SIGNATURE,
"Invalid signature in the self-signed certificate."));
return;
}
- if (!security::verifySignature(request, *clientCert)) {
+ if (!ndn::security::verifySignature(request, *clientCert)) {
NDN_LOG_ERROR("Invalid signature in the Interest packet.");
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::BAD_SIGNATURE,
"Invalid signature in the Interest packet."));
@@ -301,7 +293,7 @@
}
else if (requestType == RequestType::REVOKE) {
//verify cert is from this CA
- if (!security::verifySignature(*clientCert, caCert)) {
+ if (!ndn::security::verifySignature(*clientCert, caCert)) {
NDN_LOG_ERROR("Invalid signature in the certificate to revoke.");
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::BAD_SIGNATURE,
"Invalid signature in the certificate to revoke."));
@@ -331,7 +323,7 @@
requestState.cert = *clientCert;
// generate salt for HKDF
std::array<uint8_t, 32> salt;
- random::generateSecureBytes(salt.data(), salt.size());
+ ndn::random::generateSecureBytes(salt.data(), salt.size());
// hkdf
std::array<uint8_t, 16> aesKey;
hkdf(sharedSecret.data(), sharedSecret.size(), salt.data(), salt.size(),
@@ -340,7 +332,7 @@
try {
m_storage->addRequest(requestState);
}
- catch (const std::runtime_error& e) {
+ catch (const std::runtime_error&) {
NDN_LOG_ERROR("Duplicate Request ID: The same request has been seen before.");
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::INVALID_PARAMETER,
"Duplicate Request ID: The same request has been seen before."));
@@ -371,14 +363,14 @@
return;
}
// verify signature
- if (!security::verifySignature(request, requestState->cert)) {
+ if (!ndn::security::verifySignature(request, requestState->cert)) {
NDN_LOG_ERROR("Invalid Signature in the Interest packet.");
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::BAD_SIGNATURE,
"Invalid Signature in the Interest packet."));
return;
}
// decrypt the parameters
- Buffer paramTLVPayload;
+ ndn::Buffer paramTLVPayload;
try {
paramTLVPayload = decodeBlockWithAesGcm128(request.getApplicationParameters(), requestState->encryptionKey.data(),
requestState->requestId.data(), requestState->requestId.size(),
@@ -398,7 +390,7 @@
"No parameters are found after decryption."));
return;
}
- Block paramTLV = makeBinaryBlock(tlv::EncryptedPayload, paramTLVPayload.data(), paramTLVPayload.size());
+ auto paramTLV = ndn::makeBinaryBlock(tlv::EncryptedPayload, paramTLVPayload.data(), paramTLVPayload.size());
paramTLV.parse();
// load the corresponding challenge module
@@ -457,22 +449,22 @@
}
}
-security::Certificate
+Certificate
CaModule::issueCertificate(const RequestState& requestState)
{
auto expectedPeriod = requestState.cert.getValidityPeriod().getPeriod();
- security::ValidityPeriod period(expectedPeriod.first, expectedPeriod.second);
- security::Certificate newCert;
+ ndn::security::ValidityPeriod period(expectedPeriod.first, expectedPeriod.second);
+ Certificate newCert;
Name certName = requestState.cert.getKeyName();
- certName.append("NDNCERT").append(std::to_string(random::generateSecureWord64()));
+ certName.append("NDNCERT").append(ndn::to_string(ndn::random::generateSecureWord64()));
newCert.setName(certName);
newCert.setContent(requestState.cert.getContent());
NDN_LOG_TRACE("cert request content " << requestState.cert);
SignatureInfo signatureInfo;
signatureInfo.setValidityPeriod(period);
- security::SigningInfo signingInfo(security::SigningInfo::SIGNER_TYPE_ID,
- m_config.caProfile.caPrefix, signatureInfo);
+ ndn::security::SigningInfo signingInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
+ m_config.caProfile.caPrefix, signatureInfo);
m_keyChain.sign(newCert, signingInfo);
NDN_LOG_TRACE("new cert got signed" << newCert);
@@ -492,7 +484,7 @@
return nullptr;
}
try {
- NDN_LOG_TRACE("Request Id to query the database " << toHex(requestId.data(), requestId.size()));
+ NDN_LOG_TRACE("Request Id to query the database " << ndn::toHex(requestId.data(), requestId.size()));
return std::make_unique<RequestState>(m_storage->getRequest(requestId));
}
catch (const std::exception& e) {
@@ -520,4 +512,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/ca-module.hpp b/src/ca-module.hpp
index e98638b..88af9f1 100644
--- a/src/ca-module.hpp
+++ b/src/ca-module.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,7 +25,9 @@
#include "detail/crypto-helpers.hpp"
#include "detail/ca-storage.hpp"
-namespace ndn {
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
+
namespace ndncert {
namespace ca {
@@ -37,12 +39,12 @@
*
* @param RequestState The state of the certificate request whose status is updated.
*/
-using StatusUpdateCallback = function<void(const RequestState&)>;
+using StatusUpdateCallback = std::function<void(const RequestState&)>;
-class CaModule : noncopyable
+class CaModule : boost::noncopyable
{
public:
- CaModule(Face& face, security::KeyChain& keyChain, const std::string& configPath,
+ CaModule(ndn::Face& face, ndn::KeyChain& keyChain, const std::string& configPath,
const std::string& storageType = "ca-storage-sqlite3");
~CaModule();
@@ -53,7 +55,7 @@
return m_config;
}
- const unique_ptr<CaStorage>&
+ const std::unique_ptr<CaStorage>&
getCaStorage()
{
return m_storage;
@@ -84,7 +86,7 @@
std::unique_ptr<RequestState>
getCertificateRequest(const Interest& request);
- security::Certificate
+ Certificate
issueCertificate(const RequestState& requestState);
void
@@ -94,10 +96,10 @@
generateErrorDataPacket(const Name& name, ErrorCode error, const std::string& errorInfo);
NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- Face& m_face;
+ ndn::Face& m_face;
CaConfig m_config;
- unique_ptr<CaStorage> m_storage;
- security::KeyChain& m_keyChain;
+ std::unique_ptr<CaStorage> m_storage;
+ ndn::KeyChain& m_keyChain;
uint8_t m_requestIdGenKey[32];
std::unique_ptr<Data> m_profileData;
/**
@@ -105,12 +107,11 @@
*/
StatusUpdateCallback m_statusUpdateCallback;
- std::list<RegisteredPrefixHandle> m_registeredPrefixHandles;
- std::list<InterestFilterHandle> m_interestFilterHandles;
+ std::list<ndn::RegisteredPrefixHandle> m_registeredPrefixHandles;
+ std::list<ndn::InterestFilterHandle> m_interestFilterHandles;
};
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_CA_MODULE_HPP
diff --git a/src/challenge/challenge-email.cpp b/src/challenge/challenge-email.cpp
index 41d53d6..bc624bc 100644
--- a/src/challenge/challenge-email.cpp
+++ b/src/challenge/challenge-email.cpp
@@ -22,7 +22,6 @@
#include <regex>
#include <boost/process.hpp>
-namespace ndn {
namespace ndncert {
NDN_LOG_INIT(ndncert.challenge.email);
@@ -37,8 +36,8 @@
ChallengeEmail::ChallengeEmail(const std::string& scriptPath,
const size_t& maxAttemptTimes,
const time::seconds secretLifetime)
- : ChallengeModule("email", maxAttemptTimes, secretLifetime)
- , m_sendEmailScript(scriptPath)
+ : ChallengeModule("email", maxAttemptTimes, secretLifetime)
+ , m_sendEmailScript(scriptPath)
{
}
@@ -52,7 +51,8 @@
// for the first time, init the challenge
std::string emailAddress = readString(params.get(tlv::ParameterValue));
if (!isValidEmailAddress(emailAddress)) {
- return returnWithNewChallengeStatus(request, INVALID_EMAIL, JsonSection(), m_maxAttemptTimes - 1, m_secretLifetime);
+ return returnWithNewChallengeStatus(request, INVALID_EMAIL, JsonSection(), m_maxAttemptTimes - 1,
+ m_secretLifetime);
}
auto lastComponentRequested = readString(request.cert.getIdentity().get(-1));
if (lastComponentRequested != emailAddress) {
@@ -64,8 +64,10 @@
secretJson.add(PARAMETER_KEY_CODE, emailCode);
// send out the email
sendEmail(emailAddress, emailCode, request);
- NDN_LOG_TRACE("Secret for request " << toHex(request.requestId.data(), request.requestId.size()) << " : " << emailCode);
- return returnWithNewChallengeStatus(request, NEED_CODE, std::move(secretJson), m_maxAttemptTimes, m_secretLifetime);
+ NDN_LOG_TRACE("Secret for request " << ndn::toHex(request.requestId.data(), request.requestId.size())
+ << " : " << emailCode);
+ return returnWithNewChallengeStatus(request, NEED_CODE, std::move(secretJson),
+ m_maxAttemptTimes, m_secretLifetime);
}
if (request.challengeState) {
if (request.challengeState->challengeStatus == NEED_CODE ||
@@ -134,17 +136,17 @@
if (params.size() != 1 || params.find(PARAMETER_KEY_EMAIL) == params.end()) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
- request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
- request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_EMAIL));
- request.push_back(makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_EMAIL)->second));
+ request.push_back(ndn::makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_EMAIL));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_EMAIL)->second));
}
else if (status == Status::CHALLENGE && (challengeStatus == NEED_CODE || challengeStatus == WRONG_CODE)) {
if (params.size() != 1 || params.find(PARAMETER_KEY_CODE) == params.end()) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
- request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
- request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
- request.push_back(makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_CODE)->second));
+ request.push_back(ndn::makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_CODE)->second));
}
else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
@@ -179,4 +181,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/challenge/challenge-email.hpp b/src/challenge/challenge-email.hpp
index e2c7267..c5d76de 100644
--- a/src/challenge/challenge-email.hpp
+++ b/src/challenge/challenge-email.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "challenge-module.hpp"
-namespace ndn {
namespace ndncert {
/**
@@ -88,6 +87,5 @@
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_CHALLENGE_EMAIL_HPP
diff --git a/src/challenge/challenge-module.cpp b/src/challenge/challenge-module.cpp
index f184ca9..bf3b966 100644
--- a/src/challenge/challenge-module.cpp
+++ b/src/challenge/challenge-module.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -21,7 +21,6 @@
#include "challenge/challenge-module.hpp"
#include <ndn-cxx/util/random.hpp>
-namespace ndn {
namespace ndncert {
ChallengeModule::ChallengeModule(const std::string& challengeType,
@@ -41,7 +40,7 @@
return i == factory.end() ? false : true;
}
-unique_ptr<ChallengeModule>
+std::unique_ptr<ChallengeModule>
ChallengeModule::createChallengeModule(const std::string& challengeType)
{
ChallengeFactory& factory = getFactory();
@@ -61,11 +60,11 @@
{
uint32_t securityCode = 0;
do {
- securityCode = random::generateSecureWord32();
+ securityCode = ndn::random::generateSecureWord32();
}
while (securityCode >= 4294000000);
securityCode /= 4294;
- std::string result = std::to_string(securityCode);
+ std::string result = ndn::to_string(securityCode);
while (result.length() < 6) {
result = "0" + result;
}
@@ -103,4 +102,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/challenge/challenge-module.hpp b/src/challenge/challenge-module.hpp
index 9d7d859..1e33bfc 100644
--- a/src/challenge/challenge-module.hpp
+++ b/src/challenge/challenge-module.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,16 +23,16 @@
#include "detail/ca-request-state.hpp"
-namespace ndn {
namespace ndncert {
-class ChallengeModule : noncopyable
+class ChallengeModule : boost::noncopyable
{
public:
explicit
ChallengeModule(const std::string& challengeType, size_t maxAttemptTimes, time::seconds secretLifetime);
- virtual ~ChallengeModule() = default;
+ virtual
+ ~ChallengeModule() = default;
template <class ChallengeType>
static void
@@ -46,7 +46,7 @@
static bool
isChallengeSupported(const std::string& challengeType);
- static unique_ptr<ChallengeModule>
+ static std::unique_ptr<ChallengeModule>
createChallengeModule(const std::string& challengeType);
// For CA
@@ -83,7 +83,7 @@
const time::seconds m_secretLifetime;
private:
- typedef function<unique_ptr<ChallengeModule>()> ChallengeCreateFunc;
+ typedef std::function<std::unique_ptr<ChallengeModule>()> ChallengeCreateFunc;
typedef std::map<std::string, ChallengeCreateFunc> ChallengeFactory;
static ChallengeFactory&
@@ -91,15 +91,15 @@
};
#define NDNCERT_REGISTER_CHALLENGE(C, T) \
- static class NdnCert##C##ChallengeRegistrationClass { \
+ static class NdnCert##C##ChallengeRegistrationClass \
+ { \
public: \
NdnCert##C##ChallengeRegistrationClass() \
{ \
- ::ndn::ndncert::ChallengeModule::registerChallengeModule<C>(T); \
+ ::ndncert::ChallengeModule::registerChallengeModule<C>(T); \
} \
} g_NdnCert##C##ChallengeRegistrationVariable
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_CHALLENGE_MODULE_HPP
diff --git a/src/challenge/challenge-pin.cpp b/src/challenge/challenge-pin.cpp
index 5d3ea8a..6e42969 100644
--- a/src/challenge/challenge-pin.cpp
+++ b/src/challenge/challenge-pin.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,9 +19,9 @@
*/
#include "challenge-pin.hpp"
+
#include <ndn-cxx/util/random.hpp>
-namespace ndn {
namespace ndncert {
NDN_LOG_INIT(ndncert.challenge.pin);
@@ -32,7 +32,7 @@
const std::string ChallengePin::PARAMETER_KEY_CODE = "code";
ChallengePin::ChallengePin(const size_t& maxAttemptTimes, const time::seconds& secretLifetime)
- : ChallengeModule("pin", maxAttemptTimes, secretLifetime)
+ : ChallengeModule("pin", maxAttemptTimes, secretLifetime)
{
}
@@ -48,8 +48,10 @@
std::string secretCode = generateSecretCode();
JsonSection secretJson;
secretJson.add(PARAMETER_KEY_CODE, secretCode);
- NDN_LOG_TRACE("Secret for request " << toHex(request.requestId.data(), request.requestId.size()) << " : " << secretCode);
- return returnWithNewChallengeStatus(request, NEED_CODE, std::move(secretJson), m_maxAttemptTimes, m_secretLifetime);
+ NDN_LOG_TRACE("Secret for request " << ndn::toHex(request.requestId.data(), request.requestId.size())
+ << " : " << secretCode);
+ return returnWithNewChallengeStatus(request, NEED_CODE, std::move(secretJson), m_maxAttemptTimes,
+ m_secretLifetime);
}
if (request.challengeState) {
if (request.challengeState->challengeStatus == NEED_CODE ||
@@ -109,15 +111,15 @@
{
Block request(tlv::EncryptedPayload);
if (status == Status::BEFORE_CHALLENGE) {
- request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+ request.push_back(ndn::makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
}
else if (status == Status::CHALLENGE && (challengeStatus == NEED_CODE || challengeStatus == WRONG_CODE)) {
if (params.size() != 1 || params.find(PARAMETER_KEY_CODE) == params.end()) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
- request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
- request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
- request.push_back(makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_CODE)->second));
+ request.push_back(ndn::makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CODE));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterValue, params.find(PARAMETER_KEY_CODE)->second));
}
else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
@@ -125,5 +127,5 @@
request.encode();
return request;
}
+
} // namespace ndncert
-} // namespace ndn
diff --git a/src/challenge/challenge-pin.hpp b/src/challenge/challenge-pin.hpp
index 61e0fb6..cfcf508 100644
--- a/src/challenge/challenge-pin.hpp
+++ b/src/challenge/challenge-pin.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "challenge-module.hpp"
-namespace ndn {
namespace ndncert {
/**
@@ -70,6 +69,5 @@
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_CHALLENGE_PIN_HPP
diff --git a/src/challenge/challenge-possession.cpp b/src/challenge/challenge-possession.cpp
index ef93d25..a7f0f77 100644
--- a/src/challenge/challenge-possession.cpp
+++ b/src/challenge/challenge-possession.cpp
@@ -27,7 +27,6 @@
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
NDN_LOG_INIT(ndncert.challenge.possession);
@@ -58,7 +57,7 @@
}
catch (const boost::property_tree::file_parser_error& error) {
NDN_THROW(std::runtime_error("Failed to parse configuration file " + m_configFile + ": " +
- error.message() + " on line " + std::to_string(error.line())));
+ error.message() + " on line " + ndn::to_string(error.line())));
}
if (config.begin() == config.end()) {
@@ -70,7 +69,7 @@
auto it = anchorList.begin();
for (; it != anchorList.end(); it++) {
std::istringstream ss(it->second.get("certificate", ""));
- auto cert = io::load<security::Certificate>(ss);
+ auto cert = ndn::io::load<Certificate>(ss);
if (cert == nullptr) {
NDN_LOG_ERROR("Cannot load the certificate from config file");
continue;
@@ -87,7 +86,7 @@
if (m_trustAnchors.empty()) {
parseConfigFile();
}
- security::Certificate credential;
+ Certificate credential;
const uint8_t* signature = nullptr;
size_t signatureLen = 0;
const auto& elements = params.elements();
@@ -113,16 +112,18 @@
// verify the credential and the self-signed cert
if (request.status == Status::BEFORE_CHALLENGE) {
NDN_LOG_TRACE("Challenge Interest arrives. Check certificate and init the challenge");
+ using ndn::toHex;
+
// check the certificate
bool checkOK = false;
if (credential.hasContent() && signatureLen == 0) {
Name signingKeyName = credential.getSignatureInfo().getKeyLocator().getName();
- security::transform::PublicKey key;
+ ndn::security::transform::PublicKey key;
const auto& pubKeyBuffer = credential.getPublicKey();
key.loadPkcs8(pubKeyBuffer.data(), pubKeyBuffer.size());
for (auto anchor : m_trustAnchors) {
if (anchor.getKeyName() == signingKeyName) {
- if (security::verifySignature(credential, anchor)) {
+ if (ndn::security::verifySignature(credential, anchor)) {
checkOK = true;
}
}
@@ -137,7 +138,7 @@
// for the first time, init the challenge
std::array<uint8_t, 16> secretCode{};
- random::generateSecureBytes(secretCode.data(), 16);
+ ndn::random::generateSecureBytes(secretCode.data(), 16);
JsonSection secretJson;
secretJson.add(PARAMETER_KEY_NONCE, toHex(secretCode.data(), 16));
auto credential_block = credential.wireEncode();
@@ -152,14 +153,14 @@
if (credential.hasContent() || signatureLen == 0) {
return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
}
- credential = security::Certificate(Block(fromHex(request.challengeState->secrets.get(PARAMETER_KEY_CREDENTIAL_CERT, ""))));
- auto secretCode = *fromHex(request.challengeState->secrets.get(PARAMETER_KEY_NONCE, ""));
+ credential = Certificate(Block(ndn::fromHex(request.challengeState->secrets.get(PARAMETER_KEY_CREDENTIAL_CERT, ""))));
+ auto secretCode = *ndn::fromHex(request.challengeState->secrets.get(PARAMETER_KEY_NONCE, ""));
//check the proof
- security::transform::PublicKey key;
+ ndn::security::transform::PublicKey key;
const auto& pubKeyBuffer = credential.getPublicKey();
key.loadPkcs8(pubKeyBuffer.data(), pubKeyBuffer.size());
- if (security::verifySignature({{secretCode.data(), secretCode.size()}}, signature, signatureLen, key)) {
+ if (ndn::security::verifySignature({{secretCode.data(), secretCode.size()}}, signature, signatureLen, key)) {
return returnWithSuccess(request);
}
return returnWithError(request, ErrorCode::INVALID_PARAMETER,
@@ -196,10 +197,10 @@
if (params.size() != 1) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
- request.push_back(makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
+ request.push_back(ndn::makeStringBlock(tlv::SelectedChallenge, CHALLENGE_TYPE));
for (const auto& item : params) {
if (std::get<0>(item) == PARAMETER_KEY_CREDENTIAL_CERT) {
- request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CREDENTIAL_CERT));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CREDENTIAL_CERT));
Block valueBlock(tlv::ParameterValue);
auto& certTlvStr = std::get<1>(item);
valueBlock.push_back(Block(reinterpret_cast<const uint8_t*>(certTlvStr.data()), certTlvStr.size()));
@@ -210,17 +211,17 @@
}
}
}
- else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF){
+ else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF) {
if (params.size() != 1) {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
for (const auto& item : params) {
if (std::get<0>(item) == PARAMETER_KEY_PROOF) {
- request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_PROOF));
+ request.push_back(ndn::makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_PROOF));
auto& sigTlvStr = std::get<1>(item);
- Block valueBlock = makeBinaryBlock(tlv::ParameterValue,
- reinterpret_cast<const uint8_t*>(sigTlvStr.data()),
- sigTlvStr.size());
+ auto valueBlock = ndn::makeBinaryBlock(tlv::ParameterValue,
+ reinterpret_cast<const uint8_t*>(sigTlvStr.data()),
+ sigTlvStr.size());
request.push_back(valueBlock);
}
else {
@@ -237,14 +238,14 @@
void
ChallengePossession::fulfillParameters(std::multimap<std::string, std::string>& params,
- KeyChain& keyChain, const Name& issuedCertName,
+ ndn::KeyChain& keyChain, const Name& issuedCertName,
const std::array<uint8_t, 16>& nonce)
{
- auto keyName = security::extractKeyNameFromCertName(issuedCertName);
- auto id = keyChain.getPib().getIdentity(security::extractIdentityFromCertName(issuedCertName));
+ auto keyName = ndn::security::extractKeyNameFromCertName(issuedCertName);
+ auto id = keyChain.getPib().getIdentity(ndn::security::extractIdentityFromCertName(issuedCertName));
auto issuedCert = id.getKey(keyName).getCertificate(issuedCertName);
auto issuedCertTlv = issuedCert.wireEncode();
- auto signature = keyChain.getTpm().sign({{nonce.data(), nonce.size()}}, keyName, DigestAlgorithm::SHA256);
+ auto signature = keyChain.getTpm().sign({{nonce.data(), nonce.size()}}, keyName, ndn::DigestAlgorithm::SHA256);
for (auto& item : params) {
if (item.first == PARAMETER_KEY_CREDENTIAL_CERT) {
@@ -257,4 +258,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/challenge/challenge-possession.hpp b/src/challenge/challenge-possession.hpp
index 165e20e..ab5e641 100644
--- a/src/challenge/challenge-possession.hpp
+++ b/src/challenge/challenge-possession.hpp
@@ -1,5 +1,5 @@
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -22,7 +22,8 @@
#include "challenge-module.hpp"
-namespace ndn {
+#include <ndn-cxx/security/key-chain.hpp>
+
namespace ndncert {
/**
@@ -66,7 +67,8 @@
static void
fulfillParameters(std::multimap<std::string, std::string>& params,
- KeyChain& keyChain, const Name& issuedCertName, const std::array<uint8_t, 16>& nonce);
+ ndn::KeyChain& keyChain, const Name& issuedCertName,
+ const std::array<uint8_t, 16>& nonce);
// challenge parameters
static const std::string PARAMETER_KEY_CREDENTIAL_CERT;
@@ -79,11 +81,10 @@
parseConfigFile();
NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
- std::list<security::Certificate> m_trustAnchors;
+ std::list<Certificate> m_trustAnchors;
std::string m_configFile;
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_CHALLENGE_POSSESSION_HPP
diff --git a/src/detail/ca-configuration.cpp b/src/detail/ca-configuration.cpp
index 813c428..a6d26a0 100644
--- a/src/detail/ca-configuration.cpp
+++ b/src/detail/ca-configuration.cpp
@@ -25,7 +25,6 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -57,7 +56,7 @@
NDN_THROW(std::runtime_error("Redirect-to item's ca-prefix or certificate cannot be empty."));
}
std::istringstream ss(caCertStr);
- auto caCert = io::load<security::Certificate>(ss);
+ auto caCert = ndn::io::load<Certificate>(ss);
redirection.push_back(caCert);
}
}
@@ -77,4 +76,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-configuration.hpp b/src/detail/ca-configuration.hpp
index ba3de47..2a2a9ff 100644
--- a/src/detail/ca-configuration.hpp
+++ b/src/detail/ca-configuration.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,7 +24,6 @@
#include "detail/ca-profile.hpp"
#include "name-assignment/assignment-func.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -67,7 +66,7 @@
/**
* @brief Used for CA redirection
*/
- std::vector<std::shared_ptr<security::Certificate>> redirection;
+ std::vector<std::shared_ptr<Certificate>> redirection;
/**
* @brief Name Assignment Functions
*/
@@ -76,6 +75,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_CONFIGURATION_HPP
diff --git a/src/detail/ca-memory.cpp b/src/detail/ca-memory.cpp
index 48a0903..eae67cc 100644
--- a/src/detail/ca-memory.cpp
+++ b/src/detail/ca-memory.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,15 +19,11 @@
*/
#include "detail/ca-memory.hpp"
-#include <ndn-cxx/security/validation-policy.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
-const std::string
-CaMemory::STORAGE_TYPE = "ca-storage-memory";
-
+const std::string CaMemory::STORAGE_TYPE = "ca-storage-memory";
NDNCERT_REGISTER_CA_STORAGE(CaMemory);
CaMemory::CaMemory(const Name& caName, const std::string& path)
@@ -40,7 +36,8 @@
{
auto search = m_requests.find(requestId);
if (search == m_requests.end()) {
- NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) + " doest not exists"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId.data(), requestId.size()) +
+ " does not exists"));
}
return search->second;
}
@@ -53,7 +50,8 @@
m_requests.insert(std::make_pair(request.requestId, request));
}
else {
- NDN_THROW(std::runtime_error("Request " + toHex(request.requestId.data(), request.requestId.size()) + " already exists"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId.data(), request.requestId.size()) +
+ " already exists"));
}
}
@@ -103,4 +101,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-memory.hpp b/src/detail/ca-memory.hpp
index d61fc10..6d8b115 100644
--- a/src/detail/ca-memory.hpp
+++ b/src/detail/ca-memory.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-storage.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -64,6 +63,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_MEMORY_HPP
diff --git a/src/detail/ca-profile.cpp b/src/detail/ca-profile.cpp
index 0f1ad01..624ec7a 100644
--- a/src/detail/ca-profile.cpp
+++ b/src/detail/ca-profile.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,10 +20,11 @@
#include "detail/ca-profile.hpp"
#include "challenge/challenge-module.hpp"
+
#include <ndn-cxx/util/io.hpp>
+
#include <boost/filesystem.hpp>
-namespace ndn {
namespace ndncert {
CaProfile
@@ -79,7 +80,7 @@
auto certificateStr = json.get(CONFIG_CERTIFICATE, "");
if (certificateStr != "") {
std::istringstream ss(certificateStr);
- profile.cert = io::load<security::Certificate>(ss);
+ profile.cert = ndn::io::load<Certificate>(ss);
}
return profile;
}
@@ -114,11 +115,10 @@
}
if (cert != nullptr) {
std::stringstream ss;
- io::save(*cert, ss);
+ ndn::io::save(*cert, ss);
caItem.put("certificate", ss.str());
}
return caItem;
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-profile.hpp b/src/detail/ca-profile.hpp
index 69adf43..0592be5 100644
--- a/src/detail/ca-profile.hpp
+++ b/src/detail/ca-profile.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ndncert-common.hpp"
-namespace ndn {
namespace ndncert {
// used in parsing CA configuration file and Client CA profile storage file
@@ -90,10 +89,9 @@
/**
* @brief CA's certificate. Only Client side will have m_cert.
*/
- std::shared_ptr<security::Certificate> cert;
+ std::shared_ptr<Certificate> cert;
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_PROFILE_HPP
diff --git a/src/detail/ca-request-state.cpp b/src/detail/ca-request-state.cpp
index b8a6b27..68d189a 100644
--- a/src/detail/ca-request-state.cpp
+++ b/src/detail/ca-request-state.cpp
@@ -24,7 +24,6 @@
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
std::string statusToString(Status status)
@@ -72,7 +71,7 @@
operator<<(std::ostream& os, const RequestState& request)
{
os << "Request's CA name: " << request.caPrefix << "\n";
- os << "Request's request ID: " << toHex(request.requestId.data(), request.requestId.size()) << "\n";
+ os << "Request's request ID: " << ndn::toHex(request.requestId.data(), request.requestId.size()) << "\n";
os << "Request's status: " << statusToString(request.status) << "\n";
os << "Request's challenge type: " << request.challengeType << "\n";
if (request.challengeState) {
@@ -85,11 +84,10 @@
os << "Challenge secret: " << ss.str() << "\n";
}
os << "Certificate:\n";
- util::IndentedStream os2(os, " ");
+ ndn::util::IndentedStream os2(os, " ");
os2 << request.cert;
return os;
}
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-request-state.hpp b/src/detail/ca-request-state.hpp
index fe4db23..2c4a1d6 100644
--- a/src/detail/ca-request-state.hpp
+++ b/src/detail/ca-request-state.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -22,9 +22,9 @@
#define NDNCERT_DETAIL_CA_REQUEST_STATE_HPP
#include "detail/ndncert-common.hpp"
+
#include <array>
-namespace ndn {
namespace ndncert {
typedef std::array<uint8_t, 8> RequestId;
@@ -107,7 +107,7 @@
/**
* @brief The self-signed certificate in the request.
*/
- security::Certificate cert;
+ Certificate cert;
/**
* @brief The encryption key for the requester.
*/
@@ -135,6 +135,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP
diff --git a/src/detail/ca-sqlite.cpp b/src/detail/ca-sqlite.cpp
index c247501..45cd84d 100644
--- a/src/detail/ca-sqlite.cpp
+++ b/src/detail/ca-sqlite.cpp
@@ -28,16 +28,15 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
-using namespace ndn::util;
-const std::string CaSqlite::STORAGE_TYPE = "ca-storage-sqlite3";
+using ndn::util::Sqlite3Statement;
+const std::string CaSqlite::STORAGE_TYPE = "ca-storage-sqlite3";
NDNCERT_REGISTER_CA_STORAGE(CaSqlite);
-std::string
+static std::string
convertJson2String(const JsonSection& json)
{
std::stringstream ss;
@@ -45,7 +44,7 @@
return ss.str();
}
-JsonSection
+static JsonSection
convertString2Json(const std::string& jsonContent)
{
std::istringstream ss(jsonContent);
@@ -54,7 +53,7 @@
return json;
}
-static const std::string INITIALIZATION = R"_DBTEXT_(
+const std::string INITIALIZATION = R"SQL(
CREATE TABLE IF NOT EXISTS
RequestStates(
id INTEGER PRIMARY KEY,
@@ -75,10 +74,10 @@
);
CREATE UNIQUE INDEX IF NOT EXISTS
RequestStateIdIndex ON RequestStates(request_id);
-)_DBTEXT_";
+)SQL";
CaSqlite::CaSqlite(const Name& caName, const std::string& path)
- : CaStorage()
+ : CaStorage()
{
// Determine the path of sqlite db
boost::filesystem::path dbDir;
@@ -143,7 +142,7 @@
state.requestId = requestId;
state.caPrefix = Name(statement.getBlock(1));
state.status = static_cast<Status>(statement.getInt(2));
- state.cert = security::Certificate(statement.getBlock(4));
+ state.cert = Certificate(statement.getBlock(4));
state.challengeType = statement.getString(5);
state.requestType = static_cast<RequestType>(statement.getInt(10));
std::memcpy(state.encryptionKey.data(), statement.getBlob(11), statement.getSize(11));
@@ -158,7 +157,7 @@
return state;
}
else {
- NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) +
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId.data(), requestId.size()) +
" cannot be fetched from database"));
}
}
@@ -189,7 +188,7 @@
statement.bind(11, request.challengeState->remainingTime.count());
}
if (statement.step() != SQLITE_DONE) {
- NDN_THROW(std::runtime_error("Request " + toHex(request.requestId.data(), request.requestId.size()) +
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId.data(), request.requestId.size()) +
" cannot be added to database"));
}
}
@@ -242,7 +241,7 @@
state.caPrefix = Name(statement.getBlock(2));
state.status = static_cast<Status>(statement.getInt(3));
state.challengeType = statement.getString(6);
- state.cert = security::Certificate(statement.getBlock(5));
+ state.cert = Certificate(statement.getBlock(5));
state.requestType = static_cast<RequestType>(statement.getInt(11));
std::memcpy(state.encryptionKey.data(), statement.getBlob(12), statement.getSize(12));
state.encryptionIv = std::vector<uint8_t>(statement.getBlob(13), statement.getBlob(13) + statement.getSize(13));
@@ -276,7 +275,7 @@
state.caPrefix = Name(statement.getBlock(2));
state.status = static_cast<Status>(statement.getInt(3));
state.challengeType = statement.getString(6);
- state.cert = security::Certificate(statement.getBlock(5));
+ state.cert = Certificate(statement.getBlock(5));
state.requestType = static_cast<RequestType>(statement.getInt(11));
std::memcpy(state.encryptionKey.data(), statement.getBlob(12), statement.getSize(12));
state.encryptionIv = std::vector<uint8_t>(statement.getBlob(13), statement.getBlob(13) + statement.getSize(13));
@@ -303,4 +302,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-sqlite.hpp b/src/detail/ca-sqlite.hpp
index 2577a80..969cacf 100644
--- a/src/detail/ca-sqlite.hpp
+++ b/src/detail/ca-sqlite.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,7 +25,6 @@
struct sqlite3;
-namespace ndn {
namespace ndncert {
namespace ca {
@@ -37,7 +36,7 @@
explicit
CaSqlite(const Name& caName, const std::string& path = "");
- ~CaSqlite();
+ ~CaSqlite() override;
public:
/**
@@ -70,6 +69,5 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_SQLITE_HPP
diff --git a/src/detail/ca-storage.cpp b/src/detail/ca-storage.cpp
index a377c6c..24fe38f 100644
--- a/src/detail/ca-storage.cpp
+++ b/src/detail/ca-storage.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,11 +20,10 @@
#include "detail/ca-storage.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
-unique_ptr<CaStorage>
+std::unique_ptr<CaStorage>
CaStorage::createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path)
{
CaStorageFactory& factory = getFactory();
@@ -41,4 +40,3 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ca-storage.hpp b/src/detail/ca-storage.hpp
index 40166cf..0fa7238 100644
--- a/src/detail/ca-storage.hpp
+++ b/src/detail/ca-storage.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,11 +23,10 @@
#include "detail/ca-request-state.hpp"
-namespace ndn {
namespace ndncert {
namespace ca {
-class CaStorage : noncopyable
+class CaStorage : boost::noncopyable
{
public: // request related
/**
@@ -66,14 +65,14 @@
};
}
- static unique_ptr<CaStorage>
+ static std::unique_ptr<CaStorage>
createCaStorage(const std::string& caStorageType, const Name& caName, const std::string& path);
virtual
~CaStorage() = default;
private:
- using CaStorageCreateFunc = function<unique_ptr<CaStorage> (const Name&, const std::string&)>;
+ using CaStorageCreateFunc = std::function<std::unique_ptr<CaStorage> (const Name&, const std::string&)>;
using CaStorageFactory = std::map<std::string, CaStorageCreateFunc>;
static CaStorageFactory&
@@ -86,12 +85,11 @@
public: \
NdnCert ## C ## CaStorageRegistrationClass() \
{ \
- ::ndn::ndncert::ca::CaStorage::registerCaStorage<C>(); \
+ ::ndncert::ca::CaStorage::registerCaStorage<C>(); \
} \
} g_NdnCert ## C ## CaStorageRegistrationVariable
} // namespace ca
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CA_STORAGE_HPP
diff --git a/src/detail/challenge-encoder.cpp b/src/detail/challenge-encoder.cpp
index 11a0168..5d9d46b 100644
--- a/src/detail/challenge-encoder.cpp
+++ b/src/detail/challenge-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,30 +20,30 @@
#include "detail/challenge-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
challengetlv::encodeDataContent(ca::RequestState& request, const Name& issuedCertName)
{
Block response(tlv::EncryptedPayload);
- response.push_back(makeNonNegativeIntegerBlock(tlv::Status, static_cast<uint64_t>(request.status)));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::Status, static_cast<uint64_t>(request.status)));
if (request.challengeState) {
- response.push_back(makeStringBlock(tlv::ChallengeStatus, request.challengeState->challengeStatus));
- response.push_back(makeNonNegativeIntegerBlock(tlv::RemainingTries,
- request.challengeState->remainingTries));
- response.push_back(makeNonNegativeIntegerBlock(tlv::RemainingTime,
- request.challengeState->remainingTime.count()));
+ response.push_back(ndn::makeStringBlock(tlv::ChallengeStatus, request.challengeState->challengeStatus));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::RemainingTries,
+ request.challengeState->remainingTries));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::RemainingTime,
+ request.challengeState->remainingTime.count()));
if (request.challengeState->challengeStatus == "need-proof") {
- response.push_back(makeStringBlock(tlv::ParameterKey, "nonce"));
- auto nonce = fromHex(request.challengeState->secrets.get("nonce", ""));
- response.push_back(makeBinaryBlock(tlv::ParameterValue, nonce->data(), 16));
+ response.push_back(ndn::makeStringBlock(tlv::ParameterKey, "nonce"));
+ auto nonce = ndn::fromHex(request.challengeState->secrets.get("nonce", ""));
+ response.push_back(ndn::makeBinaryBlock(tlv::ParameterValue, nonce->data(), 16));
}
}
if (!issuedCertName.empty()) {
response.push_back(makeNestedBlock(tlv::IssuedCertName, issuedCertName));
}
response.encode();
+
return encodeBlockWithAesGcm128(ndn::tlv::Content, request.encryptionKey.data(),
response.value(), response.value_size(),
request.requestId.data(), request.requestId.size(),
@@ -56,8 +56,9 @@
auto result = decodeBlockWithAesGcm128(contentBlock, state.m_aesKey.data(),
state.m_requestId.data(), state.m_requestId.size(),
state.m_decryptionIv, state.m_encryptionIv);
- auto data = makeBinaryBlock(tlv::EncryptedPayload, result.data(), result.size());
+ auto data = ndn::makeBinaryBlock(tlv::EncryptedPayload, result.data(), result.size());
data.parse();
+
state.m_status = statusFromBlock(data.get(tlv::Status));
if (data.find(tlv::ChallengeStatus) != data.elements_end()) {
state.m_challengeStatus = readString(data.get(tlv::ChallengeStatus));
@@ -87,4 +88,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/challenge-encoder.hpp b/src/detail/challenge-encoder.hpp
index a8baa57..2013061 100644
--- a/src/detail/challenge-encoder.hpp
+++ b/src/detail/challenge-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,7 +24,6 @@
#include "detail/ca-request-state.hpp"
#include "requester-request.hpp"
-namespace ndn {
namespace ndncert {
namespace challengetlv {
@@ -36,6 +35,5 @@
} // namespace challengetlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_CHALLENGE_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_CHALLENGE_ENCODER_HPP
diff --git a/src/detail/crypto-helpers.cpp b/src/detail/crypto-helpers.cpp
index a2a0af5..d0c2e55 100644
--- a/src/detail/crypto-helpers.cpp
+++ b/src/detail/crypto-helpers.cpp
@@ -37,7 +37,6 @@
#include <cstring>
-namespace ndn {
namespace ndncert {
ECDHState::ECDHState()
@@ -416,25 +415,25 @@
{
// The spec of AES encrypted payload TLV used in NDNCERT:
// https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#242-aes-gcm-encryption
- Buffer encryptedPayload(payloadSize);
+ ndn::Buffer encryptedPayload(payloadSize);
uint8_t tag[16];
if (encryptionIv.empty()) {
encryptionIv.resize(12, 0);
- random::generateSecureBytes(encryptionIv.data(), 8);
+ ndn::random::generateSecureBytes(encryptionIv.data(), 8);
}
size_t encryptedPayloadLen = aesGcm128Encrypt(payload, payloadSize, associatedData, associatedDataSize,
key, encryptionIv.data(), encryptedPayload.data(), tag);
Block content(tlvType);
- content.push_back(makeBinaryBlock(tlv::InitializationVector, encryptionIv.data(), encryptionIv.size()));
- content.push_back(makeBinaryBlock(tlv::AuthenticationTag, tag, 16));
- content.push_back(makeBinaryBlock(tlv::EncryptedPayload, encryptedPayload.data(), encryptedPayloadLen));
+ content.push_back(ndn::makeBinaryBlock(tlv::InitializationVector, encryptionIv.data(), encryptionIv.size()));
+ content.push_back(ndn::makeBinaryBlock(tlv::AuthenticationTag, tag, 16));
+ content.push_back(ndn::makeBinaryBlock(tlv::EncryptedPayload, encryptedPayload.data(), encryptedPayloadLen));
content.encode();
// update IV's counter
updateIv(encryptionIv, payloadSize);
return content;
}
-Buffer
+ndn::Buffer
decodeBlockWithAesGcm128(const Block& block, const uint8_t* key,
const uint8_t* associatedData, size_t associatedDataSize,
std::vector<uint8_t>& decryptionIv, const std::vector<uint8_t>& encryptionIv)
@@ -443,7 +442,7 @@
// https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#242-aes-gcm-encryption
block.parse();
const auto& encryptedPayloadBlock = block.get(tlv::EncryptedPayload);
- Buffer result(encryptedPayloadBlock.value_size());
+ ndn::Buffer result(encryptedPayloadBlock.value_size());
if (block.get(tlv::InitializationVector).value_size() != 12 ||
block.get(tlv::AuthenticationTag).value_size() != 16) {
NDN_THROW(std::runtime_error("Error when decrypting the AES Encrypted Block: "
@@ -478,4 +477,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/crypto-helpers.hpp b/src/detail/crypto-helpers.hpp
index 9701786..235c6b5 100644
--- a/src/detail/crypto-helpers.hpp
+++ b/src/detail/crypto-helpers.hpp
@@ -25,7 +25,6 @@
#include <openssl/evp.h>
-namespace ndn {
namespace ndncert {
/**
@@ -33,7 +32,7 @@
*
* The ECDH is based on prime256v1.
*/
-class ECDHState : noncopyable
+class ECDHState : boost::noncopyable
{
public:
ECDHState();
@@ -169,7 +168,7 @@
* invocations of this function with the same @p key.
* @return Buffer The plaintext buffer.
*/
-Buffer
+ndn::Buffer
decodeBlockWithAesGcm128(const Block& block, const uint8_t* key,
const uint8_t* associatedData, size_t associatedDataSize,
std::vector<uint8_t>& decryptionIv, const std::vector<uint8_t>& encryptionIv);
@@ -183,6 +182,5 @@
#endif
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_CRYPTO_HELPERS_HPP
diff --git a/src/detail/error-encoder.cpp b/src/detail/error-encoder.cpp
index 3fbbdc2..e1e4357 100644
--- a/src/detail/error-encoder.cpp
+++ b/src/detail/error-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,15 +20,14 @@
#include "detail/error-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
errortlv::encodeDataContent(ErrorCode errorCode, const std::string& description)
{
Block response(ndn::tlv::Content);
- response.push_back(makeNonNegativeIntegerBlock(tlv::ErrorCode, static_cast<size_t>(errorCode)));
- response.push_back(makeStringBlock(tlv::ErrorInfo, description));
+ response.push_back(ndn::makeNonNegativeIntegerBlock(tlv::ErrorCode, static_cast<size_t>(errorCode)));
+ response.push_back(ndn::makeStringBlock(tlv::ErrorInfo, description));
response.encode();
return response;
}
@@ -45,4 +44,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/error-encoder.hpp b/src/detail/error-encoder.hpp
index 67fe80f..3b17353 100644
--- a/src/detail/error-encoder.hpp
+++ b/src/detail/error-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-profile.hpp"
-namespace ndn {
namespace ndncert {
namespace errortlv {
@@ -41,6 +40,5 @@
} // namespace errortlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_ERROR_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_ERROR_ENCODER_HPP
diff --git a/src/detail/info-encoder.cpp b/src/detail/info-encoder.cpp
index 79f617f..e6e6581 100644
--- a/src/detail/info-encoder.cpp
+++ b/src/detail/info-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,11 +20,10 @@
#include "detail/info-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
-infotlv::encodeDataContent(const CaProfile& caConfig, const security::Certificate& certificate)
+infotlv::encodeDataContent(const CaProfile& caConfig, const Certificate& certificate)
{
Block content(ndn::tlv::Content);
content.push_back(makeNestedBlock(tlv::CaPrefix, caConfig.caPrefix));
@@ -35,11 +34,11 @@
else {
caInfo = caConfig.caInfo;
}
- content.push_back(makeStringBlock(tlv::CaInfo, caInfo));
+ content.push_back(ndn::makeStringBlock(tlv::CaInfo, caInfo));
for (const auto& key : caConfig.probeParameterKeys) {
- content.push_back(makeStringBlock(tlv::ParameterKey, key));
+ content.push_back(ndn::makeStringBlock(tlv::ParameterKey, key));
}
- content.push_back(makeNonNegativeIntegerBlock(tlv::MaxValidityPeriod, caConfig.maxValidityPeriod.count()));
+ content.push_back(ndn::makeNonNegativeIntegerBlock(tlv::MaxValidityPeriod, caConfig.maxValidityPeriod.count()));
content.push_back(makeNestedBlock(tlv::CaCertificate, certificate));
content.encode();
return content;
@@ -67,7 +66,7 @@
break;
case tlv::CaCertificate:
item.parse();
- result.cert = std::make_shared<security::Certificate>(item.get(ndn::tlv::Data));
+ result.cert = std::make_shared<Certificate>(item.get(ndn::tlv::Data));
break;
default:
continue;
@@ -78,4 +77,3 @@
}
} // namespace ndncert
-} // namespace ndn
\ No newline at end of file
diff --git a/src/detail/info-encoder.hpp b/src/detail/info-encoder.hpp
index 7f9180e..4eaa967 100644
--- a/src/detail/info-encoder.hpp
+++ b/src/detail/info-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-profile.hpp"
-namespace ndn {
namespace ndncert {
namespace infotlv {
@@ -31,7 +30,7 @@
* Encode CA configuration and its certificate into a TLV block as INFO Data packet content.
*/
Block
-encodeDataContent(const CaProfile& caConfig, const security::Certificate& certificate);
+encodeDataContent(const CaProfile& caConfig, const Certificate& certificate);
/**
* Decode CA configuration from the TLV block of INFO Data packet content.
@@ -41,6 +40,5 @@
} // namespace infotlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_INFO_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_INFO_ENCODER_HPP
diff --git a/src/detail/ndncert-common.cpp b/src/detail/ndncert-common.cpp
index 7c210b7..5e22afb 100644
--- a/src/detail/ndncert-common.cpp
+++ b/src/detail/ndncert-common.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,7 +20,6 @@
#include "detail/ndncert-common.hpp"
-namespace ndn {
namespace ndncert {
std::ostream&
@@ -56,4 +55,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/ndncert-common.hpp b/src/detail/ndncert-common.hpp
index 01fa883..d9863a5 100644
--- a/src/detail/ndncert-common.hpp
+++ b/src/detail/ndncert-common.hpp
@@ -41,26 +41,37 @@
#include <tuple>
#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/encoding/block-helpers.hpp>
#include <ndn-cxx/encoding/block.hpp>
-#include <ndn-cxx/encoding/tlv.hpp>
-#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/encoding/block-helpers.hpp>
#include <ndn-cxx/interest.hpp>
-#include <ndn-cxx/lp/nack.hpp>
#include <ndn-cxx/name.hpp>
#include <ndn-cxx/security/certificate.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
+#include <ndn-cxx/util/exception.hpp>
#include <ndn-cxx/util/logger.hpp>
#include <ndn-cxx/util/optional.hpp>
+#include <ndn-cxx/util/time.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/assert.hpp>
#include <boost/noncopyable.hpp>
#include <boost/property_tree/ptree.hpp>
-namespace ndn {
namespace ndncert {
+using ndn::Block;
+using ndn::Data;
+using ndn::Interest;
+using ndn::Name;
+using ndn::SignatureInfo;
+using ndn::security::Certificate;
+
+using ndn::optional;
+using ndn::nullopt;
+
+namespace time = ndn::time;
+using namespace ndn::time_literals;
+using namespace std::string_literals;
+
namespace tlv {
enum : uint32_t {
@@ -127,6 +138,5 @@
operator<<(std::ostream& out, RequestType type);
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_NDNCERT_COMMON_HPP
diff --git a/src/detail/probe-encoder.cpp b/src/detail/probe-encoder.cpp
index 24471a7..bf51438 100644
--- a/src/detail/probe-encoder.cpp
+++ b/src/detail/probe-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,7 +20,6 @@
#include "detail/probe-encoder.hpp"
-namespace ndn {
namespace ndncert {
Block
@@ -28,8 +27,8 @@
{
Block content(ndn::tlv::ApplicationParameters);
for (const auto& items : parameters) {
- content.push_back(makeStringBlock(tlv::ParameterKey, items.first));
- content.push_back(makeStringBlock(tlv::ParameterValue, items.second));
+ content.push_back(ndn::makeStringBlock(tlv::ParameterKey, items.first));
+ content.push_back(ndn::makeStringBlock(tlv::ParameterValue, items.second));
}
content.encode();
return content;
@@ -51,14 +50,14 @@
Block
probetlv::encodeDataContent(const std::vector<Name>& identifiers, optional<size_t> maxSuffixLength,
- std::vector<std::shared_ptr<security::Certificate>> redirectionItems)
+ std::vector<std::shared_ptr<Certificate>> redirectionItems)
{
Block content(ndn::tlv::Content);
for (const auto& name : identifiers) {
Block item(tlv::ProbeResponse);
item.push_back(name.wireEncode());
if (maxSuffixLength) {
- item.push_back(makeNonNegativeIntegerBlock(tlv::MaxSuffixLength, *maxSuffixLength));
+ item.push_back(ndn::makeNonNegativeIntegerBlock(tlv::MaxSuffixLength, *maxSuffixLength));
}
content.push_back(item);
}
@@ -71,8 +70,8 @@
void
probetlv::decodeDataContent(const Block& block,
- std::vector<std::pair<Name, int>>& availableNames,
- std::vector<Name>& availableRedirection)
+ std::vector<std::pair<Name, int>>& availableNames,
+ std::vector<Name>& availableRedirection)
{
block.parse();
for (const auto& item : block.elements()) {
@@ -103,4 +102,3 @@
}
} // namespace ndncert
-} // namespace ndn
\ No newline at end of file
diff --git a/src/detail/probe-encoder.hpp b/src/detail/probe-encoder.hpp
index 58bcb44..6afe083 100644
--- a/src/detail/probe-encoder.hpp
+++ b/src/detail/probe-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ndncert-common.hpp"
-namespace ndn {
namespace ndncert {
namespace probetlv {
@@ -39,14 +38,13 @@
Block
encodeDataContent(const std::vector<Name>& identifiers,
optional<size_t> maxSuffixLength = nullopt,
- std::vector<std::shared_ptr<security::Certificate>> redirectionItems =
- std::vector<std::shared_ptr<security::Certificate>>());
+ std::vector<std::shared_ptr<Certificate>> redirectionItems =
+ std::vector<std::shared_ptr<Certificate>>());
std::multimap<std::string, std::string>
decodeApplicationParameters(const Block& block);
} // namespace probetlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_PROBE_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_PROBE_ENCODER_HPP
diff --git a/src/detail/profile-storage.cpp b/src/detail/profile-storage.cpp
index 949309a..8ae2bb6 100644
--- a/src/detail/profile-storage.cpp
+++ b/src/detail/profile-storage.cpp
@@ -23,7 +23,6 @@
#include <boost/filesystem.hpp>
#include <boost/property_tree/json_parser.hpp>
-namespace ndn {
namespace ndncert {
namespace requester {
@@ -99,4 +98,3 @@
} // namespace requester
} // namespace ndncert
-} // namespace ndn
diff --git a/src/detail/profile-storage.hpp b/src/detail/profile-storage.hpp
index 5955f15..3df6407 100644
--- a/src/detail/profile-storage.hpp
+++ b/src/detail/profile-storage.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "detail/ca-profile.hpp"
-namespace ndn {
namespace ndncert {
namespace requester {
@@ -69,6 +68,5 @@
} // namespace requester
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_DETAIL_PROFILE_STORAGE_HPP
diff --git a/src/detail/request-encoder.cpp b/src/detail/request-encoder.cpp
index 1801b63..30e2523 100644
--- a/src/detail/request-encoder.cpp
+++ b/src/detail/request-encoder.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,20 +19,21 @@
*/
#include "detail/request-encoder.hpp"
+
#include <ndn-cxx/security/transform/base64-encode.hpp>
#include <ndn-cxx/security/transform/buffer-source.hpp>
#include <ndn-cxx/security/transform/stream-sink.hpp>
-namespace ndn {
namespace ndncert {
Block
-requesttlv::encodeApplicationParameters(RequestType requestType, const std::vector <uint8_t>& ecdhPub,
- const security::Certificate& certRequest)
+requesttlv::encodeApplicationParameters(RequestType requestType,
+ const std::vector<uint8_t>& ecdhPub,
+ const Certificate& certRequest)
{
Block
request(ndn::tlv::ApplicationParameters);
- request.push_back(makeBinaryBlock(tlv::EcdhPub, ecdhPub.data(), ecdhPub.size()));
+ request.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhPub.data(), ecdhPub.size()));
if (requestType == RequestType::NEW || requestType == RequestType::RENEW) {
request.push_back(makeNestedBlock(tlv::CertRequest, certRequest));
}
@@ -45,8 +46,8 @@
void
requesttlv::decodeApplicationParameters(const Block& payload, RequestType requestType,
- std::vector <uint8_t>& ecdhPub,
- shared_ptr <security::Certificate>& clientCert)
+ std::vector<uint8_t>& ecdhPub,
+ std::shared_ptr<Certificate>& clientCert)
{
payload.parse();
@@ -63,8 +64,7 @@
}
requestPayload.parse();
- security::Certificate cert = security::Certificate(requestPayload.get(ndn::tlv::Data));
- clientCert = std::make_shared<security::Certificate>(cert);
+ clientCert = std::make_shared<Certificate>(requestPayload.get(ndn::tlv::Data));
}
Block
@@ -73,11 +73,11 @@
const std::vector <std::string>& challenges)
{
Block response(ndn::tlv::Content);
- response.push_back(makeBinaryBlock(tlv::EcdhPub, ecdhKey.data(), ecdhKey.size()));
- response.push_back(makeBinaryBlock(tlv::Salt, salt.data(), salt.size()));
- response.push_back(makeBinaryBlock(tlv::RequestId, requestId.data(), requestId.size()));
+ response.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhKey.data(), ecdhKey.size()));
+ response.push_back(ndn::makeBinaryBlock(tlv::Salt, salt.data(), salt.size()));
+ response.push_back(ndn::makeBinaryBlock(tlv::RequestId, requestId.data(), requestId.size()));
for (const auto& entry: challenges) {
- response.push_back(makeStringBlock(tlv::Challenge, entry));
+ response.push_back(ndn::makeStringBlock(tlv::Challenge, entry));
}
response.encode();
return response;
@@ -109,4 +109,3 @@
}
} // namespace ndncert
-} // namespace ndn
\ No newline at end of file
diff --git a/src/detail/request-encoder.hpp b/src/detail/request-encoder.hpp
index aff7c62..e94571e 100644
--- a/src/detail/request-encoder.hpp
+++ b/src/detail/request-encoder.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,17 +23,16 @@
#include "detail/ca-request-state.hpp"
-namespace ndn {
namespace ndncert {
namespace requesttlv {
Block
encodeApplicationParameters(RequestType requestType, const std::vector<uint8_t>& ecdhPub,
- const security::Certificate& certRequest);
+ const Certificate& certRequest);
void
decodeApplicationParameters(const Block& block, RequestType requestType, std::vector<uint8_t>& ecdhPub,
- shared_ptr<security::Certificate>& certRequest);
+ std::shared_ptr<Certificate>& certRequest);
Block
encodeDataContent(const std::vector<uint8_t>& ecdhKey, const std::array<uint8_t, 32>& salt,
@@ -45,6 +44,5 @@
} // namespace requesttlv
} // namespace ndncert
-} // namespace ndn
-#endif // NDNCERT_DETAIL_NEW_RENEW_REVOKE_ENCODER_HPP
\ No newline at end of file
+#endif // NDNCERT_DETAIL_REQUEST_ENCODER_HPP
diff --git a/src/name-assignment/assignment-func.cpp b/src/name-assignment/assignment-func.cpp
index d65eefd..f4728d3 100644
--- a/src/name-assignment/assignment-func.cpp
+++ b/src/name-assignment/assignment-func.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,9 +19,7 @@
*/
#include "assignment-func.hpp"
-#include <ndn-cxx/util/random.hpp>
-namespace ndn {
namespace ndncert {
NameAssignmentFunc::NameAssignmentFunc(const std::string& format)
@@ -39,7 +37,7 @@
}
}
-unique_ptr<NameAssignmentFunc>
+std::unique_ptr<NameAssignmentFunc>
NameAssignmentFunc::createNameAssignmentFunc(const std::string& challengeType, const std::string& format)
{
CurriedFuncFactory& factory = getFactory();
@@ -55,4 +53,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/name-assignment/assignment-func.hpp b/src/name-assignment/assignment-func.hpp
index 9e9b128..7f35fcf 100644
--- a/src/name-assignment/assignment-func.hpp
+++ b/src/name-assignment/assignment-func.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -22,12 +22,12 @@
#define NDNCERT_ASSIGNMENT_FUNC_HPP
#include "detail/ca-request-state.hpp"
+
#include <map>
-namespace ndn {
namespace ndncert {
-class NameAssignmentFunc : noncopyable
+class NameAssignmentFunc : boost::noncopyable
{
protected:
explicit NameAssignmentFunc(const std::string& format = "");
@@ -45,7 +45,7 @@
* @param vector A list of parameter key-value pair used for name assignment.
* @return a vector containing the possible namespaces derived from the parameters.
*/
- virtual std::vector<PartialName>
+ virtual std::vector<ndn::PartialName>
assignName(const std::multimap<std::string, std::string>& params) = 0;
public:
@@ -58,14 +58,14 @@
factory[typeName] = [](const std::string& format) { return std::make_unique<AssignmentType>(format); };
}
- static unique_ptr<NameAssignmentFunc>
+ static std::unique_ptr<NameAssignmentFunc>
createNameAssignmentFunc(const std::string& challengeType, const std::string& format = "");
NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
std::vector<std::string> m_nameFormat;
private:
- typedef function<unique_ptr<NameAssignmentFunc>(const std::string&)> FactoryCreateFunc;
+ typedef std::function<std::unique_ptr<NameAssignmentFunc>(const std::string&)> FactoryCreateFunc;
typedef std::map<std::string, FactoryCreateFunc> CurriedFuncFactory;
static CurriedFuncFactory&
@@ -73,15 +73,15 @@
};
#define NDNCERT_REGISTER_FUNCFACTORY(C, T) \
- static class NdnCert##C##FuncFactoryRegistrationClass { \
+ static class NdnCert##C##FuncFactoryRegistrationClass \
+ { \
public: \
NdnCert##C##FuncFactoryRegistrationClass() \
{ \
- ::ndn::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T); \
+ ::ndncert::NameAssignmentFunc::registerNameAssignmentFunc<C>(T); \
} \
} g_NdnCert##C##ChallengeRegistrationVariable
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_ASSIGNMENT_FUNC_HPP
diff --git a/src/name-assignment/assignment-hash.cpp b/src/name-assignment/assignment-hash.cpp
index f292821..f406619 100644
--- a/src/name-assignment/assignment-hash.cpp
+++ b/src/name-assignment/assignment-hash.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,26 +19,27 @@
*/
#include "assignment-hash.hpp"
+
#include <ndn-cxx/util/sha256.hpp>
-namespace ndn {
namespace ndncert {
NDNCERT_REGISTER_FUNCFACTORY(AssignmentHash, "hash");
AssignmentHash::AssignmentHash(const std::string& format)
: NameAssignmentFunc(format)
-{}
+{
+}
-std::vector<PartialName>
+std::vector<ndn::PartialName>
AssignmentHash::assignName(const std::multimap<std::string, std::string>& params)
{
- std::vector<PartialName> resultList;
+ std::vector<ndn::PartialName> resultList;
Name result;
for (const auto& item : m_nameFormat) {
auto it = params.find(item);
if (it != params.end()) {
- util::Sha256 digest;
+ ndn::util::Sha256 digest;
digest << it->second;
result.append(digest.toString());
}
@@ -51,4 +52,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/name-assignment/assignment-hash.hpp b/src/name-assignment/assignment-hash.hpp
index 83acc28..66d3984 100644
--- a/src/name-assignment/assignment-hash.hpp
+++ b/src/name-assignment/assignment-hash.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "assignment-func.hpp"
-namespace ndn {
namespace ndncert {
/**
@@ -34,12 +33,10 @@
public:
AssignmentHash(const std::string& format = "");
- std::vector<PartialName>
+ std::vector<ndn::PartialName>
assignName(const std::multimap<std::string, std::string>& params) override;
-
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_ASSIGNMENT_HASH_HPP
diff --git a/src/name-assignment/assignment-param.cpp b/src/name-assignment/assignment-param.cpp
index 53022cc..956b3d8 100644
--- a/src/name-assignment/assignment-param.cpp
+++ b/src/name-assignment/assignment-param.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,19 +20,19 @@
#include "assignment-param.hpp"
-namespace ndn {
namespace ndncert {
NDNCERT_REGISTER_FUNCFACTORY(AssignmentParam, "param");
AssignmentParam::AssignmentParam(const std::string& format)
: NameAssignmentFunc(format)
-{}
+{
+}
-std::vector<PartialName>
+std::vector<ndn::PartialName>
AssignmentParam::assignName(const std::multimap<std::string, std::string>& params)
{
- std::vector<PartialName> resultList;
+ std::vector<ndn::PartialName> resultList;
Name result;
for (const auto& item : m_nameFormat) {
auto it = std::find_if(params.begin(), params.end(),
@@ -49,4 +49,3 @@
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/name-assignment/assignment-param.hpp b/src/name-assignment/assignment-param.hpp
index 52bcb80..fc77d27 100644
--- a/src/name-assignment/assignment-param.hpp
+++ b/src/name-assignment/assignment-param.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "assignment-func.hpp"
-namespace ndn {
namespace ndncert {
/**
@@ -34,12 +33,10 @@
public:
AssignmentParam(const std::string& format = "");
- std::vector<PartialName>
+ std::vector<ndn::PartialName>
assignName(const std::multimap<std::string, std::string>& params) override;
-
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_ASSIGNMENT_PARAM_HPP
diff --git a/src/name-assignment/assignment-random.cpp b/src/name-assignment/assignment-random.cpp
index 284a1f7..3305cae 100644
--- a/src/name-assignment/assignment-random.cpp
+++ b/src/name-assignment/assignment-random.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,24 +19,22 @@
*/
#include "assignment-random.hpp"
+
#include <ndn-cxx/util/random.hpp>
-namespace ndn {
namespace ndncert {
NDNCERT_REGISTER_FUNCFACTORY(AssignmentRandom, "random");
AssignmentRandom::AssignmentRandom(const std::string& format)
: NameAssignmentFunc(format)
-{}
-
-std::vector<PartialName>
-AssignmentRandom::assignName(const std::multimap<std::string, std::string>& params)
{
- std::vector<PartialName> resultList;
- resultList.emplace_back(to_string(random::generateSecureWord64()));
- return resultList;
+}
+
+std::vector<ndn::PartialName>
+AssignmentRandom::assignName(const std::multimap<std::string, std::string>&)
+{
+ return {ndn::PartialName(ndn::to_string(ndn::random::generateSecureWord64()))};
}
} // namespace ndncert
-} // namespace ndn
diff --git a/src/name-assignment/assignment-random.hpp b/src/name-assignment/assignment-random.hpp
index 86f8096..872c784 100644
--- a/src/name-assignment/assignment-random.hpp
+++ b/src/name-assignment/assignment-random.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,7 +23,6 @@
#include "assignment-func.hpp"
-namespace ndn {
namespace ndncert {
/**
@@ -34,11 +33,10 @@
public:
AssignmentRandom(const std::string& format = "");
- std::vector<PartialName>
+ std::vector<ndn::PartialName>
assignName(const std::multimap<std::string, std::string>& params) override;
};
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_ASSIGNMENT_RANDOM_HPP
diff --git a/src/requester-request.cpp b/src/requester-request.cpp
index 5929794..6ab56ea 100644
--- a/src/requester-request.cpp
+++ b/src/requester-request.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,6 +19,7 @@
*/
#include "requester-request.hpp"
+
#include "challenge/challenge-module.hpp"
#include "detail/crypto-helpers.hpp"
#include "detail/challenge-encoder.hpp"
@@ -26,6 +27,8 @@
#include "detail/info-encoder.hpp"
#include "detail/request-encoder.hpp"
#include "detail/probe-encoder.hpp"
+
+#include <ndn-cxx/metadata-object.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/transform/base64-encode.hpp>
#include <ndn-cxx/security/transform/buffer-source.hpp>
@@ -33,41 +36,32 @@
#include <ndn-cxx/security/verification-helpers.hpp>
#include <ndn-cxx/util/io.hpp>
#include <ndn-cxx/util/random.hpp>
-#include <ndn-cxx/metadata-object.hpp>
+
#include <boost/lexical_cast.hpp>
-namespace ndn {
namespace ndncert {
namespace requester {
NDN_LOG_INIT(ndncert.client);
-shared_ptr<Interest>
+std::shared_ptr<Interest>
Request::genCaProfileDiscoveryInterest(const Name& caName)
{
Name contentName = caName;
if (readString(caName.at(-1)) != "CA")
contentName.append("CA");
contentName.append("INFO");
- return std::make_shared<Interest>(MetadataObject::makeDiscoveryInterest(contentName));
+ return std::make_shared<Interest>(ndn::MetadataObject::makeDiscoveryInterest(contentName));
}
-shared_ptr<Interest>
+std::shared_ptr<Interest>
Request::genCaProfileInterestFromDiscoveryResponse(const Data& reply)
{
- // set naming convention to be typed
- auto convention = name::getConventionEncoding();
- name::setConventionEncoding(name::Convention::TYPED);
-
- auto metaData = MetadataObject(reply);
+ auto metaData = ndn::MetadataObject(reply);
auto interestName= metaData.getVersionedName();
interestName.appendSegment(0);
auto interest = std::make_shared<Interest>(interestName);
interest->setCanBePrefix(false);
-
- // set back the convention
- name::setConventionEncoding(convention);
-
return interest;
}
@@ -75,7 +69,7 @@
Request::onCaProfileResponse(const Data& reply)
{
auto caItem = infotlv::decodeDataContent(reply.getContent());
- if (!security::verifySignature(reply, *caItem.cert)) {
+ if (!ndn::security::verifySignature(reply, *caItem.cert)) {
NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
}
@@ -87,7 +81,7 @@
{
auto caItem = infotlv::decodeDataContent(reply.getContent());
auto certBlock = caItem.cert->wireEncode();
- caItem.cert = std::make_shared<security::Certificate>(certBlock);
+ caItem.cert = std::make_shared<Certificate>(certBlock);
if (caItem.cert->getFullName() != caCertFullName) {
NDN_LOG_ERROR("Ca profile does not match the certificate information offered by the original CA.");
NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
@@ -95,12 +89,12 @@
return onCaProfileResponse(reply);
}
-shared_ptr<Interest>
+std::shared_ptr<Interest>
Request::genProbeInterest(const CaProfile& ca, std::multimap<std::string, std::string>&& probeInfo)
{
Name interestName = ca.caPrefix;
interestName.append("CA").append("PROBE");
- auto interest =std::make_shared<Interest>(interestName);
+ auto interest = std::make_shared<Interest>(interestName);
interest->setMustBeFresh(true);
interest->setCanBePrefix(false);
interest->setApplicationParameters(probetlv::encodeApplicationParameters(std::move(probeInfo)));
@@ -111,7 +105,7 @@
Request::onProbeResponse(const Data& reply, const CaProfile& ca,
std::vector<std::pair<Name, int>>& identityNames, std::vector<Name>& otherCas)
{
- if (!security::verifySignature(reply, *ca.cert)) {
+ if (!ndn::security::verifySignature(reply, *ca.cert)) {
NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
return;
@@ -120,13 +114,14 @@
probetlv::decodeDataContent(reply.getContent(), identityNames, otherCas);
}
-Request::Request(security::KeyChain& keyChain, const CaProfile& profile, RequestType requestType)
- : m_caProfile(profile)
- , m_type(requestType)
- , m_keyChain(keyChain)
-{}
+Request::Request(ndn::KeyChain& keyChain, const CaProfile& profile, RequestType requestType)
+ : m_caProfile(profile)
+ , m_type(requestType)
+ , m_keyChain(keyChain)
+{
+}
-shared_ptr<Interest>
+std::shared_ptr<Interest>
Request::genNewInterest(const Name& newIdentityName,
const time::system_clock::TimePoint& notBefore,
const time::system_clock::TimePoint& notAfter)
@@ -137,7 +132,7 @@
if (newIdentityName.empty()) {
NDN_LOG_TRACE("Randomly create a new name because newIdentityName is empty and the param is empty.");
m_identityName = m_caProfile.caPrefix;
- m_identityName.append(std::to_string(random::generateSecureWord64()));
+ m_identityName.append(ndn::to_string(ndn::random::generateSecureWord64()));
}
else {
m_identityName = newIdentityName;
@@ -145,11 +140,11 @@
// generate a newly key pair or use an existing key
const auto& pib = m_keyChain.getPib();
- security::pib::Identity identity;
+ ndn::security::pib::Identity identity;
try {
identity = pib.getIdentity(m_identityName);
}
- catch (const security::Pib::Error& e) {
+ catch (const ndn::security::Pib::Error&) {
identity = m_keyChain.createIdentity(m_identityName);
m_isNewlyCreatedIdentity = true;
m_isNewlyCreatedKey = true;
@@ -157,19 +152,19 @@
try {
m_keyPair = identity.getDefaultKey();
}
- catch (const security::Pib::Error& e) {
+ catch (const ndn::security::Pib::Error&) {
m_keyPair = m_keyChain.createKey(identity);
m_isNewlyCreatedKey = true;
}
auto& keyName = m_keyPair.getName();
// generate certificate request
- security::Certificate certRequest;
+ Certificate certRequest;
certRequest.setName(Name(keyName).append("cert-request").appendVersion());
certRequest.setContentType(ndn::tlv::ContentType_Key);
certRequest.setContent(m_keyPair.getPublicKey().data(), m_keyPair.getPublicKey().size());
SignatureInfo signatureInfo;
- signatureInfo.setValidityPeriod(security::ValidityPeriod(notBefore, notAfter));
+ signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(notBefore, notAfter));
m_keyChain.sign(certRequest, signingByKey(keyName).setSignatureInfo(signatureInfo));
// generate Interest packet
@@ -186,8 +181,8 @@
return interest;
}
-shared_ptr<Interest>
-Request::genRevokeInterest(const security::Certificate& certificate)
+std::shared_ptr<Interest>
+Request::genRevokeInterest(const Certificate& certificate)
{
if (!m_caProfile.caPrefix.isPrefixOf(certificate.getName())) {
return nullptr;
@@ -206,7 +201,7 @@
std::list<std::string>
Request::onNewRenewRevokeResponse(const Data& reply)
{
- if (!security::verifySignature(reply, *m_caProfile.cert)) {
+ if (!ndn::security::verifySignature(reply, *m_caProfile.cert)) {
NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
}
@@ -238,7 +233,7 @@
return challenge->getRequestedParameterList(m_status, m_challengeStatus);
}
-shared_ptr<Interest>
+std::shared_ptr<Interest>
Request::genChallengeInterest(std::multimap<std::string, std::string>&& parameters)
{
if (m_challengeType == "") {
@@ -269,7 +264,7 @@
void
Request::onChallengeResponse(const Data& reply)
{
- if (!security::verifySignature(reply, *m_caProfile.cert)) {
+ if (!ndn::security::verifySignature(reply, *m_caProfile.cert)) {
NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
}
@@ -277,23 +272,23 @@
challengetlv::decodeDataContent(reply.getContent(), *this);
}
-shared_ptr<Interest>
+std::shared_ptr<Interest>
Request::genCertFetchInterest() const
{
Name interestName = m_issuedCertName;
- auto interest =std::make_shared<Interest>(interestName);
+ auto interest = std::make_shared<Interest>(interestName);
interest->setMustBeFresh(false);
interest->setCanBePrefix(false);
return interest;
}
-shared_ptr<security::Certificate>
+std::shared_ptr<Certificate>
Request::onCertFetchResponse(const Data& reply)
{
try {
- return std::make_shared<security::Certificate>(reply);
+ return std::make_shared<Certificate>(reply);
}
- catch (const std::exception& e) {
+ catch (const std::exception&) {
NDN_LOG_ERROR("Cannot parse replied certificate ");
NDN_THROW(std::runtime_error("Cannot parse replied certificate "));
return nullptr;
@@ -334,4 +329,3 @@
} // namespace requester
} // namespace ndncert
-} // namespace ndn
diff --git a/src/requester-request.hpp b/src/requester-request.hpp
index a1817ea..acd06cc 100644
--- a/src/requester-request.hpp
+++ b/src/requester-request.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,11 +25,12 @@
#include "detail/crypto-helpers.hpp"
#include "detail/profile-storage.hpp"
-namespace ndn {
+#include <ndn-cxx/security/key-chain.hpp>
+
namespace ndncert {
namespace requester {
-class Request : noncopyable
+class Request : boost::noncopyable
{
public:
/**
@@ -38,7 +39,7 @@
* @param caName The name prefix of the CA.
* @return A shared pointer to an Interest ready to be sent.
*/
- static shared_ptr<Interest>
+ static std::shared_ptr<Interest>
genCaProfileDiscoveryInterest(const Name& caName);
/**
@@ -47,7 +48,7 @@
* @param reply The Data packet replied from discovery Interest.
* @return A shared pointer to an Interest ready to be sent.
*/
- static shared_ptr<Interest>
+ static std::shared_ptr<Interest>
genCaProfileInterestFromDiscoveryResponse(const Data& reply);
/**
@@ -85,7 +86,7 @@
* @param probeInfo The requester information to carry to the CA
* @return A shared pointer of to the encoded interest, ready to be sent.
*/
- static shared_ptr<Interest>
+ static std::shared_ptr<Interest>
genProbeInterest(const CaProfile& ca, std::multimap<std::string, std::string>&& probeInfo);
/**
@@ -103,9 +104,8 @@
onProbeResponse(const Data& reply, const CaProfile& ca,
std::vector<std::pair<Name, int>>& identityNames, std::vector<Name>& otherCas);
-
explicit
- Request(security::KeyChain& keyChain, const CaProfile& profile, RequestType requestType);
+ Request(ndn::KeyChain& keyChain, const CaProfile& profile, RequestType requestType);
// NEW/REVOKE/RENEW related helpers
/**
@@ -117,7 +117,7 @@
* @param notAfter The expected notAfter field for the certificate (expiration time)
* @return The shared pointer to the encoded interest.
*/
- shared_ptr<Interest>
+ std::shared_ptr<Interest>
genNewInterest(const Name& newIdentityName,
const time::system_clock::TimePoint& notBefore,
const time::system_clock::TimePoint& notAfter);
@@ -129,8 +129,8 @@
* @param certificate The certificate to the revoked.
* @return The shared pointer to the encoded interest.
*/
- shared_ptr<Interest>
- genRevokeInterest(const security::Certificate& certificate);
+ std::shared_ptr<Interest>
+ genRevokeInterest(const Certificate& certificate);
/**
* @brief Decodes the replied data of NEW, RENEW, or REVOKE interest from the CA.
@@ -164,7 +164,7 @@
* @return The shared pointer to the encoded interest
* @throw std::runtime_error if the challenge is not selected or is not supported.
*/
- shared_ptr<Interest>
+ std::shared_ptr<Interest>
genChallengeInterest(std::multimap<std::string, std::string>&& parameters);
/**
@@ -183,7 +183,7 @@
* @param state, the state of the request.
* @return The shared pointer to the encoded interest
*/
- shared_ptr<Interest>
+ std::shared_ptr<Interest>
genCertFetchInterest() const;
/**
@@ -192,7 +192,7 @@
* @param reply, the data replied from the certificate fetch interest.
* @return The shared pointer to the certificate being fetched.
*/
- static shared_ptr<security::Certificate>
+ static std::shared_ptr<Certificate>
onCertFetchResponse(const Data& reply);
/**
@@ -273,7 +273,7 @@
/**
* @brief The local keychain to generate and install identities, keys and certificates
*/
- security::KeyChain& m_keyChain;
+ ndn::KeyChain& m_keyChain;
/**
* @brief State about how identity/key is generated.
*/
@@ -282,11 +282,10 @@
/**
* @brief The keypair for the request.
*/
- security::Key m_keyPair;
+ ndn::security::Key m_keyPair;
};
} // namespace requester
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_REQUESTER_REQUEST_HPP
diff --git a/tests/database-fixture.hpp b/tests/database-fixture.hpp
index 598e304..53f813e 100644
--- a/tests/database-fixture.hpp
+++ b/tests/database-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -24,9 +24,9 @@
#include "identity-management-fixture.hpp"
#include "unit-test-time-fixture.hpp"
+
#include <boost/filesystem.hpp>
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -58,6 +58,5 @@
} // namespace tests
} // namespace ndncert
-} // namespace ndn
#endif // NDNCERT_TESTS_DATABASE_FIXTURE_HPP
diff --git a/tests/global-configuration.cpp b/tests/global-configuration.cpp
index 61d0cbd..0c92646 100644
--- a/tests/global-configuration.cpp
+++ b/tests/global-configuration.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -18,12 +18,14 @@
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
+#include "detail/ndncert-common.hpp"
+
#include "boost-test.hpp"
+
#include <boost/filesystem.hpp>
#include <fstream>
#include <stdlib.h>
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -36,19 +38,22 @@
if (envHome)
m_home = envHome;
- boost::filesystem::path dir{TMP_TESTS_PATH};
- dir /= "test-home";
- ::setenv("HOME", dir.c_str(), 1);
+ auto testHome = boost::filesystem::path(TMP_TESTS_PATH) / "test-home";
+ if (::setenv("HOME", testHome.c_str(), 1) != 0)
+ NDN_THROW(std::runtime_error("setenv() failed"));
- boost::filesystem::create_directories(dir);
- std::ofstream clientConf((dir / ".ndn" / "client.conf").c_str());
+ boost::filesystem::create_directories(testHome);
+
+ std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str());
clientConf << "pib=pib-sqlite3" << std::endl
<< "tpm=tpm-file" << std::endl;
}
- ~GlobalConfiguration()
+ ~GlobalConfiguration() noexcept
{
- if (!m_home.empty())
+ if (m_home.empty())
+ ::unsetenv("HOME");
+ else
::setenv("HOME", m_home.data(), 1);
}
@@ -66,4 +71,3 @@
} // namespace tests
} // namespace ndncert
-} // namespace ndn
\ No newline at end of file
diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp
index 8ca0545..c4a4590 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/identity-management-fixture.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -20,15 +20,16 @@
*/
#include "identity-management-fixture.hpp"
+
#include <ndn-cxx/security/additional-description.hpp>
#include <ndn-cxx/util/io.hpp>
+
#include <boost/filesystem.hpp>
-namespace ndn {
namespace ndncert {
namespace tests {
-namespace v2 = security::v2;
+using namespace ndn::security;
IdentityManagementBaseFixture::~IdentityManagementBaseFixture()
{
@@ -43,10 +44,10 @@
{
m_certFiles.insert(filename);
try {
- io::save(obj, filename);
+ ndn::io::save(obj, filename);
return true;
}
- catch (const io::Error&) {
+ catch (const ndn::io::Error&) {
return false;
}
}
@@ -56,8 +57,8 @@
{
}
-security::Identity
-IdentityManagementFixture::addIdentity(const Name& identityName, const KeyParams& params)
+Identity
+IdentityManagementFixture::addIdentity(const Name& identityName, const ndn::KeyParams& params)
{
auto identity = m_keyChain.createIdentity(identityName, params);
m_identities.insert(identityName);
@@ -65,32 +66,31 @@
}
bool
-IdentityManagementFixture::saveCertificate(const security::Identity& identity, const std::string& filename)
+IdentityManagementFixture::saveCertificate(const Identity& identity, const std::string& filename)
{
try {
auto cert = identity.getDefaultKey().getDefaultCertificate();
return saveCertToFile(cert, filename);
}
- catch (const security::Pib::Error&) {
+ catch (const Pib::Error&) {
return false;
}
}
-security::Identity
+Identity
IdentityManagementFixture::addSubCertificate(const Name& subIdentityName,
- const security::Identity& issuer, const KeyParams& params)
+ const Identity& issuer, const ndn::KeyParams& params)
{
auto subIdentity = addIdentity(subIdentityName, params);
- v2::Certificate request = subIdentity.getDefaultKey().getDefaultCertificate();
-
+ Certificate request = subIdentity.getDefaultKey().getDefaultCertificate();
request.setName(request.getKeyName().append("parent").appendVersion());
SignatureInfo info;
auto now = time::system_clock::now();
- info.setValidityPeriod(security::ValidityPeriod(now, now + 7300_days));
+ info.setValidityPeriod(ValidityPeriod(now, now + 7300_days));
- v2::AdditionalDescription description;
+ AdditionalDescription description;
description.set("type", "sub-certificate");
info.addCustomTlv(description.wireEncode());
@@ -100,14 +100,14 @@
return subIdentity;
}
-v2::Certificate
-IdentityManagementFixture::addCertificate(const security::Key& key, const std::string& issuer)
+Certificate
+IdentityManagementFixture::addCertificate(const Key& key, const std::string& issuer)
{
Name certificateName = key.getName();
certificateName
.append(issuer)
.appendVersion();
- v2::Certificate certificate;
+ Certificate certificate;
certificate.setName(certificateName);
// set metainfo
@@ -120,7 +120,7 @@
// set signature-info
SignatureInfo info;
auto now = time::system_clock::now();
- info.setValidityPeriod(security::ValidityPeriod(now, now + 10_days));
+ info.setValidityPeriod(ValidityPeriod(now, now + 10_days));
m_keyChain.sign(certificate, signingByKey(key).setSignatureInfo(info));
return certificate;
@@ -128,4 +128,3 @@
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/identity-management-fixture.hpp b/tests/identity-management-fixture.hpp
index 9b10dbf..7856bf9 100644
--- a/tests/identity-management-fixture.hpp
+++ b/tests/identity-management-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,11 +22,11 @@
#ifndef NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
#define NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
+#include "detail/ndncert-common.hpp"
+
#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
-#include <vector>
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -51,6 +51,10 @@
*/
class IdentityManagementFixture : public IdentityManagementBaseFixture
{
+protected:
+ using Identity = ndn::security::Identity;
+ using Key = ndn::security::Key;
+
public:
IdentityManagementFixture();
@@ -58,9 +62,9 @@
* @brief Add identity @p identityName
* @return name of the created self-signed certificate
*/
- security::Identity
+ Identity
addIdentity(const Name& identityName,
- const KeyParams& params = security::KeyChain::getDefaultKeyParams());
+ const ndn::KeyParams& params = ndn::KeyChain::getDefaultKeyParams());
/**
* @brief Save identity certificate to a file
@@ -69,7 +73,7 @@
* @return whether successful
*/
bool
- saveCertificate(const security::Identity& identity, const std::string& filename);
+ saveCertificate(const Identity& identity, const std::string& filename);
/**
* @brief Issue a certificate for \p subIdentityName signed by \p issuer
@@ -80,22 +84,21 @@
*
* @return the sub identity
*/
- security::Identity
- addSubCertificate(const Name& subIdentityName, const security::Identity& issuer,
- const KeyParams& params = security::KeyChain::getDefaultKeyParams());
+ Identity
+ addSubCertificate(const Name& subIdentityName, const Identity& issuer,
+ const ndn::KeyParams& params = ndn::KeyChain::getDefaultKeyParams());
/**
* @brief Add a self-signed certificate to @p key with issuer ID @p issuer
*/
- security::Certificate
- addCertificate(const security::Key& key, const std::string& issuer);
+ Certificate
+ addCertificate(const Key& key, const std::string& issuer);
protected:
- KeyChain m_keyChain;
+ ndn::KeyChain m_keyChain;
};
} // namespace tests
} // namespace ndncert
-} // namespace ndn
#endif // NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
diff --git a/tests/unit-test-time-fixture.hpp b/tests/unit-test-time-fixture.hpp
index cebce38..c497940 100644
--- a/tests/unit-test-time-fixture.hpp
+++ b/tests/unit-test-time-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2020 Regents of the University of California.
+ * Copyright (c) 2013-2021 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,10 +22,12 @@
#ifndef NDN_TESTS_UNIT_UNIT_TEST_TIME_FIXTURE_HPP
#define NDN_TESTS_UNIT_UNIT_TEST_TIME_FIXTURE_HPP
+#include "detail/ndncert-common.hpp"
+
#include <ndn-cxx/util/time-unit-test-clock.hpp>
+
#include <boost/asio/io_service.hpp>
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -35,8 +37,8 @@
{
public:
UnitTestTimeFixture()
- : steadyClock(make_shared<time::UnitTestSteadyClock>())
- , systemClock(make_shared<time::UnitTestSystemClock>())
+ : steadyClock(std::make_shared<time::UnitTestSteadyClock>())
+ , systemClock(std::make_shared<time::UnitTestSystemClock>())
{
time::setCustomClocks(steadyClock, systemClock);
}
@@ -95,13 +97,12 @@
}
public:
- shared_ptr<time::UnitTestSteadyClock> steadyClock;
- shared_ptr<time::UnitTestSystemClock> systemClock;
+ std::shared_ptr<time::UnitTestSteadyClock> steadyClock;
+ std::shared_ptr<time::UnitTestSystemClock> systemClock;
boost::asio::io_service io;
};
} // namespace tests
} // namespace ndncert
-} // namespace ndn
#endif // NDN_TESTS_UNIT_UNIT_TEST_TIME_FIXTURE_HPP
diff --git a/tests/unit-tests/bench.t.cpp b/tests/unit-tests/bench.t.cpp
index 7e321e3..5dbdb3b 100644
--- a/tests/unit-tests/bench.t.cpp
+++ b/tests/unit-tests/bench.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -24,31 +24,28 @@
#include "requester-request.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(TestForBenchmark, IdentityManagementTimeFixture)
+BOOST_FIXTURE_TEST_SUITE(Benchmark, IdentityManagementTimeFixture)
BOOST_AUTO_TEST_CASE(PacketSize0)
{
- name::setConventionEncoding(name::Convention::TYPED);
-
auto identity = addIdentity(Name("/ndn"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ ndn::util::DummyClientFace face(io, m_keyChain, {true, true});
ca::CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
auto profileData = ca.getCaProfileData();
- Interest interest = MetadataObject::makeDiscoveryInterest(Name("/ndn/CA/INFO"));
+ Interest interest = ndn::MetadataObject::makeDiscoveryInterest(Name("/ndn/CA/INFO"));
// std::cout << "CA Config discovery Interest Size: " << interest.wireEncode().size() << std::endl;
- shared_ptr<Interest> infoInterest = nullptr;
+ std::shared_ptr<Interest> infoInterest;
face.setInterestFilter(
- InterestFilter("/ndn/CA/INFO"),
+ ndn::InterestFilter("/ndn/CA/INFO"),
[&](const auto&, const Interest& interest) {
// std::cout << interest.getName() << std::endl;
if (interest.getName() == profileData.getName()) {
@@ -72,7 +69,7 @@
else {
count++;
// std::cout << "CA Config Data Size: " << response.wireEncode().size() << std::endl;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(ndn::security::verifySignature(response, cert));
auto contentBlock = response.getContent();
contentBlock.parse();
auto caItem = infotlv::decodeDataContent(contentBlock);
@@ -97,25 +94,25 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ ndn::util::DummyClientFace face(io, m_keyChain, {true, true});
ca::CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
// generate NEW Interest
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto newInterest = state.genNewInterest(Name("/ndn/alice"),
- time::system_clock::now(),
- time::system_clock::now() + time::days(1));
+ time::system_clock::now(),
+ time::system_clock::now() + time::days(1));
// std::cout << "New Interest Size: " << newInterest->wireEncode().size() << std::endl;
// generate CHALLENGE Interest
- shared_ptr<Interest> challengeInterest = nullptr;
- shared_ptr<Interest> challengeInterest2 = nullptr;
- shared_ptr<Interest> challengeInterest3 = nullptr;
+ std::shared_ptr<Interest> challengeInterest;
+ std::shared_ptr<Interest> challengeInterest2;
+ std::shared_ptr<Interest> challengeInterest3;
int count = 0;
face.onSendData.connect([&](const Data& response) {
@@ -127,7 +124,7 @@
}
else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 0) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(ndn::security::verifySignature(response, cert));
state.onChallengeResponse(response);
BOOST_CHECK(state.m_status == Status::CHALLENGE);
@@ -137,7 +134,7 @@
}
else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 1) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(ndn::security::verifySignature(response, cert));
state.onChallengeResponse(response);
BOOST_CHECK(state.m_status == Status::CHALLENGE);
@@ -153,7 +150,7 @@
else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 2) {
// std::cout << "CHALLENGE Data Size: " << response.wireEncode().size() << std::endl;
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(ndn::security::verifySignature(response, cert));
state.onChallengeResponse(response);
BOOST_CHECK(state.m_status == Status::SUCCESS);
}
@@ -170,8 +167,7 @@
BOOST_CHECK_EQUAL(count, 3);
}
-BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
+BOOST_AUTO_TEST_SUITE_END() // Benchmark
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/ca-memory.t.cpp b/tests/unit-tests/ca-memory.t.cpp
index 290e4ca..fd6f9a5 100644
--- a/tests/unit-tests/ca-memory.t.cpp
+++ b/tests/unit-tests/ca-memory.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -22,7 +22,6 @@
#include "detail/ca-sqlite.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -93,8 +92,7 @@
BOOST_CHECK_EQUAL(allRequests.size(), 1);
}
-BOOST_AUTO_TEST_SUITE_END() // TestCaModule
+BOOST_AUTO_TEST_SUITE_END() // TestCaMemory
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/ca-module.t.cpp b/tests/unit-tests/ca-module.t.cpp
index 385f7ef..d4a733d 100644
--- a/tests/unit-tests/ca-module.t.cpp
+++ b/tests/unit-tests/ca-module.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -26,17 +26,18 @@
#include "requester-request.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
using namespace ca;
+using ndn::util::DummyClientFace;
+using ndn::security::verifySignature;
BOOST_FIXTURE_TEST_SUITE(TestCaModule, DatabaseFixture)
BOOST_AUTO_TEST_CASE(Initialization)
{
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
BOOST_CHECK_EQUAL(ca.getCaConf().caProfile.caPrefix, "/ndn");
@@ -47,22 +48,20 @@
BOOST_AUTO_TEST_CASE(HandleProfileFetching)
{
- name::setConventionEncoding(name::Convention::TYPED);
-
auto identity = addIdentity(Name("/ndn"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
auto profileData = ca.getCaProfileData();
- Interest interest = MetadataObject::makeDiscoveryInterest(Name("/ndn/CA/INFO"));
- shared_ptr<Interest> infoInterest = nullptr;
+ Interest interest = ndn::MetadataObject::makeDiscoveryInterest(Name("/ndn/CA/INFO"));
+ std::shared_ptr<Interest> infoInterest = nullptr;
face.setInterestFilter(
- InterestFilter("/ndn/CA/INFO"),
+ ndn::InterestFilter("/ndn/CA/INFO"),
[&](const auto&, const Interest& interest) {
if (interest.getName() == profileData.getName()) {
face.put(profileData);
@@ -77,12 +76,12 @@
count++;
auto block = response.getContent();
block.parse();
- infoInterest =std::make_shared<Interest>(Name(block.get(ndn::tlv::Name)).appendSegment(0));
+ infoInterest = std::make_shared<Interest>(Name(block.get(ndn::tlv::Name)).appendSegment(0));
infoInterest->setCanBePrefix(false);
}
else {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
auto contentBlock = response.getContent();
contentBlock.parse();
auto caItem = infotlv::decodeDataContent(contentBlock);
@@ -107,16 +106,16 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
Interest interest("/ndn/CA/PROBE");
interest.setCanBePrefix(false);
- Block paramTLV = makeEmptyBlock(ndn::tlv::ApplicationParameters);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, "name"));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "zhiyi"));
+ Block paramTLV = ndn::makeEmptyBlock(ndn::tlv::ApplicationParameters);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, "name"));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi"));
paramTLV.encode();
interest.setApplicationParameters(paramTLV);
@@ -124,7 +123,7 @@
int count = 0;
face.onSendData.connect([&](const Data& response) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
Block contentBlock = response.getContent();
contentBlock.parse();
Block probeResponse = contentBlock.get(tlv::ProbeResponse);
@@ -145,16 +144,16 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
Interest interest("/ndn/CA/PROBE");
interest.setCanBePrefix(false);
- Block paramTLV = makeEmptyBlock(ndn::tlv::ApplicationParameters);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, "name"));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "zhiyi"));
+ Block paramTLV = ndn::makeEmptyBlock(ndn::tlv::ApplicationParameters);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, "name"));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi"));
paramTLV.encode();
interest.setApplicationParameters(paramTLV);
@@ -162,7 +161,7 @@
int count = 0;
face.onSendData.connect([&](const Data& response) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
auto contentBlock = response.getContent();
contentBlock.parse();
auto probeResponseBlock = contentBlock.get(tlv::ProbeResponse);
@@ -183,16 +182,16 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-5", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
Interest interest("/ndn/CA/PROBE");
interest.setCanBePrefix(false);
- Block paramTLV = makeEmptyBlock(ndn::tlv::ApplicationParameters);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, "name"));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "zhiyi"));
+ Block paramTLV = ndn::makeEmptyBlock(ndn::tlv::ApplicationParameters);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, "name"));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi"));
paramTLV.encode();
interest.setApplicationParameters(paramTLV);
@@ -200,7 +199,7 @@
int count = 0;
face.onSendData.connect([&](const Data& response) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
Block contentBlock = response.getContent();
contentBlock.parse();
@@ -212,8 +211,8 @@
}
}
BOOST_CHECK_EQUAL(redirectionItems.size(), 2);
- BOOST_CHECK_EQUAL(security::extractIdentityFromCertName(redirectionItems[0].getPrefix(-1)), "/ndn/site1");
- BOOST_CHECK_EQUAL(security::extractIdentityFromCertName(redirectionItems[1].getPrefix(-1)), "/ndn/site1");
+ BOOST_CHECK_EQUAL(ndn::security::extractIdentityFromCertName(redirectionItems[0].getPrefix(-1)), "/ndn/site1");
+ BOOST_CHECK_EQUAL(ndn::security::extractIdentityFromCertName(redirectionItems[1].getPrefix(-1)), "/ndn/site1");
});
face.receive(interest);
advanceClocks(time::milliseconds(20), 60);
@@ -226,13 +225,13 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto interest = state.genNewInterest(Name("/ndn/zhiyi"),
time::system_clock::now(),
@@ -241,7 +240,7 @@
int count = 0;
face.onSendData.connect([&](const Data& response) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
auto contentBlock = response.getContent();
contentBlock.parse();
@@ -277,13 +276,13 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1");
advanceClocks(time::milliseconds(20), 60);
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto current_tp = time::system_clock::now();
auto interest1 = state.genNewInterest(Name("/ndn/zhiyi"), current_tp, current_tp - time::hours(1));
@@ -308,22 +307,23 @@
auto key = identity.getDefaultKey();
//build expired cert
- security::Certificate cert;
+ Certificate cert;
cert.setName(Name(key.getName()).append("self-sign").appendVersion());
cert.setContentType(ndn::tlv::ContentType_Key);
cert.setContent(key.getPublicKey().data(), key.getPublicKey().size());
SignatureInfo signatureInfo;
- signatureInfo.setValidityPeriod(security::ValidityPeriod(time::system_clock::now() - time::days(1), time::system_clock::now() - time::seconds(1)));
+ signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now() - time::days(1),
+ time::system_clock::now() - time::seconds(1)));
m_keyChain.sign(cert, signingByKey(key.getName()).setSignatureInfo(signatureInfo));
m_keyChain.setDefaultCertificate(key, cert);
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto interest = state.genNewInterest(Name("/ndn/zhiyi"),
time::system_clock::now(),
@@ -349,13 +349,13 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto interest1 = state.genNewInterest(Name("/ndn/a"), time::system_clock::now(),
@@ -374,8 +374,7 @@
}
else {
// should successfully get responses
- BOOST_CHECK_EXCEPTION(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode)), std::runtime_error,
- [](const auto& e) { return true; });
+ BOOST_CHECK_THROW(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode)), std::runtime_error);
}
});
face.receive(*interest1);
@@ -390,13 +389,13 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1");
advanceClocks(time::milliseconds(20), 60);
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto current_tp = time::system_clock::now();
@@ -420,23 +419,23 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ DummyClientFace face(io, m_keyChain, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
// generate NEW Interest
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto newInterest = state.genNewInterest(Name("/ndn/zhiyi"), time::system_clock::now(),
time::system_clock::now() + time::days(1));
// generate CHALLENGE Interest
- shared_ptr<Interest> challengeInterest = nullptr;
- shared_ptr<Interest> challengeInterest2 = nullptr;
- shared_ptr<Interest> challengeInterest3 = nullptr;
+ std::shared_ptr<Interest> challengeInterest;
+ std::shared_ptr<Interest> challengeInterest2;
+ std::shared_ptr<Interest> challengeInterest3;
int count = 0;
face.onSendData.connect([&](const Data& response) {
@@ -447,7 +446,7 @@
}
else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 0) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
state.onChallengeResponse(response);
BOOST_CHECK(state.m_status == Status::CHALLENGE);
@@ -457,7 +456,7 @@
}
else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 1) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
state.onChallengeResponse(response);
BOOST_CHECK(state.m_status == Status::CHALLENGE);
@@ -471,7 +470,7 @@
}
else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 2) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
state.onChallengeResponse(response);
BOOST_CHECK(state.m_status == Status::SUCCESS);
}
@@ -494,21 +493,21 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, {true, true});
+ DummyClientFace face(io, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
//generate a certificate
auto clientIdentity = m_keyChain.createIdentity("/ndn/qwerty");
auto clientKey = clientIdentity.getDefaultKey();
- security::Certificate clientCert;
+ Certificate clientCert;
clientCert.setName(Name(clientKey.getName()).append("cert-request").appendVersion());
clientCert.setContentType(ndn::tlv::ContentType_Key);
clientCert.setFreshnessPeriod(time::hours(24));
clientCert.setContent(clientKey.getPublicKey().data(), clientKey.getPublicKey().size());
SignatureInfo signatureInfo;
- signatureInfo.setValidityPeriod(security::ValidityPeriod(time::system_clock::now(),
- time::system_clock::now() + time::hours(10)));
+ signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now(),
+ time::system_clock::now() + time::hours(10)));
m_keyChain.sign(clientCert, signingByKey(clientKey.getName()).setSignatureInfo(signatureInfo));
RequestId requestId = {{101}};
RequestState certRequest;
@@ -521,7 +520,7 @@
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::REVOKE);
auto interest = state.genRevokeInterest(issuedCert);
@@ -529,7 +528,7 @@
int count = 0;
face.onSendData.connect([&](const Data& response) {
count++;
- BOOST_CHECK(security::verifySignature(response, cert));
+ BOOST_CHECK(verifySignature(response, cert));
auto contentBlock = response.getContent();
contentBlock.parse();
@@ -565,26 +564,26 @@
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- util::DummyClientFace face(io, {true, true});
+ DummyClientFace face(io, {true, true});
CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
advanceClocks(time::milliseconds(20), 60);
// generate a certificate
auto clientIdentity = m_keyChain.createIdentity("/ndn/qwerty");
auto clientKey = clientIdentity.getDefaultKey();
- security::Certificate clientCert;
- clientCert.setName(Name(clientKey.getName()).append("NDNCERT").append(std::to_string(1473283247810732701)));
+ Certificate clientCert;
+ clientCert.setName(Name(clientKey.getName()).append("NDNCERT").append("1473283247810732701"));
clientCert.setContentType(ndn::tlv::ContentType_Key);
clientCert.setFreshnessPeriod(time::hours(24));
clientCert.setContent(clientKey.getPublicKey().data(), clientKey.getPublicKey().size());
SignatureInfo signatureInfo;
- signatureInfo.setValidityPeriod(security::ValidityPeriod(time::system_clock::now(),
- time::system_clock::now() + time::hours(10)));
+ signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now(),
+ time::system_clock::now() + time::hours(10)));
m_keyChain.sign(clientCert, signingByKey(clientKey.getName()).setSignatureInfo(signatureInfo));
CaProfile item;
item.caPrefix = Name("/ndn");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
requester::Request state(m_keyChain, item, RequestType::NEW);
auto interest = state.genRevokeInterest(clientCert);
@@ -602,8 +601,7 @@
BOOST_CHECK_EQUAL(receiveData, true);
}
-BOOST_AUTO_TEST_SUITE_END() // TestCaModule
+BOOST_AUTO_TEST_SUITE_END() // TestCaModule
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/ca-sqlite.t.cpp b/tests/unit-tests/ca-sqlite.t.cpp
index 78077db..c592d47 100644
--- a/tests/unit-tests/ca-sqlite.t.cpp
+++ b/tests/unit-tests/ca-sqlite.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -21,7 +21,6 @@
#include "detail/ca-sqlite.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -130,8 +129,7 @@
BOOST_CHECK_THROW(storage.addRequest(request1), std::runtime_error);
}
-BOOST_AUTO_TEST_SUITE_END() // TestCaModule
+BOOST_AUTO_TEST_SUITE_END() // TestCaSqlite
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/challenge-email.t.cpp b/tests/unit-tests/challenge-email.t.cpp
index 8ee9be9..92fb45b 100644
--- a/tests/unit-tests/challenge-email.t.cpp
+++ b/tests/unit-tests/challenge-email.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -21,7 +21,6 @@
#include "challenge/challenge-email.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -52,9 +51,9 @@
request.requestType = RequestType::NEW;
request.cert = cert;
- Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_EMAIL));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "zhiyi@cs.ucla.edu"));
+ Block paramTLV = ndn::makeEmptyBlock(tlv::EncryptedPayload);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_EMAIL));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi@cs.ucla.edu"));
ChallengeEmail challenge("./tests/unit-tests/test-send-email.sh");
challenge.handleChallengeRequest(paramTLV, request);
@@ -106,9 +105,9 @@
request.requestType = RequestType::NEW;
request.cert = cert;
- Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_EMAIL));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "zhiyi@cs"));
+ Block paramTLV = ndn::makeEmptyBlock(tlv::EncryptedPayload);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_EMAIL));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi@cs"));
ChallengeEmail challenge;
challenge.handleChallengeRequest(paramTLV, request);
@@ -136,9 +135,9 @@
request.challengeState = ca::ChallengeState(ChallengeEmail::NEED_CODE, time::system_clock::now(),
3, time::seconds(3600), std::move(secret));
- Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "4567"));
+ Block paramTLV = ndn::makeEmptyBlock(tlv::EncryptedPayload);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "4567"));
ChallengeEmail challenge;
challenge.handleChallengeRequest(paramTLV, request);
@@ -165,9 +164,9 @@
request.challengeState = ca::ChallengeState(ChallengeEmail::NEED_CODE, time::system_clock::now(),
3, time::seconds(3600), std::move(secret));
- Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "7890"));
+ Block paramTLV = ndn::makeEmptyBlock(tlv::EncryptedPayload);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "7890"));
ChallengeEmail challenge;
challenge.handleChallengeRequest(paramTLV, request);
@@ -177,8 +176,7 @@
BOOST_CHECK_EQUAL(request.challengeState->secrets.empty(), false);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestChallengeEmail
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/challenge-pin.t.cpp b/tests/unit-tests/challenge-pin.t.cpp
index 61167d0..b835089 100644
--- a/tests/unit-tests/challenge-pin.t.cpp
+++ b/tests/unit-tests/challenge-pin.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -21,7 +21,6 @@
#include "challenge/challenge-pin.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -46,7 +45,7 @@
request.cert = cert;
ChallengePin challenge;
- challenge.handleChallengeRequest(makeEmptyBlock(tlv::EncryptedPayload), request);
+ challenge.handleChallengeRequest(ndn::makeEmptyBlock(tlv::EncryptedPayload), request);
BOOST_CHECK(request.status == Status::CHALLENGE);
BOOST_CHECK_EQUAL(request.challengeState->challengeStatus, ChallengePin::NEED_CODE);
@@ -71,9 +70,9 @@
request.challengeState = ca::ChallengeState(ChallengePin::NEED_CODE, time::system_clock::now(),
3, time::seconds(3600), std::move(secret));
- Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "12345"));
+ Block paramTLV = ndn::makeEmptyBlock(tlv::EncryptedPayload);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "12345"));
ChallengePin challenge;
challenge.handleChallengeRequest(paramTLV, request);
@@ -100,9 +99,9 @@
request.challengeState = ca::ChallengeState(ChallengePin::NEED_CODE, time::system_clock::now(),
3, time::seconds(3600), std::move(secret));
- Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
- paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
- paramTLV.push_back(makeStringBlock(tlv::ParameterValue, "45678"));
+ Block paramTLV = ndn::makeEmptyBlock(tlv::EncryptedPayload);
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
+ paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "45678"));
ChallengePin challenge;
challenge.handleChallengeRequest(paramTLV, request);
@@ -112,8 +111,7 @@
BOOST_CHECK_EQUAL(request.challengeState->secrets.empty(), false);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestChallengePin
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/challenge-possession.t.cpp b/tests/unit-tests/challenge-possession.t.cpp
index 84d05d5..2c76c3d 100644
--- a/tests/unit-tests/challenge-possession.t.cpp
+++ b/tests/unit-tests/challenge-possession.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,14 +19,13 @@
*/
#include "challenge/challenge-possession.hpp"
-#include "test-common.hpp"
#include "detail/challenge-encoder.hpp"
+#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
-BOOST_FIXTURE_TEST_SUITE(TestChallengeCredential, IdentityManagementFixture)
+BOOST_FIXTURE_TEST_SUITE(TestChallengePossession, IdentityManagementFixture)
BOOST_AUTO_TEST_CASE(LoadConfig)
{
@@ -65,12 +64,12 @@
auto identityB = addIdentity(Name("/trust/cert"));
auto keyB = identityB.getDefaultKey();
auto credentialName = Name(keyB.getName()).append("Credential").appendVersion();
- security::Certificate credential;
+ Certificate credential;
credential.setName(credentialName);
credential.setContent(keyB.getPublicKey().data(), keyB.getPublicKey().size());
SignatureInfo signatureInfo;
- signatureInfo.setValidityPeriod(security::ValidityPeriod(time::system_clock::now(), time::system_clock::now() +
- time::minutes(1)));
+ signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now(),
+ time::system_clock::now() + time::minutes(1)));
m_keyChain.sign(credential, signingByCertificate(trustAnchor).setSignatureInfo(signatureInfo));
m_keyChain.addCertificate(keyB, credential);
@@ -83,7 +82,7 @@
BOOST_CHECK_EQUAL(state.challengeState->challengeStatus, "need-proof");
// reply from server
- auto nonceBuf = fromHex(state.challengeState->secrets.get("nonce", ""));
+ auto nonceBuf = ndn::fromHex(state.challengeState->secrets.get("nonce", ""));
std::array<uint8_t, 16> nonce{};
memcpy(nonce.data(), nonceBuf->data(), 16);
auto params2 = challenge.getRequestedParameterList(state.status, state.challengeState->challengeStatus);
@@ -118,12 +117,12 @@
auto identityB = addIdentity(Name("/trust/cert"));
auto keyB = identityB.getDefaultKey();
auto credentialName = Name(keyB.getName()).append("Credential").appendVersion();
- security::Certificate credential;
+ Certificate credential;
credential.setName(credentialName);
credential.setContent(keyB.getPublicKey().data(), keyB.getPublicKey().size());
SignatureInfo signatureInfo;
- signatureInfo.setValidityPeriod(security::ValidityPeriod(time::system_clock::now(), time::system_clock::now() +
- time::minutes(1)));
+ signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now(),
+ time::system_clock::now() + time::minutes(1)));
m_keyChain.sign(credential, signingByCertificate(trustAnchor).setSignatureInfo(signatureInfo));
m_keyChain.addCertificate(keyB, credential);
@@ -144,8 +143,7 @@
BOOST_CHECK_EQUAL(statusToString(state.status), statusToString(Status::FAILURE));
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestChallengePossession
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/configuration.t.cpp b/tests/unit-tests/configuration.t.cpp
index 20748d9..f7a8bc5 100644
--- a/tests/unit-tests/configuration.t.cpp
+++ b/tests/unit-tests/configuration.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,13 +23,12 @@
#include "detail/info-encoder.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
BOOST_FIXTURE_TEST_SUITE(TestConfig, IdentityManagementFixture)
-BOOST_AUTO_TEST_CASE(CAConfigFile)
+BOOST_AUTO_TEST_CASE(CaConfigFile)
{
ca::CaConfig config;
config.load("tests/unit-tests/config-files/config-ca-1");
@@ -73,7 +72,7 @@
BOOST_CHECK_EQUAL(names[2].size(), 1);
}
-BOOST_AUTO_TEST_CASE(CAConfigFileWithErrors)
+BOOST_AUTO_TEST_CASE(CaConfigFileWithErrors)
{
ca::CaConfig config;
// nonexistent file
@@ -143,8 +142,7 @@
BOOST_CHECK_EQUAL(lastItem.caPrefix, "/ndn/edu/ucla/zhiyi");
}
-BOOST_AUTO_TEST_SUITE_END() // TestCaConfig
+BOOST_AUTO_TEST_SUITE_END() // TestConfig
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/crypto-helpers.t.cpp b/tests/unit-tests/crypto-helpers.t.cpp
index 9025da0..008a2f6 100644
--- a/tests/unit-tests/crypto-helpers.t.cpp
+++ b/tests/unit-tests/crypto-helpers.t.cpp
@@ -21,7 +21,6 @@
#include "detail/crypto-helpers.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -281,7 +280,7 @@
(uint8_t*)associatedData.c_str(), associatedData.size(), encryptionIv);
block.parse();
auto ivBlock = block.get(tlv::InitializationVector);
- Buffer ivBuf(ivBlock.value(), ivBlock.value_size());
+ ndn::Buffer ivBuf(ivBlock.value(), ivBlock.value_size());
BOOST_CHECK_EQUAL(ivBuf.size(), 12);
BOOST_CHECK_EQUAL(loadBigU32(&encryptionIv[8]), 6);
BOOST_CHECK_EQUAL(loadBigU32(&ivBuf[8]), 0);
@@ -290,7 +289,7 @@
(uint8_t*)associatedData.c_str(), associatedData.size(), encryptionIv);
block.parse();
ivBlock = block.get(tlv::InitializationVector);
- Buffer ivBuf2(ivBlock.value(), ivBlock.value_size());
+ ndn::Buffer ivBuf2(ivBlock.value(), ivBlock.value_size());
BOOST_CHECK_EQUAL(std::memcmp(ivBuf2.data(), encryptionIv.data(), 8), 0);
}
@@ -338,8 +337,7 @@
std::runtime_error);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestCryptoHelpers
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/name-assignment.t.cpp b/tests/unit-tests/name-assignment.t.cpp
index 425e513..94b7fef 100644
--- a/tests/unit-tests/name-assignment.t.cpp
+++ b/tests/unit-tests/name-assignment.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -23,11 +23,11 @@
#include "name-assignment/assignment-hash.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
BOOST_AUTO_TEST_SUITE(TestNameAssignment)
+
BOOST_AUTO_TEST_CASE(NameAssignmentRandom)
{
AssignmentRandom assignment;
@@ -68,10 +68,7 @@
BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2);
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestNameAssignment
} // namespace tests
} // namespace ndncert
-} // namespace ndn
-
-
diff --git a/tests/unit-tests/protocol-encoders.t.cpp b/tests/unit-tests/protocol-encoders.t.cpp
index 61128e3..bc1daa0 100644
--- a/tests/unit-tests/protocol-encoders.t.cpp
+++ b/tests/unit-tests/protocol-encoders.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,9 +25,7 @@
#include "detail/probe-encoder.hpp"
#include "detail/ca-configuration.hpp"
#include "test-common.hpp"
-#include "identity-management-fixture.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -108,7 +106,7 @@
std::vector<uint8_t> pub = ECDHState().getSelfPubKey();
auto b = requesttlv::encodeApplicationParameters(RequestType::REVOKE, pub, *certRequest);
std::vector<uint8_t> returnedPub;
- std::shared_ptr<security::Certificate> returnedCert;
+ std::shared_ptr<Certificate> returnedCert;
requesttlv::decodeApplicationParameters(b, RequestType::REVOKE, returnedPub, returnedCert);
BOOST_CHECK_EQUAL(returnedPub.size(), pub.size());
@@ -143,7 +141,7 @@
0xe0, 0xff, 0x56, 0x83, 0xf2, 0x43, 0xb2, 0x13};
requester::ProfileStorage caCache;
caCache.load("tests/unit-tests/config-files/config-client-1");
- security::Certificate certRequest = *caCache.getKnownProfiles().front().cert;
+ auto certRequest = *caCache.getKnownProfiles().front().cert;
RequestId id = {{102}};
ca::RequestState state;
state.caPrefix = Name("/ndn/ucla");
@@ -170,8 +168,7 @@
BOOST_CHECK_EQUAL(context.m_issuedCertName, "/ndn/ucla/a/b/c");
}
-BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_SUITE_END() // TestProtocolEncoding
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tests/unit-tests/requester.t.cpp b/tests/unit-tests/requester.t.cpp
index 1f07a3f..d2833c4 100644
--- a/tests/unit-tests/requester.t.cpp
+++ b/tests/unit-tests/requester.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -25,7 +25,6 @@
#include "ca-module.hpp"
#include "test-common.hpp"
-namespace ndn {
namespace ndncert {
namespace tests {
@@ -33,7 +32,6 @@
BOOST_FIXTURE_TEST_SUITE(TestRequester, IdentityManagementTimeFixture)
-/* PROBE */
BOOST_AUTO_TEST_CASE(GenProbeInterest)
{
auto identity = addIdentity(Name("/site"));
@@ -45,7 +43,7 @@
ca_profile.probeParameterKeys.push_back("uid");
ca_profile.probeParameterKeys.push_back("name");
ca_profile.caPrefix = Name("/site");
- ca_profile.cert = std::make_shared<security::Certificate>(cert);
+ ca_profile.cert = std::make_shared<Certificate>(cert);
std::multimap<std::string, std::string> probeParams;
probeParams.emplace("email", "zhiyi@cs.ucla.edu");
@@ -69,20 +67,20 @@
ca_profile.probeParameterKeys.push_back("uid");
ca_profile.probeParameterKeys.push_back("name");
ca_profile.caPrefix = Name("/site");
- ca_profile.cert = std::make_shared<security::Certificate>(cert);
+ ca_profile.cert = std::make_shared<Certificate>(cert);
std::vector<Name> availableNames;
availableNames.push_back(Name("/site1"));
availableNames.push_back(Name("/site2"));
- util::DummyClientFace face(io, m_keyChain, {true, true});
+ ndn::util::DummyClientFace face(io, m_keyChain, {true, true});
ca::CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-5", "ca-storage-memory");
Data reply;
reply.setName(Name("/site/CA/PROBE"));
reply.setFreshnessPeriod(time::seconds(100));
reply.setContent(probetlv::encodeDataContent(availableNames, 3, ca.m_config.redirection));
- m_keyChain.sign(reply, signingByIdentity(identity));
+ m_keyChain.sign(reply, ndn::signingByIdentity(identity));
std::vector<std::pair<Name, int>> names;
std::vector<Name> redirects;
@@ -96,8 +94,8 @@
BOOST_CHECK_EQUAL(names[1].second, 3);
BOOST_CHECK_EQUAL(redirects.size(), 2);
- BOOST_CHECK_EQUAL(security::extractIdentityFromCertName(redirects[0].getPrefix(-1)), "/ndn/site1");
- BOOST_CHECK_EQUAL(security::extractIdentityFromCertName(redirects[1].getPrefix(-1)), "/ndn/site1");
+ BOOST_CHECK_EQUAL(ndn::security::extractIdentityFromCertName(redirects[0].getPrefix(-1)), "/ndn/site1");
+ BOOST_CHECK_EQUAL(ndn::security::extractIdentityFromCertName(redirects[1].getPrefix(-1)), "/ndn/site1");
}
BOOST_AUTO_TEST_CASE(ErrorHandling)
@@ -108,14 +106,14 @@
CaProfile item;
item.caPrefix = Name("/site");
- item.cert = std::make_shared<security::Certificate>(cert);
+ item.cert = std::make_shared<Certificate>(cert);
Request state(m_keyChain, item, RequestType::NEW);
Data errorPacket;
errorPacket.setName(Name("/site/pretend/this/is/error/packet"));
errorPacket.setFreshnessPeriod(time::seconds(100));
errorPacket.setContent(errortlv::encodeDataContent(ErrorCode::INVALID_PARAMETER, "This is a test."));
- m_keyChain.sign(errorPacket, signingByIdentity(identity));
+ m_keyChain.sign(errorPacket, ndn::signingByIdentity(identity));
std::vector<std::pair<Name, int>> ids;
std::vector<Name> cas;
@@ -128,4 +126,3 @@
} // namespace tests
} // namespace ndncert
-} // namespace ndn
diff --git a/tools/ndncert-ca-server.cpp b/tools/ndncert-ca-server.cpp
index 697960f..5f0e3a3 100644
--- a/tools/ndncert-ca-server.cpp
+++ b/tools/ndncert-ca-server.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2020, Regents of the University of California.
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -19,6 +19,7 @@
*/
#include "ca-module.hpp"
+
#include <boost/asio.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/program_options/options_description.hpp>
@@ -27,17 +28,17 @@
#include <iostream>
#include <chrono>
#include <deque>
+
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/security/key-chain.hpp>
-namespace ndn {
namespace ndncert {
namespace ca {
-Face face;
-security::KeyChain keyChain;
-std::string repoHost = "localhost";
-std::string repoPort = "7376";
+static ndn::Face face;
+static ndn::KeyChain keyChain;
+static std::string repoHost = "localhost";
+static std::string repoPort = "7376";
const size_t MAX_CACHED_CERT_NUM = 100;
static bool
@@ -141,8 +142,8 @@
}
});
face.setInterestFilter(
- InterestFilter(ca.getCaConf().caProfile.caPrefix),
- [&](const InterestFilter&, const Interest& interest) {
+ ndn::InterestFilter(ca.getCaConf().caProfile.caPrefix),
+ [&](const auto&, const auto& interest) {
const auto& interestName = interest.getName();
if (interestName.isPrefixOf(profileData.getName())) {
face.put(profileData);
@@ -166,10 +167,9 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
int
main(int argc, char* argv[])
{
- return ndn::ndncert::ca::main(argc, argv);
+ return ndncert::ca::main(argc, argv);
}
diff --git a/tools/ndncert-ca-status.cpp b/tools/ndncert-ca-status.cpp
index 0db2353..2d0c0f9 100644
--- a/tools/ndncert-ca-status.cpp
+++ b/tools/ndncert-ca-status.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
+/*
+ * Copyright (c) 2017-2021, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -20,16 +20,17 @@
#include "ca-module.hpp"
#include "detail/ca-sqlite.hpp"
-#include <iostream>
+
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>
-namespace ndn {
+#include <iostream>
+
namespace ndncert {
namespace ca {
-int
+static int
main(int argc, char* argv[])
{
namespace po = boost::program_options;
@@ -75,10 +76,9 @@
} // namespace ca
} // namespace ndncert
-} // namespace ndn
int
main(int argc, char* argv[])
{
- return ndn::ndncert::ca::main(argc, argv);
+ return ndncert::ca::main(argc, argv);
}
diff --git a/tools/ndncert-client.cpp b/tools/ndncert-client.cpp
index fec4aa1..30c7454 100644
--- a/tools/ndncert-client.cpp
+++ b/tools/ndncert-client.cpp
@@ -20,6 +20,8 @@
#include "requester-request.hpp"
+#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/security/key-chain.hpp>
#include <ndn-cxx/security/verification-helpers.hpp>
#include <boost/asio.hpp>
@@ -29,7 +31,6 @@
#include <iostream>
-namespace ndn {
namespace ndncert {
namespace requester {
@@ -46,9 +47,9 @@
runChallenge(const std::string& challengeType);
static size_t nStep = 1;
-static Face face;
-static security::KeyChain keyChain;
-static shared_ptr<Request> requesterState;
+static ndn::Face face;
+static ndn::KeyChain keyChain;
+static std::shared_ptr<Request> requesterState;
static void
captureParams(std::multimap<std::string, std::string>& requirement)
@@ -92,7 +93,7 @@
try {
return std::stoul(periodStr);
}
- catch (const std::exception& e) {
+ catch (const std::exception&) {
std::cerr << "Your input is invalid. Try again: " << std::endl;
count++;
}
@@ -183,7 +184,7 @@
try {
challengeIndex = std::stoul(choice);
}
- catch (const std::exception& e) {
+ catch (const std::exception&) {
std::cerr << "Your input is not valid. Try again:" << std::endl;
inputCount++;
continue;
@@ -262,7 +263,8 @@
std::cerr << "\nOr choose another trusted CA suggested by the CA: " << std::endl;
for (const auto& redirect : redirects) {
std::cerr << "> Index: " << count++ << std::endl
- << ">> Suggested CA: " << security::extractIdentityFromCertName(redirect.getPrefix(-1)) << std::endl;
+ << ">> Suggested CA: " << ndn::security::extractIdentityFromCertName(redirect.getPrefix(-1))
+ << std::endl;
}
std::cerr << "Please type in the index of your choice:" << std::endl;
size_t index = 0;
@@ -271,7 +273,7 @@
getline(std::cin, input);
index = std::stoul(input);
}
- catch (const std::exception& e) {
+ catch (const std::exception&) {
std::cerr << "Your input is Invalid. Exit" << std::endl;
exit(1);
}
@@ -293,7 +295,7 @@
std::cerr << "You are applying name: " << selectedName.toUri() << std::endl;
}
}
- catch (const std::exception& e) {
+ catch (const std::exception&) {
std::cerr << "Your input is Invalid. Exit" << std::endl;
exit(1);
}
@@ -302,7 +304,7 @@
else {
//redirects
auto redirectedCaFullName = redirects[index - names.size()];
- auto redirectedCaName = security::extractIdentityFromCertName(redirectedCaFullName.getPrefix(-1));
+ auto redirectedCaName = ndn::security::extractIdentityFromCertName(redirectedCaFullName.getPrefix(-1));
std::cerr << "You selected to be redirected to CA: " << redirectedCaName.toUri() << std::endl;
face.expressInterest(
*Request::genCaProfileDiscoveryInterest(redirectedCaName),
@@ -365,7 +367,7 @@
try {
caIndex = std::stoul(caIndexS);
}
- catch (const std::exception& e) {
+ catch (const std::exception&) {
std::cerr << "Your input is neither NONE nor a valid index. Exit" << std::endl;
return;
}
@@ -532,10 +534,9 @@
} // namespace requester
} // namespace ndncert
-} // namespace ndn
int
main(int argc, char* argv[])
{
- return ndn::ndncert::requester::main(argc, argv);
+ return ndncert::requester::main(argc, argv);
}