Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * 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 Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
Alexander Afanasyev | cfe0b06 | 2014-05-08 18:26:50 -0700 | [diff] [blame] | 24 | #include "version.hpp" |
Alexander Afanasyev | d7db8bf | 2015-01-04 15:31:02 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 26 | #include "security/key-chain.hpp" |
| 27 | #include "security/v1/certificate-subject-description.hpp" |
| 28 | #include "security/v1/secured-bag.hpp" |
| 29 | |
Alexander Afanasyev | d7db8bf | 2015-01-04 15:31:02 -0800 | [diff] [blame] | 30 | #include "util.hpp" |
| 31 | #include "list.hpp" |
| 32 | #include "get-default.hpp" |
| 33 | #include "set-default.hpp" |
| 34 | #include "key-gen.hpp" |
| 35 | #include "dsk-gen.hpp" |
| 36 | #include "sign-req.hpp" |
| 37 | #include "cert-gen.hpp" |
| 38 | #include "cert-revoke.hpp" |
| 39 | #include "cert-dump.hpp" |
| 40 | #include "cert-install.hpp" |
| 41 | #include "export.hpp" |
| 42 | #include "import.hpp" |
| 43 | #include "delete.hpp" |
Alexander Afanasyev | d7db8bf | 2015-01-04 15:31:02 -0800 | [diff] [blame] | 44 | #include "set-acl.hpp" |
| 45 | #include "unlock-tpm.hpp" |
| 46 | #include "op-tool.hpp" |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 47 | |
| 48 | using namespace ndn; |
Alexander Afanasyev | 4c9a3d5 | 2017-01-03 17:45:19 -0800 | [diff] [blame] | 49 | using namespace ndn::security; |
| 50 | using namespace ndn::security::v1; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 51 | |
| 52 | std::string ndnsec_helper("\ |
| 53 | help Show all commands.\n\ |
Alexander Afanasyev | cfe0b06 | 2014-05-08 18:26:50 -0700 | [diff] [blame] | 54 | version Show version and exit.\n\ |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 55 | list Display information in PublicInfo.\n\ |
| 56 | get-default Get default setting info.\n\ |
| 57 | set-default Configure default setting.\n\ |
| 58 | key-gen Generate a Key-Signing-Key for an identity.\n\ |
Alexander Afanasyev | ace7445 | 2014-11-30 22:28:24 -0800 | [diff] [blame] | 59 | dsk-gen Generate a Data-Signing-Key for an identity.\n\ |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 60 | sign-req Generate a certificate signing request.\n\ |
| 61 | cert-gen Generate an identity certificate.\n\ |
Yingdi Yu | 5edf97d | 2014-06-15 11:35:12 -0700 | [diff] [blame] | 62 | cert-revoke Revoke an identity certificate.\n\ |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 63 | cert-dump Dump a certificate from PublicInfo.\n\ |
| 64 | cert-install Install a certificate into PublicInfo.\n\ |
Yingdi Yu | 5c1f841 | 2014-03-25 11:49:47 -0700 | [diff] [blame] | 65 | delete Delete identity/key/certificate.\n\ |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 66 | export Export an identity package.\n\ |
| 67 | import Import an identity package.\n\ |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 68 | set-acl Configure ACL of a private key.\n\ |
| 69 | unlock-tpm Unlock Tpm.\n\ |
| 70 | op-tool Operator tool.\n\ |
Yingdi Yu | 05842f2 | 2014-04-15 19:21:56 -0700 | [diff] [blame] | 71 | "); |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 72 | |
Yingdi Yu | 05842f2 | 2014-04-15 19:21:56 -0700 | [diff] [blame] | 73 | int |
Yingdi Yu | 5c1f841 | 2014-03-25 11:49:47 -0700 | [diff] [blame] | 74 | main(int argc, char** argv) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 75 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 76 | if (argc < 2) |
Yingdi Yu | f8fc8de | 2014-02-25 15:45:39 -0800 | [diff] [blame] | 77 | { |
| 78 | std::cerr << ndnsec_helper << std::endl; |
| 79 | return 1; |
| 80 | } |
| 81 | |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 82 | std::string command(argv[1]); |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 83 | |
| 84 | try |
| 85 | { |
Alexander Afanasyev | cfe0b06 | 2014-05-08 18:26:50 -0700 | [diff] [blame] | 86 | if (command == "help") { std::cout << ndnsec_helper << std::endl; } |
| 87 | else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING |
| 88 | << std::endl; } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 89 | else if (command == "list") { return ndnsec_list(argc - 1, argv + 1); } |
| 90 | else if (command == "get-default") { return ndnsec_get_default(argc - 1, argv + 1); } |
| 91 | else if (command == "set-default") { return ndnsec_set_default(argc - 1, argv + 1); } |
| 92 | else if (command == "key-gen") { return ndnsec_key_gen(argc - 1, argv + 1); } |
Alexander Afanasyev | ace7445 | 2014-11-30 22:28:24 -0800 | [diff] [blame] | 93 | else if (command == "dsk-gen") { return ndnsec_dsk_gen(argc - 1, argv + 1); } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 94 | else if (command == "sign-req") { return ndnsec_sign_req(argc - 1, argv + 1); } |
| 95 | else if (command == "cert-gen") { return ndnsec_cert_gen(argc - 1, argv + 1); } |
Yingdi Yu | 5edf97d | 2014-06-15 11:35:12 -0700 | [diff] [blame] | 96 | else if (command == "cert-revoke") { return ndnsec_cert_revoke(argc - 1, argv + 1); } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 97 | else if (command == "cert-dump") { return ndnsec_cert_dump(argc - 1, argv + 1); } |
| 98 | else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); } |
| 99 | else if (command == "delete") { return ndnsec_delete(argc - 1, argv + 1); } |
| 100 | else if (command == "export") { return ndnsec_export(argc - 1, argv + 1); } |
| 101 | else if (command == "import") { return ndnsec_import(argc - 1, argv + 1); } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 102 | else if (command == "set-acl") { return ndnsec_set_acl(argc - 1, argv + 1); } |
| 103 | else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc - 1, argv + 1); } |
| 104 | else if (command == "op-tool") { return ndnsec_op_tool(argc - 1, argv + 1); } |
| 105 | else { |
| 106 | std::cerr << ndnsec_helper << std::endl; |
| 107 | return 1; |
| 108 | } |
| 109 | } |
| 110 | catch (const std::runtime_error& e) |
| 111 | { |
| 112 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 113 | return 1; |
| 114 | } |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 115 | |
| 116 | return 0; |
| 117 | } |