tools: Add security tools; Add waf build options for tools.
Change-Id: I058510acc1a0361fed43d94c7a0b545416a9efb4
diff --git a/tools/ndnsec-sign-req.cpp b/tools/ndnsec-sign-req.cpp
new file mode 100644
index 0000000..6aef0b8
--- /dev/null
+++ b/tools/ndnsec-sign-req.cpp
@@ -0,0 +1,93 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/*
+ * Copyright (c) 2013, Regents of the University of California
+ * Yingdi Yu
+ *
+ * BSD license, See the LICENSE file for more information
+ *
+ * Author: Yingdi Yu <yingdi@cs.ucla.edu>
+ */
+
+#include <iostream>
+#include <fstream>
+
+#include <boost/program_options/options_description.hpp>
+#include <boost/program_options/variables_map.hpp>
+#include <boost/program_options/parsers.hpp>
+#include <cryptopp/base64.h>
+#include <cryptopp/files.h>
+
+#include "security/key-chain.hpp"
+
+using namespace ndn;
+namespace po = boost::program_options;
+
+
+int main(int argc, char** argv)
+{
+ std::string name;
+ bool isKeyName = false;
+
+ po::options_description desc("General Usage\n ndn-sign-req [-h] [-k] name\nGeneral options");
+ desc.add_options()
+ ("help,h", "produce help message")
+ ("key,k", "optional, if specified, name is keyName (e.g. /ndn/edu/ucla/alice/ksk-123456789), otherwise identity name")
+ ("name,n", po::value<std::string>(&name), "name, for example, /ndn/edu/ucla/alice")
+ ;
+
+ po::positional_options_description p;
+ p.add("name", 1);
+
+ po::variables_map vm;
+ try {
+ po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
+ po::notify(vm);
+ }
+ catch(const std::exception &e) {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ std::cerr << desc << std::endl;
+ return 1;
+ }
+
+ if (vm.count("help"))
+ {
+ std::cerr << desc << std::endl;
+ return 1;
+ }
+
+ if (0 == vm.count("name"))
+ {
+ std::cerr << "identity_name must be specified" << std::endl;
+ std::cerr << desc << std::endl;
+ return 1;
+ }
+
+ if (vm.count("key"))
+ isKeyName = true;
+
+ KeyChain keyChain;
+
+ try{
+ if(isKeyName)
+ {
+ shared_ptr<IdentityCertificate> selfSignCert = keyChain.selfSign(name);
+
+ CryptoPP::StringSource ss(selfSignCert->wireEncode().wire(), selfSignCert->wireEncode().size(), true,
+ new CryptoPP::Base64Encoder(new CryptoPP::FileSink(std::cout), true, 64));
+ }
+ else
+ {
+ Name keyName = keyChain.getDefaultKeyNameForIdentity(name);
+ ptr_lib::shared_ptr<IdentityCertificate> selfSignCert = keyChain.selfSign(keyName);
+
+ CryptoPP::StringSource ss(selfSignCert->wireEncode().wire(), selfSignCert->wireEncode().size(), true,
+ new CryptoPP::Base64Encoder(new CryptoPP::FileSink(std::cout), true, 64));
+ }
+ }
+ catch(std::exception & e)
+ {
+ std::cerr << "ERROR: " << e.what() << std::endl;
+ return 1;
+ }
+ return 0;
+}