blob: 25aee9907c41b169c5e3c7e94d137272bb5235c5 [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu8d7468f2014-02-21 14:49:45 -080022 */
23
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -070024#include "version.hpp"
Yingdi Yu8d7468f2014-02-21 14:49:45 -080025#include "ndnsec-util.hpp"
26#include "ndnsec-list.hpp"
27#include "ndnsec-get-default.hpp"
28#include "ndnsec-set-default.hpp"
29#include "ndnsec-key-gen.hpp"
30#include "ndnsec-dsk-gen.hpp"
31#include "ndnsec-sign-req.hpp"
32#include "ndnsec-cert-gen.hpp"
Yingdi Yu5edf97d2014-06-15 11:35:12 -070033#include "ndnsec-cert-revoke.hpp"
Yingdi Yu8d7468f2014-02-21 14:49:45 -080034#include "ndnsec-cert-dump.hpp"
35#include "ndnsec-cert-install.hpp"
36#include "ndnsec-export.hpp"
37#include "ndnsec-import.hpp"
38#include "ndnsec-delete.hpp"
39#include "ndnsec-sig-verify.hpp"
40#include "ndnsec-set-acl.hpp"
41#include "ndnsec-unlock-tpm.hpp"
42#include "ndnsec-op-tool.hpp"
43
44using namespace ndn;
45
46std::string ndnsec_helper("\
47 help Show all commands.\n\
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -070048 version Show version and exit.\n\
Yingdi Yu8d7468f2014-02-21 14:49:45 -080049 list Display information in PublicInfo.\n\
50 get-default Get default setting info.\n\
51 set-default Configure default setting.\n\
52 key-gen Generate a Key-Signing-Key for an identity.\n\
Alexander Afanasyevace74452014-11-30 22:28:24 -080053 dsk-gen Generate a Data-Signing-Key for an identity.\n\
Yingdi Yu8d7468f2014-02-21 14:49:45 -080054 sign-req Generate a certificate signing request.\n\
55 cert-gen Generate an identity certificate.\n\
Yingdi Yu5edf97d2014-06-15 11:35:12 -070056 cert-revoke Revoke an identity certificate.\n\
Yingdi Yu8d7468f2014-02-21 14:49:45 -080057 cert-dump Dump a certificate from PublicInfo.\n\
58 cert-install Install a certificate into PublicInfo.\n\
Yingdi Yu5c1f8412014-03-25 11:49:47 -070059 delete Delete identity/key/certificate.\n\
Yingdi Yu8d7468f2014-02-21 14:49:45 -080060 export Export an identity package.\n\
61 import Import an identity package.\n\
62 sig-verify Verify the signature of a Data packet.\n\
63 set-acl Configure ACL of a private key.\n\
64 unlock-tpm Unlock Tpm.\n\
65 op-tool Operator tool.\n\
Yingdi Yu05842f22014-04-15 19:21:56 -070066");
Yingdi Yu8d7468f2014-02-21 14:49:45 -080067
Yingdi Yu05842f22014-04-15 19:21:56 -070068int
Yingdi Yu5c1f8412014-03-25 11:49:47 -070069main(int argc, char** argv)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080070{
Yingdi Yub61f5402014-02-26 17:46:11 -080071 if (argc < 2)
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080072 {
73 std::cerr << ndnsec_helper << std::endl;
74 return 1;
75 }
76
Yingdi Yu8d7468f2014-02-21 14:49:45 -080077 std::string command(argv[1]);
Yingdi Yub61f5402014-02-26 17:46:11 -080078
79 try
80 {
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -070081 if (command == "help") { std::cout << ndnsec_helper << std::endl; }
82 else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING
83 << std::endl; }
Yingdi Yub61f5402014-02-26 17:46:11 -080084 else if (command == "list") { return ndnsec_list(argc - 1, argv + 1); }
85 else if (command == "get-default") { return ndnsec_get_default(argc - 1, argv + 1); }
86 else if (command == "set-default") { return ndnsec_set_default(argc - 1, argv + 1); }
87 else if (command == "key-gen") { return ndnsec_key_gen(argc - 1, argv + 1); }
Alexander Afanasyevace74452014-11-30 22:28:24 -080088 else if (command == "dsk-gen") { return ndnsec_dsk_gen(argc - 1, argv + 1); }
Yingdi Yub61f5402014-02-26 17:46:11 -080089 else if (command == "sign-req") { return ndnsec_sign_req(argc - 1, argv + 1); }
90 else if (command == "cert-gen") { return ndnsec_cert_gen(argc - 1, argv + 1); }
Yingdi Yu5edf97d2014-06-15 11:35:12 -070091 else if (command == "cert-revoke") { return ndnsec_cert_revoke(argc - 1, argv + 1); }
Yingdi Yub61f5402014-02-26 17:46:11 -080092 else if (command == "cert-dump") { return ndnsec_cert_dump(argc - 1, argv + 1); }
93 else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); }
94 else if (command == "delete") { return ndnsec_delete(argc - 1, argv + 1); }
95 else if (command == "export") { return ndnsec_export(argc - 1, argv + 1); }
96 else if (command == "import") { return ndnsec_import(argc - 1, argv + 1); }
97 else if (command == "sig-verify") { return ndnsec_sig_verify(argc - 1, argv + 1); }
98 else if (command == "set-acl") { return ndnsec_set_acl(argc - 1, argv + 1); }
99 else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
100 else if (command == "op-tool") { return ndnsec_op_tool(argc - 1, argv + 1); }
101 else {
102 std::cerr << ndnsec_helper << std::endl;
103 return 1;
104 }
105 }
106 catch (const std::runtime_error& e)
107 {
108 std::cerr << "ERROR: " << e.what() << std::endl;
109 return 1;
110 }
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800111
112 return 0;
113}