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