blob: 466aeedcba66874439a445989cd4ad8ab2ceaf85 [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
15#ifndef NDNSEC_LIST_HPP
16#define NDNSEC_LIST_HPP
17
18#include "ndnsec-util.hpp"
19
Yingdi Yub61f5402014-02-26 17:46:11 -080020int
21ndnsec_list(int argc, char** argv)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080022{
23 using namespace ndn;
24 namespace po = boost::program_options;
25
Yingdi Yub61f5402014-02-26 17:46:11 -080026 bool isGetId = true;
27 bool isGetKey = false;
28 bool isGetCert = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080029
Yingdi Yub61f5402014-02-26 17:46:11 -080030 po::options_description description("General Usage\n ndnsec list [-h] [-k|c]\nGeneral options");
31 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080032 ("help,h", "produce help message")
Yingdi Yub61f5402014-02-26 17:46:11 -080033 ("key,k", "granularity: key")
34 ("key2,K", "granularity: key")
35 ("cert,c", "granularity: certificate")
36 ("cert2,C", "granularity: certificate")
Yingdi Yu8d7468f2014-02-21 14:49:45 -080037 ;
38
39 po::variables_map vm;
Yingdi Yub61f5402014-02-26 17:46:11 -080040 try
Yingdi Yu8d7468f2014-02-21 14:49:45 -080041 {
Yingdi Yub61f5402014-02-26 17:46:11 -080042 po::store(po::parse_command_line(argc, argv, description), vm);
43 po::notify(vm);
44 }
45 catch (const std::exception& e)
46 {
47 std::cerr << "ERROR: " << e.what() << std::endl;
48 std::cerr << description << std::endl;
49 return 1;
50 }
51
52 if (vm.count("help") != 0)
53 {
54 std::cerr << description << std::endl;;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080055 return 0;
56 }
57
Yingdi Yub61f5402014-02-26 17:46:11 -080058 if (vm.count("cert") != 0 || vm.count("cert2") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080059 {
Yingdi Yub61f5402014-02-26 17:46:11 -080060 isGetCert = true;
61 isGetId = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080062 }
Yingdi Yub61f5402014-02-26 17:46:11 -080063 else if(vm.count("key") != 0 || vm.count("key2") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080064 {
Yingdi Yub61f5402014-02-26 17:46:11 -080065 isGetKey = true;
66 isGetId = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080067 }
68
Yingdi Yub61f5402014-02-26 17:46:11 -080069 KeyChain keyChain;
70
71 if (isGetId)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080072 {
Yingdi Yub61f5402014-02-26 17:46:11 -080073 std::vector<Name> defaultIdentities;
74 keyChain.getAllIdentities(defaultIdentities, true);
75
76 for (size_t i = 0; i < defaultIdentities.size(); i++)
77 std::cout << "* " << defaultIdentities[i] << std::endl;
78
79 std::vector<Name> otherIdentities;
80 keyChain.getAllIdentities(otherIdentities, false);
81 for (size_t i = 0; i < otherIdentities.size(); i++)
82 std::cout << " " << otherIdentities[i] << std::endl;
83
84 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080085 }
Yingdi Yub61f5402014-02-26 17:46:11 -080086 if (isGetKey)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080087 {
Yingdi Yub61f5402014-02-26 17:46:11 -080088 std::vector<Name> defaultIdentities;
89 keyChain.getAllIdentities(defaultIdentities, true);
90
91 for (size_t i = 0; i < defaultIdentities.size(); i++)
92 {
93 std::cout << "* " << defaultIdentities[i] << std::endl;
94
95 std::vector<Name> defaultKeys;
96 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true);
97
98 for (size_t j = 0; j < defaultKeys.size(); j++)
99 std::cout << " +->* " << defaultKeys[j] << std::endl;
100
101 std::vector<Name> otherKeys;
102 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false);
103
104 for (size_t j = 0; j < otherKeys.size(); j++)
105 std::cout << " +-> " << otherKeys[j] << std::endl;
106
107 std::cout << std::endl;
108 }
109
110 std::vector<Name> otherIdentities;
111 keyChain.getAllIdentities(otherIdentities, false);
112
113 for (size_t i = 0; i < otherIdentities.size(); i++)
114 {
115 std::cout << " " << otherIdentities[i] << std::endl;
116
117 std::vector<Name> defaultKeys;
118 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true);
119
120 for (size_t j = 0; j < defaultKeys.size(); j++)
121 std::cout << " +->* " << defaultKeys[j] << std::endl;
122
123 std::vector<Name> otherKeys;
124 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false);
125
126 for (size_t j = 0; j < otherKeys.size(); j++)
127 std::cout << " +-> " << otherKeys[j] << std::endl;
128
129 std::cout << std::endl;
130 }
131 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800132 }
Yingdi Yub61f5402014-02-26 17:46:11 -0800133 if (isGetCert)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800134 {
Yingdi Yub61f5402014-02-26 17:46:11 -0800135 std::vector<Name> defaultIdentities;
136 keyChain.getAllIdentities(defaultIdentities, true);
137
138 for (size_t i = 0; i < defaultIdentities.size(); i++)
139 {
140 std::cout << "* " << defaultIdentities[i] << std::endl;
141
142 std::vector<Name> defaultKeys;
143 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true);
144
145 for (size_t j = 0; j < defaultKeys.size(); j++)
146 {
147 std::cout << " +->* " << defaultKeys[j] << std::endl;
148
149 std::vector<Name> defaultCertificates;
150 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true);
151
152 for (size_t k = 0; k < defaultCertificates.size(); k++)
153 std::cout << " +->* " << defaultCertificates[k] << std::endl;
154
155 std::vector<Name> otherCertificates;
156 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false);
157
158 for (size_t k = 0; k < otherCertificates.size(); k++)
159 std::cout << " +-> " << otherCertificates[k] << std::endl;
160 }
161
162 std::vector<Name> otherKeys;
163 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false);
164
165 for (size_t j = 0; j < otherKeys.size(); j++)
166 {
167 std::cout << " +-> " << otherKeys[j] << std::endl;
168
169 std::vector<Name> defaultCertificates;
170 keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true);
171
172 for (size_t k = 0; k < defaultCertificates.size(); k++)
173 std::cout << " +->* " << defaultCertificates[k] << std::endl;
174
175 std::vector<Name> otherCertificates;
176 keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false);
177
178 for (size_t k = 0; k < otherCertificates.size(); k++)
179 std::cout << " +-> " << otherCertificates[k] << std::endl;
180 }
181 std::cout << std::endl;
182 }
183
184 std::vector<Name> otherIdentities;
185 keyChain.getAllIdentities(otherIdentities, false);
186
187 for (size_t i = 0; i < otherIdentities.size(); i++)
188 {
189 std::cout << " " << otherIdentities[i] << std::endl;
190
191 std::vector<Name> defaultKeys;
192 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true);
193
194 for (size_t j = 0; j < defaultKeys.size(); j++)
195 {
196 std::cout << " +->* " << defaultKeys[j] << std::endl;
197
198 std::vector<Name> defaultCertificates;
199 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true);
200
201 for (size_t k = 0; k < defaultCertificates.size(); k++)
202 std::cout << " +->* " << defaultCertificates[k] << std::endl;
203
204 std::vector<Name> otherCertificates;
205 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false);
206
207 for (size_t k = 0; k < otherCertificates.size(); k++)
208 std::cout << " +-> " << otherCertificates[k] << std::endl;
209 }
210
211 std::vector<Name> otherKeys;
212 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false);
213
214 for (size_t j = 0; j < otherKeys.size(); j++)
215 {
216 std::cout << " +-> " << otherKeys[j] << std::endl;
217
218 std::vector<Name> defaultCertificates;
219 keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true);
220
221 for (size_t k = 0; k < defaultCertificates.size(); k++)
222 std::cout << " +->* " << defaultCertificates[k] << std::endl;
223
224 std::vector<Name> otherCertificates;
225 keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false);
226
227 for (size_t k = 0; k < otherCertificates.size(); k++)
228 std::cout << " +-> " << otherCertificates[k] << std::endl;
229 }
230
231 std::cout << std::endl;
232 }
233 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800234 }
Yingdi Yub61f5402014-02-26 17:46:11 -0800235 return 1;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800236}
237
238#endif //NDNSEC_LIST_HPP