blob: 0406fcaf310c64947134337e9711826fe7c79d16 [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
24#ifndef NDNSEC_LIST_HPP
25#define NDNSEC_LIST_HPP
26
27#include "ndnsec-util.hpp"
28
Yingdi Yub61f5402014-02-26 17:46:11 -080029int
30ndnsec_list(int argc, char** argv)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080031{
32 using namespace ndn;
33 namespace po = boost::program_options;
34
Yingdi Yub61f5402014-02-26 17:46:11 -080035 bool isGetId = true;
36 bool isGetKey = false;
37 bool isGetCert = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080038
Yingdi Yub61f5402014-02-26 17:46:11 -080039 po::options_description description("General Usage\n ndnsec list [-h] [-k|c]\nGeneral options");
40 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080041 ("help,h", "produce help message")
Yingdi Yub61f5402014-02-26 17:46:11 -080042 ("key,k", "granularity: key")
43 ("key2,K", "granularity: key")
44 ("cert,c", "granularity: certificate")
45 ("cert2,C", "granularity: certificate")
Yingdi Yu8d7468f2014-02-21 14:49:45 -080046 ;
47
48 po::variables_map vm;
Yingdi Yub61f5402014-02-26 17:46:11 -080049 try
Yingdi Yu8d7468f2014-02-21 14:49:45 -080050 {
Yingdi Yub61f5402014-02-26 17:46:11 -080051 po::store(po::parse_command_line(argc, argv, description), vm);
52 po::notify(vm);
53 }
54 catch (const std::exception& e)
55 {
56 std::cerr << "ERROR: " << e.what() << std::endl;
57 std::cerr << description << std::endl;
58 return 1;
59 }
60
61 if (vm.count("help") != 0)
62 {
63 std::cerr << description << std::endl;;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080064 return 0;
65 }
66
Yingdi Yub61f5402014-02-26 17:46:11 -080067 if (vm.count("cert") != 0 || vm.count("cert2") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080068 {
Yingdi Yub61f5402014-02-26 17:46:11 -080069 isGetCert = true;
70 isGetId = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080071 }
Yingdi Yub61f5402014-02-26 17:46:11 -080072 else if(vm.count("key") != 0 || vm.count("key2") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080073 {
Yingdi Yub61f5402014-02-26 17:46:11 -080074 isGetKey = true;
75 isGetId = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080076 }
77
Yingdi Yub61f5402014-02-26 17:46:11 -080078 KeyChain keyChain;
79
80 if (isGetId)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080081 {
Yingdi Yub61f5402014-02-26 17:46:11 -080082 std::vector<Name> defaultIdentities;
83 keyChain.getAllIdentities(defaultIdentities, true);
84
85 for (size_t i = 0; i < defaultIdentities.size(); i++)
86 std::cout << "* " << defaultIdentities[i] << std::endl;
87
88 std::vector<Name> otherIdentities;
89 keyChain.getAllIdentities(otherIdentities, false);
90 for (size_t i = 0; i < otherIdentities.size(); i++)
91 std::cout << " " << otherIdentities[i] << std::endl;
92
93 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080094 }
Yingdi Yub61f5402014-02-26 17:46:11 -080095 if (isGetKey)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080096 {
Yingdi Yub61f5402014-02-26 17:46:11 -080097 std::vector<Name> defaultIdentities;
98 keyChain.getAllIdentities(defaultIdentities, true);
99
100 for (size_t i = 0; i < defaultIdentities.size(); i++)
101 {
102 std::cout << "* " << defaultIdentities[i] << std::endl;
103
104 std::vector<Name> defaultKeys;
105 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true);
106
107 for (size_t j = 0; j < defaultKeys.size(); j++)
108 std::cout << " +->* " << defaultKeys[j] << std::endl;
109
110 std::vector<Name> otherKeys;
111 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false);
112
113 for (size_t j = 0; j < otherKeys.size(); j++)
114 std::cout << " +-> " << otherKeys[j] << std::endl;
115
116 std::cout << std::endl;
117 }
118
119 std::vector<Name> otherIdentities;
120 keyChain.getAllIdentities(otherIdentities, false);
121
122 for (size_t i = 0; i < otherIdentities.size(); i++)
123 {
124 std::cout << " " << otherIdentities[i] << std::endl;
125
126 std::vector<Name> defaultKeys;
127 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true);
128
129 for (size_t j = 0; j < defaultKeys.size(); j++)
130 std::cout << " +->* " << defaultKeys[j] << std::endl;
131
132 std::vector<Name> otherKeys;
133 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false);
134
135 for (size_t j = 0; j < otherKeys.size(); j++)
136 std::cout << " +-> " << otherKeys[j] << std::endl;
137
138 std::cout << std::endl;
139 }
140 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800141 }
Yingdi Yub61f5402014-02-26 17:46:11 -0800142 if (isGetCert)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800143 {
Yingdi Yub61f5402014-02-26 17:46:11 -0800144 std::vector<Name> defaultIdentities;
145 keyChain.getAllIdentities(defaultIdentities, true);
146
147 for (size_t i = 0; i < defaultIdentities.size(); i++)
148 {
149 std::cout << "* " << defaultIdentities[i] << std::endl;
150
151 std::vector<Name> defaultKeys;
152 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true);
153
154 for (size_t j = 0; j < defaultKeys.size(); j++)
155 {
156 std::cout << " +->* " << defaultKeys[j] << std::endl;
157
158 std::vector<Name> defaultCertificates;
159 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true);
160
161 for (size_t k = 0; k < defaultCertificates.size(); k++)
162 std::cout << " +->* " << defaultCertificates[k] << std::endl;
163
164 std::vector<Name> otherCertificates;
165 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false);
166
167 for (size_t k = 0; k < otherCertificates.size(); k++)
168 std::cout << " +-> " << otherCertificates[k] << std::endl;
169 }
170
171 std::vector<Name> otherKeys;
172 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false);
173
174 for (size_t j = 0; j < otherKeys.size(); j++)
175 {
176 std::cout << " +-> " << otherKeys[j] << std::endl;
177
178 std::vector<Name> defaultCertificates;
179 keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true);
180
181 for (size_t k = 0; k < defaultCertificates.size(); k++)
182 std::cout << " +->* " << defaultCertificates[k] << std::endl;
183
184 std::vector<Name> otherCertificates;
185 keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false);
186
187 for (size_t k = 0; k < otherCertificates.size(); k++)
188 std::cout << " +-> " << otherCertificates[k] << std::endl;
189 }
190 std::cout << std::endl;
191 }
192
193 std::vector<Name> otherIdentities;
194 keyChain.getAllIdentities(otherIdentities, false);
195
196 for (size_t i = 0; i < otherIdentities.size(); i++)
197 {
198 std::cout << " " << otherIdentities[i] << std::endl;
199
200 std::vector<Name> defaultKeys;
201 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true);
202
203 for (size_t j = 0; j < defaultKeys.size(); j++)
204 {
205 std::cout << " +->* " << defaultKeys[j] << std::endl;
206
207 std::vector<Name> defaultCertificates;
208 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true);
209
210 for (size_t k = 0; k < defaultCertificates.size(); k++)
211 std::cout << " +->* " << defaultCertificates[k] << std::endl;
212
213 std::vector<Name> otherCertificates;
214 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false);
215
216 for (size_t k = 0; k < otherCertificates.size(); k++)
217 std::cout << " +-> " << otherCertificates[k] << std::endl;
218 }
219
220 std::vector<Name> otherKeys;
221 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false);
222
223 for (size_t j = 0; j < otherKeys.size(); j++)
224 {
225 std::cout << " +-> " << otherKeys[j] << std::endl;
226
227 std::vector<Name> defaultCertificates;
228 keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true);
229
230 for (size_t k = 0; k < defaultCertificates.size(); k++)
231 std::cout << " +->* " << defaultCertificates[k] << std::endl;
232
233 std::vector<Name> otherCertificates;
234 keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false);
235
236 for (size_t k = 0; k < otherCertificates.size(); k++)
237 std::cout << " +-> " << otherCertificates[k] << std::endl;
238 }
239
240 std::cout << std::endl;
241 }
242 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800243 }
Yingdi Yub61f5402014-02-26 17:46:11 -0800244 return 1;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800245}
246
247#endif //NDNSEC_LIST_HPP