blob: 09fd64a0438496cd8fdb76d0d8c4d6a794bcbaa8 [file] [log] [blame]
Zhiyi Zhang440e6a22017-04-14 14:31:37 -07001/* -*- 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#include "ca-detail/ca-sqlite.hpp"
23
24#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
31std::string
32convertJson2String(const JsonSection& json)
33{
34 std::stringstream ss;
35 boost::property_tree::write_json(ss, json);
36 return ss.str();
37}
38
39int
40main(int argc, char* argv[])
41{
42 namespace po = boost::program_options;
43 std::string caNameString = "";
44 po::options_description description("General Usage\n ndncert-ca [-h] [-f] configFilePath-file\n");
45 description.add_options()
46 ("help,h", "produce help message")
47 ("CAName,c", po::value<std::string>(&caNameString), "ca name");
48 po::positional_options_description p;
49 po::variables_map vm;
50 try {
51 po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm);
52 po::notify(vm);
53 }
54 catch (const std::exception& e) {
55 std::cerr << "ERROR: " << e.what() << std::endl;
56 return 1;
57 }
58 if (vm.count("help") != 0) {
59 std::cerr << description << std::endl;
60 return 0;
61 }
62
63 CaSqlite storage;
64 std::list<CertificateRequest> requestList;
65 std::list<security::v2::Certificate> certList;
66 if (caNameString != "") {
67 requestList = storage.listAllRequests(Name(caNameString));
68 certList = storage.listAllIssuedCertificates(Name(caNameString));
69 }
70 else {
71 requestList = storage.listAllRequests();
72 certList = storage.listAllIssuedCertificates();
73 }
74
75 std::cerr << "The pending requests :" << std::endl;
76
77 for (const auto& entry : requestList) {
78 std::cerr << "Request ID: " << entry.getRequestId() << "\t"
79 << "Current Status: " << entry.getStatus() << std::endl
80 << "Applying CA: " << entry.getCaName().toUri() << std::endl
81 << "Applying for key: " << entry.getCert().getKeyName().toUri() << std::endl
82 << "Challenge Secret: " << convertJson2String(entry.getChallengeSecrets()) << std::endl;
83 }
84
85 std::cerr << "\n\n" << "The issued certs :" << std::endl;
86
87 for (const auto& entry : certList) {
88 std::cerr << entry.getName().toUri() << std::endl;
89 }
90
91 return 0;
92}
93
94} // namespace ndncert
95} // namespace ndn
96
97int
98main(int argc, char* argv[])
99{
100 return ndn::ndncert::main(argc, argv);
101}