blob: db796c15469ad3a09878ed8d9cca3579a43014a2 [file] [log] [blame]
Yingdi Yu8d7468f2014-02-21 14:49:45 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2013, Regents of the University of California
4 * BSD license, See the LICENSE file for more information
5 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
6 */
7
8#ifndef NDNSEC_LIST_HPP
9#define NDNSEC_LIST_HPP
10
11#include "ndnsec-util.hpp"
12
Yingdi Yub61f5402014-02-26 17:46:11 -080013int
14ndnsec_list(int argc, char** argv)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080015{
16 using namespace ndn;
17 namespace po = boost::program_options;
18
Yingdi Yub61f5402014-02-26 17:46:11 -080019 bool isGetId = true;
20 bool isGetKey = false;
21 bool isGetCert = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080022
Yingdi Yub61f5402014-02-26 17:46:11 -080023 po::options_description description("General Usage\n ndnsec list [-h] [-k|c]\nGeneral options");
24 description.add_options()
Yingdi Yu8d7468f2014-02-21 14:49:45 -080025 ("help,h", "produce help message")
Yingdi Yub61f5402014-02-26 17:46:11 -080026 ("key,k", "granularity: key")
27 ("key2,K", "granularity: key")
28 ("cert,c", "granularity: certificate")
29 ("cert2,C", "granularity: certificate")
Yingdi Yu8d7468f2014-02-21 14:49:45 -080030 ;
31
32 po::variables_map vm;
Yingdi Yub61f5402014-02-26 17:46:11 -080033 try
Yingdi Yu8d7468f2014-02-21 14:49:45 -080034 {
Yingdi Yub61f5402014-02-26 17:46:11 -080035 po::store(po::parse_command_line(argc, argv, description), vm);
36 po::notify(vm);
37 }
38 catch (const std::exception& e)
39 {
40 std::cerr << "ERROR: " << e.what() << std::endl;
41 std::cerr << description << std::endl;
42 return 1;
43 }
44
45 if (vm.count("help") != 0)
46 {
47 std::cerr << description << std::endl;;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080048 return 0;
49 }
50
Yingdi Yub61f5402014-02-26 17:46:11 -080051 if (vm.count("cert") != 0 || vm.count("cert2") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080052 {
Yingdi Yub61f5402014-02-26 17:46:11 -080053 isGetCert = true;
54 isGetId = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080055 }
Yingdi Yub61f5402014-02-26 17:46:11 -080056 else if(vm.count("key") != 0 || vm.count("key2") != 0)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080057 {
Yingdi Yub61f5402014-02-26 17:46:11 -080058 isGetKey = true;
59 isGetId = false;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080060 }
61
Yingdi Yub61f5402014-02-26 17:46:11 -080062 KeyChain keyChain;
63
64 if (isGetId)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080065 {
Yingdi Yub61f5402014-02-26 17:46:11 -080066 std::vector<Name> defaultIdentities;
67 keyChain.getAllIdentities(defaultIdentities, true);
68
69 for (size_t i = 0; i < defaultIdentities.size(); i++)
70 std::cout << "* " << defaultIdentities[i] << std::endl;
71
72 std::vector<Name> otherIdentities;
73 keyChain.getAllIdentities(otherIdentities, false);
74 for (size_t i = 0; i < otherIdentities.size(); i++)
75 std::cout << " " << otherIdentities[i] << std::endl;
76
77 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -080078 }
Yingdi Yub61f5402014-02-26 17:46:11 -080079 if (isGetKey)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080080 {
Yingdi Yub61f5402014-02-26 17:46:11 -080081 std::vector<Name> defaultIdentities;
82 keyChain.getAllIdentities(defaultIdentities, true);
83
84 for (size_t i = 0; i < defaultIdentities.size(); i++)
85 {
86 std::cout << "* " << defaultIdentities[i] << std::endl;
87
88 std::vector<Name> defaultKeys;
89 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true);
90
91 for (size_t j = 0; j < defaultKeys.size(); j++)
92 std::cout << " +->* " << defaultKeys[j] << std::endl;
93
94 std::vector<Name> otherKeys;
95 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false);
96
97 for (size_t j = 0; j < otherKeys.size(); j++)
98 std::cout << " +-> " << otherKeys[j] << std::endl;
99
100 std::cout << std::endl;
101 }
102
103 std::vector<Name> otherIdentities;
104 keyChain.getAllIdentities(otherIdentities, false);
105
106 for (size_t i = 0; i < otherIdentities.size(); i++)
107 {
108 std::cout << " " << otherIdentities[i] << std::endl;
109
110 std::vector<Name> defaultKeys;
111 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true);
112
113 for (size_t j = 0; j < defaultKeys.size(); j++)
114 std::cout << " +->* " << defaultKeys[j] << std::endl;
115
116 std::vector<Name> otherKeys;
117 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false);
118
119 for (size_t j = 0; j < otherKeys.size(); j++)
120 std::cout << " +-> " << otherKeys[j] << std::endl;
121
122 std::cout << std::endl;
123 }
124 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800125 }
Yingdi Yub61f5402014-02-26 17:46:11 -0800126 if (isGetCert)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800127 {
Yingdi Yub61f5402014-02-26 17:46:11 -0800128 std::vector<Name> defaultIdentities;
129 keyChain.getAllIdentities(defaultIdentities, true);
130
131 for (size_t i = 0; i < defaultIdentities.size(); i++)
132 {
133 std::cout << "* " << defaultIdentities[i] << std::endl;
134
135 std::vector<Name> defaultKeys;
136 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true);
137
138 for (size_t j = 0; j < defaultKeys.size(); j++)
139 {
140 std::cout << " +->* " << defaultKeys[j] << std::endl;
141
142 std::vector<Name> defaultCertificates;
143 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true);
144
145 for (size_t k = 0; k < defaultCertificates.size(); k++)
146 std::cout << " +->* " << defaultCertificates[k] << std::endl;
147
148 std::vector<Name> otherCertificates;
149 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false);
150
151 for (size_t k = 0; k < otherCertificates.size(); k++)
152 std::cout << " +-> " << otherCertificates[k] << std::endl;
153 }
154
155 std::vector<Name> otherKeys;
156 keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false);
157
158 for (size_t j = 0; j < otherKeys.size(); j++)
159 {
160 std::cout << " +-> " << otherKeys[j] << std::endl;
161
162 std::vector<Name> defaultCertificates;
163 keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true);
164
165 for (size_t k = 0; k < defaultCertificates.size(); k++)
166 std::cout << " +->* " << defaultCertificates[k] << std::endl;
167
168 std::vector<Name> otherCertificates;
169 keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false);
170
171 for (size_t k = 0; k < otherCertificates.size(); k++)
172 std::cout << " +-> " << otherCertificates[k] << std::endl;
173 }
174 std::cout << std::endl;
175 }
176
177 std::vector<Name> otherIdentities;
178 keyChain.getAllIdentities(otherIdentities, false);
179
180 for (size_t i = 0; i < otherIdentities.size(); i++)
181 {
182 std::cout << " " << otherIdentities[i] << std::endl;
183
184 std::vector<Name> defaultKeys;
185 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true);
186
187 for (size_t j = 0; j < defaultKeys.size(); j++)
188 {
189 std::cout << " +->* " << defaultKeys[j] << std::endl;
190
191 std::vector<Name> defaultCertificates;
192 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true);
193
194 for (size_t k = 0; k < defaultCertificates.size(); k++)
195 std::cout << " +->* " << defaultCertificates[k] << std::endl;
196
197 std::vector<Name> otherCertificates;
198 keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false);
199
200 for (size_t k = 0; k < otherCertificates.size(); k++)
201 std::cout << " +-> " << otherCertificates[k] << std::endl;
202 }
203
204 std::vector<Name> otherKeys;
205 keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false);
206
207 for (size_t j = 0; j < otherKeys.size(); j++)
208 {
209 std::cout << " +-> " << otherKeys[j] << std::endl;
210
211 std::vector<Name> defaultCertificates;
212 keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true);
213
214 for (size_t k = 0; k < defaultCertificates.size(); k++)
215 std::cout << " +->* " << defaultCertificates[k] << std::endl;
216
217 std::vector<Name> otherCertificates;
218 keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false);
219
220 for (size_t k = 0; k < otherCertificates.size(); k++)
221 std::cout << " +-> " << otherCertificates[k] << std::endl;
222 }
223
224 std::cout << std::endl;
225 }
226 return 0;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800227 }
Yingdi Yub61f5402014-02-26 17:46:11 -0800228 return 1;
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800229}
230
231#endif //NDNSEC_LIST_HPP