blob: 6a2572a8b3efd22ae82eec7f0e264b2b8deb78c1 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07002/**
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library 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 Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Yingdi Yu8d7468f2014-02-21 14:49:45 -080020 */
21
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080022#include "ndnsec.hpp"
23#include "util.hpp"
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -070024#include "version.hpp"
Alexander Afanasyevd7db8bf2015-01-04 15:31:02 -080025
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080026std::string ndnsec_helper = R"STR(
27 help Show all commands
28 version Show version and exit
29 list Display information in PublicInfo
30 get-default Get default setting info
31 set-default Configure default setting
32 key-gen Generate a Key-Signing-Key for an identity
33 dsk-gen Generate a Data-Signing-Key for an identity
34 sign-req Generate a certificate signing request
35 cert-gen Generate an identity certificate
36 cert-revoke Revoke an identity certificate
37 cert-dump Dump a certificate from PublicInfo
38 cert-install Install a certificate into PublicInfo
39 delete Delete identity/key/certificate
40 export Export an identity package
41 import Import an identity package
42 set-acl Configure ACL of a private key
43 unlock-tpm Unlock Tpm
44)STR";
Yingdi Yu8d7468f2014-02-21 14:49:45 -080045
Yingdi Yu05842f22014-04-15 19:21:56 -070046int
Yingdi Yu5c1f8412014-03-25 11:49:47 -070047main(int argc, char** argv)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080048{
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080049 if (argc < 2) {
50 std::cerr << ndnsec_helper << std::endl;
51 return 1;
52 }
53
54 using namespace ndn::ndnsec;
55
56 std::string command(argv[1]);
57 try {
58 if (command == "help") { std::cout << ndnsec_helper << std::endl; }
59 else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING << std::endl; }
60 else if (command == "list") { return ndnsec_list(argc - 1, argv + 1); }
61 else if (command == "get-default") { return ndnsec_get_default(argc - 1, argv + 1); }
62 else if (command == "set-default") { return ndnsec_set_default(argc - 1, argv + 1); }
63 else if (command == "key-gen") { return ndnsec_key_gen(argc - 1, argv + 1); }
64 else if (command == "dsk-gen") { return ndnsec_dsk_gen(argc - 1, argv + 1); }
65 else if (command == "sign-req") { return ndnsec_sign_req(argc - 1, argv + 1); }
66 else if (command == "cert-gen") { return ndnsec_cert_gen(argc - 1, argv + 1); }
67 else if (command == "cert-revoke") { return ndnsec_cert_revoke(argc - 1, argv + 1); }
68 else if (command == "cert-dump") { return ndnsec_cert_dump(argc - 1, argv + 1); }
69 else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); }
70 else if (command == "delete") { return ndnsec_delete(argc - 1, argv + 1); }
71 else if (command == "export") { return ndnsec_export(argc - 1, argv + 1); }
72 else if (command == "import") { return ndnsec_import(argc - 1, argv + 1); }
73 else if (command == "set-acl") { return ndnsec_set_acl(argc - 1, argv + 1); }
74 else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
75 else {
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080076 std::cerr << ndnsec_helper << std::endl;
77 return 1;
78 }
Alexander Afanasyev82c359c2017-01-04 14:48:07 -080079 }
80 catch (const std::runtime_error& e) {
81 std::cerr << "ERROR: " << e.what() << std::endl;
82 return 1;
83 }
Yingdi Yu8d7468f2014-02-21 14:49:45 -080084
85 return 0;
86}