Fix build against current ndn-cxx
Change-Id: I9f2e06204ee190d507c76aac7ead09ad8e4d5009
diff --git a/src/challenge/challenge-possession.cpp b/src/challenge/challenge-possession.cpp
index 73a0c29..ef93d25 100644
--- a/src/challenge/challenge-possession.cpp
+++ b/src/challenge/challenge-possession.cpp
@@ -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.
*
@@ -18,12 +18,15 @@
*/
#include "challenge-possession.hpp"
-#include <ndn-cxx/security/verification-helpers.hpp>
+
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/transform/public-key.hpp>
+#include <ndn-cxx/security/verification-helpers.hpp>
#include <ndn-cxx/util/io.hpp>
#include <ndn-cxx/util/random.hpp>
+#include <boost/property_tree/json_parser.hpp>
+
namespace ndn {
namespace ndncert {
@@ -53,9 +56,9 @@
try {
boost::property_tree::read_json(m_configFile, config);
}
- catch (const boost::property_tree::info_parser_error& error) {
- NDN_THROW(std::runtime_error("Failed to parse configuration file " + m_configFile +
- " " + error.message() + " line " + std::to_string(error.line())));
+ 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())));
}
if (config.begin() == config.end()) {
@@ -96,7 +99,8 @@
}
catch (const std::exception& e) {
NDN_LOG_ERROR("Cannot load challenge parameter: credential " << e.what());
- return returnWithError(request, ErrorCode::INVALID_PARAMETER, "Cannot challenge credential: credential." + std::string(e.what()));
+ return returnWithError(request, ErrorCode::INVALID_PARAMETER,
+ "Cannot challenge credential: credential."s + e.what());
}
}
else if (readString(elements[i]) == PARAMETER_KEY_PROOF) {
@@ -114,7 +118,7 @@
if (credential.hasContent() && signatureLen == 0) {
Name signingKeyName = credential.getSignatureInfo().getKeyLocator().getName();
security::transform::PublicKey key;
- const auto &pubKeyBuffer = credential.getPublicKey();
+ const auto& pubKeyBuffer = credential.getPublicKey();
key.loadPkcs8(pubKeyBuffer.data(), pubKeyBuffer.size());
for (auto anchor : m_trustAnchors) {
if (anchor.getKeyName() == signingKeyName) {
@@ -123,8 +127,9 @@
}
}
}
- } else {
- return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
+ }
+ else {
+ return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
}
if (!checkOK) {
return returnWithError(request, ErrorCode::INVALID_PARAMETER, "Certificate cannot be verified");
@@ -140,11 +145,12 @@
NDN_LOG_TRACE("Secret for request " << toHex(request.requestId.data(), request.requestId.size())
<< " : " << toHex(secretCode.data(), 16));
return returnWithNewChallengeStatus(request, NEED_PROOF, std::move(secretJson), m_maxAttemptTimes, m_secretLifetime);
- } else if (request.challengeState && request.challengeState->challengeStatus == NEED_PROOF) {
+ }
+ else if (request.challengeState && request.challengeState->challengeStatus == NEED_PROOF) {
NDN_LOG_TRACE("Challenge Interest (proof) arrives. Check the proof");
//check the format and load credential
if (credential.hasContent() || signatureLen == 0) {
- return returnWithError(request, ErrorCode::BAD_INTEREST_FORMAT, "Cannot find certificate");
+ 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, ""));
@@ -153,11 +159,11 @@
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 (security::verifySignature({{secretCode.data(), secretCode.size()}}, signature, signatureLen, key)) {
return returnWithSuccess(request);
}
return returnWithError(request, ErrorCode::INVALID_PARAMETER,
- "Cannot verify the proof of private key against credential.");
+ "Cannot verify the proof of private key against credential.");
}
NDN_LOG_TRACE("Proof of possession: bad state");
return returnWithError(request, ErrorCode::INVALID_PARAMETER, "Fail to recognize the request.");
@@ -171,12 +177,13 @@
if (status == Status::BEFORE_CHALLENGE) {
result.emplace(PARAMETER_KEY_CREDENTIAL_CERT, "Please provide the certificate issued by a trusted CA.");
return result;
- } else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF) {
+ }
+ else if (status == Status::CHALLENGE && challengeStatus == NEED_PROOF) {
result.emplace(PARAMETER_KEY_PROOF, "Please sign a Data packet with request ID as the content.");
- } else {
+ }
+ else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
}
-
return result;
}
@@ -195,29 +202,33 @@
request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_CREDENTIAL_CERT));
Block valueBlock(tlv::ParameterValue);
auto& certTlvStr = std::get<1>(item);
- valueBlock.push_back(Block((uint8_t*)certTlvStr.c_str(), certTlvStr.size()));
+ valueBlock.push_back(Block(reinterpret_cast<const uint8_t*>(certTlvStr.data()), certTlvStr.size()));
request.push_back(valueBlock);
}
else {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
}
- } 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) {
+ for (const auto& item : params) {
if (std::get<0>(item) == PARAMETER_KEY_PROOF) {
request.push_back(makeStringBlock(tlv::ParameterKey, PARAMETER_KEY_PROOF));
- auto &sigTlvStr = std::get<1>(item);
- Block valueBlock = makeBinaryBlock(tlv::ParameterValue, (uint8_t *) sigTlvStr.c_str(),
+ auto& sigTlvStr = std::get<1>(item);
+ Block valueBlock = makeBinaryBlock(tlv::ParameterValue,
+ reinterpret_cast<const uint8_t*>(sigTlvStr.data()),
sigTlvStr.size());
request.push_back(valueBlock);
- } else {
+ }
+ else {
NDN_THROW(std::runtime_error("Wrong parameter provided."));
}
}
- } else {
+ }
+ else {
NDN_THROW(std::runtime_error("Unexpected status or challenge status."));
}
request.encode();
@@ -229,20 +240,20 @@
KeyChain& keyChain, const Name& issuedCertName,
const std::array<uint8_t, 16>& nonce)
{
- auto& pib = keyChain.getPib();
- auto id = pib.getIdentity(security::extractIdentityFromCertName(issuedCertName));
- auto issuedCert = id.getKey(security::extractKeyNameFromCertName(issuedCertName)).getCertificate(issuedCertName);
+ auto keyName = security::extractKeyNameFromCertName(issuedCertName);
+ auto id = keyChain.getPib().getIdentity(security::extractIdentityFromCertName(issuedCertName));
+ auto issuedCert = id.getKey(keyName).getCertificate(issuedCertName);
auto issuedCertTlv = issuedCert.wireEncode();
- auto signatureTlv = keyChain.sign(nonce.data(), nonce.size(), security::signingByCertificate(issuedCertName));
+ auto signature = keyChain.getTpm().sign({{nonce.data(), nonce.size()}}, keyName, DigestAlgorithm::SHA256);
+
for (auto& item : params) {
- if (std::get<0>(item) == PARAMETER_KEY_CREDENTIAL_CERT) {
- std::get<1>(item) = std::string((char*)issuedCertTlv.wire(), issuedCertTlv.size());
+ if (item.first == PARAMETER_KEY_CREDENTIAL_CERT) {
+ item.second = std::string(reinterpret_cast<const char*>(issuedCertTlv.wire()), issuedCertTlv.size());
}
- else if (std::get<0>(item) == PARAMETER_KEY_PROOF) {
- std::get<1>(item) = std::string((char*)signatureTlv.value(), signatureTlv.value_size());
+ else if (item.first == PARAMETER_KEY_PROOF) {
+ item.second = std::string(signature->get<char>(), signature->size());
}
}
- return;
}
} // namespace ndncert