blob: 1e72ac0597a0e64c7a03e33ed49f2565d545a4be [file] [log] [blame]
Yingdi Yu8d7468f2014-02-21 14:49:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07002/**
3 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
11 *
12 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu8d7468f2014-02-21 14:49:45 -080013 */
14
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -070015#include "version.hpp"
Yingdi Yu8d7468f2014-02-21 14:49:45 -080016#include "ndnsec-util.hpp"
17#include "ndnsec-list.hpp"
18#include "ndnsec-get-default.hpp"
19#include "ndnsec-set-default.hpp"
20#include "ndnsec-key-gen.hpp"
21#include "ndnsec-dsk-gen.hpp"
22#include "ndnsec-sign-req.hpp"
23#include "ndnsec-cert-gen.hpp"
24#include "ndnsec-cert-dump.hpp"
25#include "ndnsec-cert-install.hpp"
26#include "ndnsec-export.hpp"
27#include "ndnsec-import.hpp"
28#include "ndnsec-delete.hpp"
29#include "ndnsec-sig-verify.hpp"
30#include "ndnsec-set-acl.hpp"
31#include "ndnsec-unlock-tpm.hpp"
32#include "ndnsec-op-tool.hpp"
33
34using namespace ndn;
35
36std::string ndnsec_helper("\
37 help Show all commands.\n\
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -070038 version Show version and exit.\n\
Yingdi Yu8d7468f2014-02-21 14:49:45 -080039 list Display information in PublicInfo.\n\
40 get-default Get default setting info.\n\
41 set-default Configure default setting.\n\
42 key-gen Generate a Key-Signing-Key for an identity.\n\
Yingdi Yu8d7468f2014-02-21 14:49:45 -080043 sign-req Generate a certificate signing request.\n\
44 cert-gen Generate an identity certificate.\n\
45 cert-dump Dump a certificate from PublicInfo.\n\
46 cert-install Install a certificate into PublicInfo.\n\
Yingdi Yu5c1f8412014-03-25 11:49:47 -070047 delete Delete identity/key/certificate.\n\
Yingdi Yu8d7468f2014-02-21 14:49:45 -080048 export Export an identity package.\n\
49 import Import an identity package.\n\
50 sig-verify Verify the signature of a Data packet.\n\
51 set-acl Configure ACL of a private key.\n\
52 unlock-tpm Unlock Tpm.\n\
53 op-tool Operator tool.\n\
Yingdi Yu05842f22014-04-15 19:21:56 -070054");
Yingdi Yu8d7468f2014-02-21 14:49:45 -080055
Yingdi Yu05842f22014-04-15 19:21:56 -070056int
Yingdi Yu5c1f8412014-03-25 11:49:47 -070057main(int argc, char** argv)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080058{
Yingdi Yub61f5402014-02-26 17:46:11 -080059 if (argc < 2)
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080060 {
61 std::cerr << ndnsec_helper << std::endl;
62 return 1;
63 }
64
Yingdi Yu8d7468f2014-02-21 14:49:45 -080065 std::string command(argv[1]);
Yingdi Yub61f5402014-02-26 17:46:11 -080066
67 try
68 {
Alexander Afanasyevcfe0b062014-05-08 18:26:50 -070069 if (command == "help") { std::cout << ndnsec_helper << std::endl; }
70 else if (command == "version") { std::cout << NDN_CXX_VERSION_BUILD_STRING
71 << std::endl; }
Yingdi Yub61f5402014-02-26 17:46:11 -080072 else if (command == "list") { return ndnsec_list(argc - 1, argv + 1); }
73 else if (command == "get-default") { return ndnsec_get_default(argc - 1, argv + 1); }
74 else if (command == "set-default") { return ndnsec_set_default(argc - 1, argv + 1); }
75 else if (command == "key-gen") { return ndnsec_key_gen(argc - 1, argv + 1); }
76 else if (command == "sign-req") { return ndnsec_sign_req(argc - 1, argv + 1); }
77 else if (command == "cert-gen") { return ndnsec_cert_gen(argc - 1, argv + 1); }
78 else if (command == "cert-dump") { return ndnsec_cert_dump(argc - 1, argv + 1); }
79 else if (command == "cert-install") { return ndnsec_cert_install(argc - 1, argv + 1); }
80 else if (command == "delete") { return ndnsec_delete(argc - 1, argv + 1); }
81 else if (command == "export") { return ndnsec_export(argc - 1, argv + 1); }
82 else if (command == "import") { return ndnsec_import(argc - 1, argv + 1); }
83 else if (command == "sig-verify") { return ndnsec_sig_verify(argc - 1, argv + 1); }
84 else if (command == "set-acl") { return ndnsec_set_acl(argc - 1, argv + 1); }
85 else if (command == "unlock-tpm") { return ndnsec_unlock_tpm(argc - 1, argv + 1); }
86 else if (command == "op-tool") { return ndnsec_op_tool(argc - 1, argv + 1); }
87 else {
88 std::cerr << ndnsec_helper << std::endl;
89 return 1;
90 }
91 }
92 catch (const std::runtime_error& e)
93 {
94 std::cerr << "ERROR: " << e.what() << std::endl;
95 return 1;
96 }
Yingdi Yu8d7468f2014-02-21 14:49:45 -080097
98 return 0;
99}