Skip to content

Commit

Permalink
Avoid deprecated ndn-cxx functions
Browse files Browse the repository at this point in the history
Change-Id: I039306cf97a85ee28969651198823a5878b28ed3
  • Loading branch information
Pesa committed Apr 25, 2023
1 parent 6a625d8 commit f48e163
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/ca-module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ CaModule::onNewRenewRevoke(const Interest& request, RequestType requestType)
uint8_t requestIdData[32];
Block certNameTlv = clientCert->getName().wireEncode();
try {
hmacSha256(certNameTlv.wire(), certNameTlv.size(), m_requestIdGenKey, 32, requestIdData);
hmacSha256(certNameTlv.data(), certNameTlv.size(), m_requestIdGenKey, 32, requestIdData);
}
catch (const std::runtime_error& e) {
NDN_LOG_ERROR("Error computing the request ID: " << std::string(e.what()));
NDN_LOG_ERROR("Error computing the request ID: " << e.what());
m_face.put(generateErrorDataPacket(request.getName(), ErrorCode::INVALID_PARAMETER,
"Error computing the request ID."));
return;
Expand Down
18 changes: 7 additions & 11 deletions src/challenge/challenge-possession.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2023, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand Down Expand Up @@ -38,7 +38,7 @@ const std::string ChallengePossession::PARAMETER_KEY_PROOF = "proof";
const std::string ChallengePossession::NEED_PROOF = "need-proof";

ChallengePossession::ChallengePossession(const std::string& configPath)
: ChallengeModule("Possession", 1, time::seconds(60))
: ChallengeModule("Possession", 1, time::seconds(60))
{
if (configPath.empty()) {
m_configFile = std::string(NDNCERT_SYSCONFDIR) + "/ndncert/challenge-credential.conf";
Expand Down Expand Up @@ -112,7 +112,6 @@ ChallengePossession::handleChallengeRequest(const Block& params, ca::RequestStat
// 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
if (!credential.hasContent() || signatureLen != 0) {
Expand All @@ -133,10 +132,9 @@ ChallengePossession::handleChallengeRequest(const Block& params, ca::RequestStat
std::array<uint8_t, 16> secretCode{};
ndn::random::generateSecureBytes(secretCode);
JsonSection secretJson;
secretJson.add(PARAMETER_KEY_NONCE, toHex(secretCode));
const auto& credBlock = credential.wireEncode();
secretJson.add(PARAMETER_KEY_CREDENTIAL_CERT, toHex({credBlock.wire(), credBlock.size()}));
NDN_LOG_TRACE("Secret for request " << toHex(request.requestId) << " : " << toHex(secretCode));
secretJson.add(PARAMETER_KEY_NONCE, ndn::toHex(secretCode));
secretJson.add(PARAMETER_KEY_CREDENTIAL_CERT, ndn::toHex(credential.wireEncode()));
NDN_LOG_TRACE("Secret for request " << ndn::toHex(request.requestId) << " : " << ndn::toHex(secretCode));
return returnWithNewChallengeStatus(request, NEED_PROOF, std::move(secretJson), m_maxAttemptTimes, m_secretLifetime);
}
else if (request.challengeState && request.challengeState->challengeStatus == NEED_PROOF) {
Expand Down Expand Up @@ -210,9 +208,7 @@ ChallengePossession::genChallengeRequestTLV(Status status, const std::string& ch
for (const auto& item : params) {
if (std::get<0>(item) == PARAMETER_KEY_PROOF) {
request.push_back(ndn::makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_PROOF));
auto& sigTlvStr = std::get<1>(item);
auto valueBlock = ndn::makeBinaryBlock(tlv::ParameterValue, sigTlvStr.data(), sigTlvStr.size());
request.push_back(valueBlock);
request.push_back(ndn::makeStringBlock(tlv::ParameterValue, std::get<1>(item)));
}
else {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
Expand All @@ -239,7 +235,7 @@ ChallengePossession::fulfillParameters(std::multimap<std::string, std::string>&

for (auto& [key, val] : params) {
if (key == PARAMETER_KEY_CREDENTIAL_CERT) {
val = std::string(reinterpret_cast<const char*>(issuedCertTlv.wire()), issuedCertTlv.size());
val = std::string(reinterpret_cast<const char*>(issuedCertTlv.data()), issuedCertTlv.size());
}
else if (key == PARAMETER_KEY_PROOF) {
val = std::string(signature->get<char>(), signature->size());
Expand Down
12 changes: 6 additions & 6 deletions tools/ndncert-ca-server.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2017-2022, Regents of the University of California.
* Copyright (c) 2017-2023, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
Expand Down Expand Up @@ -39,24 +39,24 @@ 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;
constexpr size_t MAX_CACHED_CERT_NUM = 100;

static bool
writeDataToRepo(const Data& data)
{
boost::asio::ip::tcp::iostream requestStream;
#if BOOST_VERSION >= 106600
requestStream.expires_after(std::chrono::seconds(3));
requestStream.expires_after(std::chrono::seconds(5));
#else
requestStream.expires_from_now(boost::posix_time::seconds(3));
#endif //BOOST_VERSION >= 106600
requestStream.expires_from_now(boost::posix_time::seconds(5));
#endif // BOOST_VERSION >= 106600
requestStream.connect(repoHost, repoPort);
if (!requestStream) {
std::cerr << "ERROR: Cannot publish the certificate to repo-ng"
<< " (" << requestStream.error().message() << ")" << std::endl;
return false;
}
requestStream.write(reinterpret_cast<const char*>(data.wireEncode().wire()),
requestStream.write(reinterpret_cast<const char*>(data.wireEncode().data()),
data.wireEncode().size());
return true;
}
Expand Down

0 comments on commit f48e163

Please sign in to comment.