1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "cli/calistcommand.hpp"
21 #include "remote/apilistener.hpp"
22 #include "remote/pkiutility.hpp"
23 #include "base/logger.hpp"
24 #include "base/application.hpp"
25 #include "base/tlsutility.hpp"
26 #include "base/json.hpp"
29 using namespace icinga;
30 namespace po = boost::program_options;
32 REGISTER_CLICOMMAND("ca/list", CAListCommand);
34 String CAListCommand::GetDescription() const
36 return "Lists all certificate signing requests.";
39 String CAListCommand::GetShortDescription() const
41 return "lists all certificate signing requests";
44 void CAListCommand::InitParameters(boost::program_options::options_description& visibleDesc,
45 boost::program_options::options_description& hiddenDesc) const
47 visibleDesc.add_options()
48 ("json", "encode output as JSON")
53 * The entry point for the "ca list" CLI command.
55 * @returns An exit status.
57 int CAListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
59 Dictionary::Ptr requests = PkiUtility::GetCertificateRequests();
62 std::cout << JsonEncode(requests);
64 ObjectLock olock(requests);
66 std::cout << "Fingerprint | Timestamp | Signed | Subject\n";
67 std::cout << "-----------------------------------------------------------------|--------------------------|--------|--------\n";
69 for (auto& kv : requests) {
70 Dictionary::Ptr request = kv.second;
74 /* << Utility::FormatDateTime("%Y/%m/%d %H:%M:%S", request->Get("timestamp")) */
75 << request->Get("timestamp")
77 << (request->Contains("cert_response") ? "*" : " ") << " "
79 << request->Get("subject")