blob: 7377fc1c7aca7bdb07427ffe991be89b54188d3c [file] [log] [blame]
Zhiyi Zhang08e0e982017-03-01 10:10:42 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
4 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
21#include "ca-module.hpp"
22
Zhiyi Zhangb6fab0f2017-09-21 16:26:27 -070023#include <iostream>
24
Zhiyi Zhang08e0e982017-03-01 10:10:42 -080025#include <boost/program_options/options_description.hpp>
26#include <boost/program_options/variables_map.hpp>
27#include <boost/program_options/parsers.hpp>
28
29namespace ndn {
30namespace ndncert {
31
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080032
Zhiyi Zhang08e0e982017-03-01 10:10:42 -080033int
34main(int argc, char* argv[])
35{
36 namespace po = boost::program_options;
37 std::string configFilePath = std::string(SYSCONFDIR) + "/ndncert/ca.conf";
38 po::options_description description("General Usage\n ndncert-ca [-h] [-f] configFilePath-file\n");
39 description.add_options()
40 ("help,h", "produce help message")
41 ("config-file,f", po::value<std::string>(&configFilePath), "config file name");
42 po::positional_options_description p;
43 po::variables_map vm;
44 try {
45 po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm);
46 po::notify(vm);
47 }
48 catch (const std::exception& e) {
49 std::cerr << "ERROR: " << e.what() << std::endl;
50 return 1;
51 }
52 if (vm.count("help") != 0) {
53 std::cerr << description << std::endl;
54 return 0;
55 }
56
57 Face face;
58 security::v2::KeyChain keyChain;
59 CaModule ca(face, keyChain, configFilePath);
Zhiyi Zhang08e0e982017-03-01 10:10:42 -080060
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080061 ca.setRecommendCaHandler(Name("/ndn"),
62 [] (const std::string& input, const std::list<Name>& list) -> std::tuple<Name, std::string> {
63 Name recommendedCa;
64 std::string identity;
65 for (auto caName : list) {
66 std::string univName = readString(caName.get(-1));
67 if (input.find(univName) != std::string::npos) {
68 recommendedCa = caName;
69 identity = input.substr(0, input.find("@"));
70 break;
71 }
72 }
73 return std::make_tuple(recommendedCa, identity);
74 });
75
76 face.processEvents();
Zhiyi Zhang08e0e982017-03-01 10:10:42 -080077 return 0;
78}
79
80} // namespace ndncert
81} // namespace ndn
82
83int
84main(int argc, char* argv[])
85{
86 return ndn::ndncert::main(argc, argv);
87}