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