blob: 5d094367b741140a50c37e8245b9a1301aec998b [file] [log] [blame]
Zhiyi Zhang440e6a22017-04-14 14:31:37 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
tylerliu182bc532020-09-25 01:54:45 -07003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhang440e6a22017-04-14 14:31:37 -07004 *
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"
Zhiyi Zhang8bd8e5b2020-09-29 17:40:40 -070022#include "ca-storage-detail/ca-sqlite.hpp"
Zhiyi Zhangb6fab0f2017-09-21 16:26:27 -070023#include <iostream>
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070024#include <boost/program_options/options_description.hpp>
25#include <boost/program_options/variables_map.hpp>
26#include <boost/program_options/parsers.hpp>
27
28namespace ndn {
29namespace ndncert {
30
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070031int
32main(int argc, char* argv[])
33{
34 namespace po = boost::program_options;
35 std::string caNameString = "";
36 po::options_description description("General Usage\n ndncert-ca [-h] [-f] configFilePath-file\n");
37 description.add_options()
38 ("help,h", "produce help message")
39 ("CAName,c", po::value<std::string>(&caNameString), "ca name");
40 po::positional_options_description p;
41 po::variables_map vm;
42 try {
43 po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm);
44 po::notify(vm);
45 }
46 catch (const std::exception& e) {
47 std::cerr << "ERROR: " << e.what() << std::endl;
48 return 1;
49 }
50 if (vm.count("help") != 0) {
51 std::cerr << description << std::endl;
52 return 0;
53 }
54
55 CaSqlite storage;
Zhiyi Zhange232a742020-09-29 17:34:17 -070056 std::list<RequestState> requestList;
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070057 std::list<security::v2::Certificate> certList;
58 if (caNameString != "") {
59 requestList = storage.listAllRequests(Name(caNameString));
60 certList = storage.listAllIssuedCertificates(Name(caNameString));
61 }
62 else {
63 requestList = storage.listAllRequests();
64 certList = storage.listAllIssuedCertificates();
65 }
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070066 std::cerr << "The pending requests :" << std::endl;
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070067 for (const auto& entry : requestList) {
Zhiyi Zhanga749f442020-09-29 17:19:51 -070068 std::cerr << entry;
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070069 }
Zhiyi Zhanga749f442020-09-29 17:19:51 -070070 std::cerr << "\n\nThe issued certs :" << std::endl;
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070071 for (const auto& entry : certList) {
72 std::cerr << entry.getName().toUri() << std::endl;
73 }
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070074 return 0;
75}
76
77} // namespace ndncert
78} // namespace ndn
79
80int
81main(int argc, char* argv[])
82{
83 return ndn::ndncert::main(argc, argv);
84}