mgmt: rename extractRequester() and support signed Interest v0.3
Change-Id: I6bb6635896fa1b9fa54beb70b902c5a35831dc9c
diff --git a/daemon/mgmt/manager-base.cpp b/daemon/mgmt/manager-base.cpp
index a39bbd6..ee5f782 100644
--- a/daemon/mgmt/manager-base.cpp
+++ b/daemon/mgmt/manager-base.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -58,22 +58,20 @@
return m_dispatcher.addNotificationStream(makeRelPrefix(verb));
}
-void
-ManagerBase::extractRequester(const Interest& interest,
- const ndn::mgmt::AcceptContinuation& accept)
+std::string
+ManagerBase::extractSigner(const Interest& interest)
{
- const Name& interestName = interest.getName();
-
try {
- ndn::SignatureInfo sigInfo(interestName.at(ndn::signed_interest::POS_SIG_INFO).blockFromValue());
- if (!sigInfo.hasKeyLocator() || sigInfo.getKeyLocator().getType() != tlv::Name) {
- return accept("");
+ // try v0.3 format first
+ auto sigInfo = interest.getSignatureInfo();
+ if (!sigInfo) {
+ // fallback to v0.2 format
+ sigInfo.emplace(interest.getName().at(ndn::signed_interest::POS_SIG_INFO).blockFromValue());
}
-
- accept(sigInfo.getKeyLocator().getName().toUri());
+ return sigInfo->getKeyLocator().getName().toUri();
}
catch (const tlv::Error&) {
- accept("");
+ return "";
}
}
diff --git a/daemon/mgmt/manager-base.hpp b/daemon/mgmt/manager-base.hpp
index eeb55f5..592d4fa 100644
--- a/daemon/mgmt/manager-base.hpp
+++ b/daemon/mgmt/manager-base.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -92,15 +92,13 @@
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED: // helpers
/**
- * @brief Extracts the requester from a ControlCommand request.
+ * @brief Extracts the name from the %KeyLocator of a ControlCommand request.
*
* This is called after the signature has been validated.
- *
- * @param interest a request for ControlCommand
- * @param accept callback of successful validation, takes the requester string as argument
+ * Returns an empty string if %SignatureInfo or %KeyLocator are missing or malformed.
*/
- static void
- extractRequester(const Interest& interest, const ndn::mgmt::AcceptContinuation& accept);
+ static std::string
+ extractSigner(const Interest& interest);
NFD_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/**
diff --git a/daemon/mgmt/rib-manager.cpp b/daemon/mgmt/rib-manager.cpp
index afeca1c..484b4eb 100644
--- a/daemon/mgmt/rib-manager.cpp
+++ b/daemon/mgmt/rib-manager.cpp
@@ -313,7 +313,7 @@
auto& validator = prefix == LOCALHOST_TOP_PREFIX ? m_localhostValidator : m_localhopValidator;
validator.validate(interest,
- [&interest, accept] (auto&&...) { extractRequester(interest, accept); },
+ [&interest, accept] (auto&&...) { accept(extractSigner(interest)); },
[reject] (auto&&...) { reject(ndn::mgmt::RejectReply::STATUS403); });
};
}