Fix bug in challenge module about component index. Also add some LOG points
Change-Id: I8ec737ef9d7177becbe84055efa2438efab02225
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index b0d0e44..1e4058c 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -173,6 +173,7 @@
_LOG_TRACE(e.what());
return;
}
+ _LOG_TRACE("SELECT request choosing challenge " << challengeType);
auto challenge = ChallengeModule::createChallengeModule(challengeType);
if (challenge == nullptr) {
_LOG_TRACE("Unrecognized challenge type " << challengeType);
diff --git a/src/challenge-module.cpp b/src/challenge-module.cpp
index 6a28866..c7ab849 100644
--- a/src/challenge-module.cpp
+++ b/src/challenge-module.cpp
@@ -19,11 +19,14 @@
*/
#include "challenge-module.hpp"
+#include "logging.hpp"
#include <random>
namespace ndn {
namespace ndncert {
+_LOG_INIT(ndncert.pinchallenge);
+
const std::string ChallengeModule::WAIT_SELECTION = "wait-selection";
const std::string ChallengeModule::SUCCESS = "success";
const std::string ChallengeModule::PENDING = "pending";
@@ -44,9 +47,12 @@
JsonSection
ChallengeModule::handleChallengeRequest(const Interest& interest, CertificateRequest& request)
{
- int pos = request.getCaName().size();
+ int pos = request.getCaName().size() + 1;
const Name& interestName = interest.getName();
std::string interestType = interestName.get(pos).toUri();
+
+ _LOG_TRACE("Incoming challenge request. type: " << interestType);
+
if (interestType == "_SELECT") {
return processSelectInterest(interest, request);
}
diff --git a/src/challenge-module/challenge-pin.cpp b/src/challenge-module/challenge-pin.cpp
index 1aa96ce..d21420c 100644
--- a/src/challenge-module/challenge-pin.cpp
+++ b/src/challenge-module/challenge-pin.cpp
@@ -46,7 +46,7 @@
JsonSection
ChallengePin::processSelectInterest(const Interest& interest, CertificateRequest& request)
{
- // interest format: /CA/_SELECT/{"request-id":"id"}/PIN/<signature>
+ // interest format: /caName/CA/_SELECT/{"request-id":"id"}/PIN/<signature>
request.setStatus(NEED_CODE);
request.setChallengeType(CHALLENGE_TYPE);
request.setChallengeSecrets(generateStoredSecrets(time::system_clock::now(),
@@ -58,8 +58,8 @@
JsonSection
ChallengePin::processValidateInterest(const Interest& interest, CertificateRequest& request)
{
- // interest format: /CA/_VALIDATION/{"request-id":"id"}/PIN/{"code":"code"}/<signature>
- JsonSection infoJson = getJsonFromNameComponent(interest.getName(), request.getCaName().size() + 3);
+ // interest format: /caName/CA/_VALIDATION/{"request-id":"id"}/PIN/{"code":"code"}/<signature>
+ JsonSection infoJson = getJsonFromNameComponent(interest.getName(), request.getCaName().size() + 4);
std::string givenCode = infoJson.get<std::string>(JSON_PIN_CODE);
const auto parsedSecret = parseStoredSecrets(request.getChallengeSecrets());
diff --git a/src/client-module.cpp b/src/client-module.cpp
index fe4eb72..157f28d 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -187,6 +187,9 @@
}
JsonSection json = getJsonFromData(reply);
+
+ _LOG_TRACE("SELECT response would change the status from " << state->m_status << " to " + json.get<std::string>(JSON_STATUS));
+
state->m_status = json.get<std::string>(JSON_STATUS);
if (!checkStatus(*state, json, errorCallback)) {
@@ -393,7 +396,8 @@
return false;
}
if (state.m_requestId.empty() || state.m_status.empty()) {
- errorCallback("The response does not carry required fields.");
+ errorCallback("The response does not carry required fields. requestID: " + state.m_requestId
+ + " status: " + state.m_status);
return false;
}
return true;