blob: 6e4932858a670d3591a1e1c1793f250d4b0425e3 [file] [log] [blame]
Jiewen Tan870b29b2014-11-17 19:09:49 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yumin Xia2c509c22017-02-09 14:37:36 -08002/*
Alexander Afanasyev08d18742018-03-15 16:31:28 -04003 * Copyright (c) 2014-2018, Regents of the University of California.
Jiewen Tan870b29b2014-11-17 19:09:49 -08004 *
5 * This file is part of NDNS (Named Data Networking Domain Name Service).
6 * See AUTHORS.md for complete list of NDNS authors and contributors.
7 *
8 * NDNS is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NDNS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NDNS, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "mgmt/management-tool.hpp"
21#include "ndns-label.hpp"
22#include "logger.hpp"
23#include <boost/program_options.hpp>
24#include <boost/filesystem.hpp>
25#include <string>
26
27int
28main(int argc, char* argv[])
29{
30 using std::string;
31 using namespace ndn;
32 using namespace ndns;
33
Jiewen Tan870b29b2014-11-17 19:09:49 -080034 string certStr;
35 string db;
36 string output = "-";
37 try {
38 namespace po = boost::program_options;
39 po::variables_map vm;
40
41 po::options_description options("Generic Options");
42 options.add_options()
43 ("help,h", "print help message")
44 ("db,b", po::value<std::string>(&db), "Set the path of NDNS server database. "
45 "Default: " DEFAULT_DATABASE_PATH "/ndns.db");
46
47 po::options_description config("Output Options");
48 config.add_options()
49 ("output,o", po::value<string>(&output), "Set the output path of the to be export cert. "
50 "Default: stdout(-)")
51 ;
52
53 options.add(config);
54
55 po::options_description hidden("Hidden Options");
56 hidden.add_options()
57 ("certName", po::value<string>(&certStr), "the name of the certificate")
58 ;
59
60 po::positional_options_description postion;
61 postion.add("certName", 1);
62
63 po::options_description cmdline_options;
64 cmdline_options.add(options).add(hidden);
65
66 // po::options_description config_file_options;
67 // config_file_options.add(config).add(hidden);
68
69 po::parsed_options parsed =
70 po::command_line_parser(argc, argv).options(cmdline_options).positional(postion).run();
71
72 po::store(parsed, vm);
73 po::notify(vm);
74
75 if (vm.count("help")) {
76 std::cout << "Usage: ndns-export-certificate [-b db] certificateName [-o output] "
77 << std::endl;
78 std::cout << options << std::endl;
79 return 0;
80 }
81
82 if (vm.count("certName") == 0) {
83 std::cerr << "Error: certificate name must be specified" << std::endl;
84 return 1;
85 }
86 }
87 catch (const std::exception& ex) {
88 std::cerr << "Parameter Error: " << ex.what() << std::endl;
89 return 1;
90 }
91
92 try {
93 Name certName(certStr);
94
Yumin Xia2c509c22017-02-09 14:37:36 -080095 KeyChain keyChain;
Alexander Afanasyevd6b3bda2014-11-25 17:33:58 -080096 ndn::ndns::ManagementTool tool(db, keyChain);
Jiewen Tan870b29b2014-11-17 19:09:49 -080097 tool.exportCertificate(certName, output);
98 }
99 catch (const std::exception& ex) {
100 std::cerr << "Error: " << ex.what() << std::endl;
101 return 1;
102 }
103}