mgmt: combine ndns-add-rr and ndns-add-rr-from-file to a single command
Change-Id: I5b1410be95710a629d6a2ca401d475b16837d357
Refs: #2229, #2701
diff --git a/src/mgmt/management-tool.cpp b/src/mgmt/management-tool.cpp
index 186cced..e74c601 100644
--- a/src/mgmt/management-tool.cpp
+++ b/src/mgmt/management-tool.cpp
@@ -35,6 +35,7 @@
#include <ndn-cxx/encoding/oid.hpp>
#include <ndn-cxx/security/v1/cryptopp.hpp>
#include <ndn-cxx/link.hpp>
+#include <ndn-cxx/security/signing-helpers.hpp>
namespace ndn {
namespace ndns {
@@ -270,11 +271,12 @@
}
void
-ManagementTool::addRrSet(const Name& zoneName,
- const std::string& inFile,
- const time::seconds& ttl,
- const Name& inputDskCertName,
- const ndn::io::IoEncoding encoding)
+ManagementTool::addRrsetFromFile(const Name& zoneName,
+ const std::string& inFile,
+ const time::seconds& ttl,
+ const Name& inputDskCertName,
+ const ndn::io::IoEncoding encoding,
+ bool needResign)
{
//check precondition
Zone zone(zoneName);
@@ -301,7 +303,7 @@
}
}
- //first load the data
+ // load data
shared_ptr<Data> data;
if (inFile == DEFAULT_IO)
data = ndn::io::load<ndn::Data>(std::cin, encoding);
@@ -312,41 +314,8 @@
throw Error("input does not contain a valid Data packet");
}
- // determine whether the data is a self-signed certificate
- shared_ptr<Regex> regex1 = make_shared<Regex>("(<>*)<KEY>(<>+)<ID-CERT><>");
- if (regex1->match(data->getName())) {
- IdentityCertificate scert(*data);
- Name keyName = scert.getPublicKeyName();
- if (keyName.getPrefix(zoneName.size()) != zoneName) {
- throw Error("the input key does not belong to the zone");
- }
-
- Name keyLocator = scert.getSignature().getKeyLocator().getName();
-
- // if it is, extract the content and name from the data, and resign it using the dsk.
- shared_ptr<Regex> regex2 = make_shared<Regex>("(<>*)<KEY>(<>+)<ID-CERT>");
- BOOST_VERIFY(regex2->match(keyLocator) == true);
- if (keyName == regex2->expand("\\1\\2")) {
-
- Name canonicalName;
- canonicalName
- .append(zoneName)
- .append("KEY")
- .append(keyName.getSubName(zoneName.size(), keyName.size() - zoneName.size()))
- .append("ID-CERT")
- .append(data->getName().get(-1));
-
- if (data->getName() != canonicalName) {
- // name need to be adjusted
- auto newData = make_shared<Data>();
- newData->setName(canonicalName);
- newData->setMetaInfo(data->getMetaInfo());
- newData->setContent(data->getContent());
- m_keyChain.sign(*newData);
-
- data = newData;
- }
- }
+ if (needResign) {
+ m_keyChain.sign(*data, signingByCertificate(dskCertName));
}
// create response for the input data