blob: d426535c6587876bfdc6bf3f48d6e6ab15461eeb [file] [log] [blame]
Zhiyi Zhang440e6a22017-04-14 14:31:37 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -07003 * Copyright (c) 2017-2019, 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"
22#include "ca-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
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) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070078 std::cerr << "Request ID: " << entry.m_requestId << "\t"
79 << "Current Status: " << entry.m_status << std::endl
80 << "Applying CA: " << entry.m_caName << std::endl
81 << "Applying for key: " << entry.m_cert.getName() << std::endl
82 << "Challenge remaining tries: " << entry.m_remainingTries << std::endl
83 << "Challenge Secret: " << convertJson2String(entry.m_challengeSecrets) << std::endl;
Zhiyi Zhang440e6a22017-04-14 14:31:37 -070084 }
85
86 std::cerr << "\n\n" << "The issued certs :" << std::endl;
87
88 for (const auto& entry : certList) {
89 std::cerr << entry.getName().toUri() << std::endl;
90 }
91
92 return 0;
93}
94
95} // namespace ndncert
96} // namespace ndn
97
98int
99main(int argc, char* argv[])
100{
101 return ndn::ndncert::main(argc, argv);
102}