blob: 3ebe2caaa30a0eb0eff1f73af8c2506a21337eba [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
13int
14ndnsec_list(int argc, char** argv)
15{
16 using namespace ndn;
17 namespace po = boost::program_options;
18
19 bool getId = true;
20 bool getKey = false;
21 bool getCert = false;
22
23 po::options_description desc("General Usage\n ndnsec list [-h] [-K|C]\nGeneral options");
24 desc.add_options()
25 ("help,h", "produce help message")
26 ("key,K", "granularity: key")
27 ("cert,C", "granularity: certificate")
28 ;
29
30 po::variables_map vm;
31 po::store(po::parse_command_line(argc, argv, desc), vm);
32 po::notify(vm);
33
34 if (vm.count("help"))
35 {
36 std::cerr << desc << std::endl;;
37 return 0;
38 }
39
40 if (vm.count("cert"))
41 {
42 getCert = true;
43 getId = false;
44 }
45 else if(vm.count("key"))
46 {
47 getKey = true;
48 getId = false;
49 }
50
51 try
52 {
53 KeyChain keyChain;
54
55 if(getId)
56 {
57 std::vector<Name> defaultList;
58 keyChain.getAllIdentities(defaultList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070059 for(size_t i = 0; i < defaultList.size(); i++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080060 std::cout << "* " << defaultList[i] << std::endl;
61 std::vector<Name> otherList;
62 keyChain.getAllIdentities(otherList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070063 for(size_t i = 0; i < otherList.size(); i++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080064 std::cout << " " << otherList[i] << std::endl;
65 return 0;
66 }
67 if(getKey)
68 {
69 std::vector<Name> defaultIdList;
70 keyChain.getAllIdentities(defaultIdList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070071 for(size_t i = 0; i < defaultIdList.size(); i++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080072 {
73 std::cout << "* " << defaultIdList[i] << std::endl;
74 std::vector<Name> defaultKeyList;
75 keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070076 for(size_t j = 0; j < defaultKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080077 std::cout << " +->* " << defaultKeyList[j] << std::endl;
78 std::vector<Name> otherKeyList;
79 keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070080 for(size_t j = 0; j < otherKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080081 std::cout << " +-> " << otherKeyList[j] << std::endl;
82 std::cout << std::endl;
83 }
84 std::vector<Name> otherIdList;
85 keyChain.getAllIdentities(otherIdList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070086 for(size_t i = 0; i < otherIdList.size(); i++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080087 {
88 std::cout << " " << otherIdList[i] << std::endl;
89 std::vector<Name> defaultKeyList;
90 keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070091 for(size_t j = 0; j < defaultKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080092 std::cout << " +->* " << defaultKeyList[j] << std::endl;
93 std::vector<Name> otherKeyList;
94 keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -070095 for(size_t j = 0; j < otherKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -080096 std::cout << " +-> " << otherKeyList[j] << std::endl;
97 std::cout << std::endl;
98 }
99 return 0;
100 }
101 if(getCert)
102 {
103 std::vector<Name> defaultIdList;
104 keyChain.getAllIdentities(defaultIdList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700105 for(size_t i = 0; i < defaultIdList.size(); i++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800106 {
107 std::cout << "* " << defaultIdList[i] << std::endl;
108 std::vector<Name> defaultKeyList;
109 keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700110 for(size_t j = 0; j < defaultKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800111 {
112 std::cout << " +->* " << defaultKeyList[j] << std::endl;
113 std::vector<Name> defaultCertList;
114 keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700115 for(size_t k = 0; k < defaultCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800116 std::cout << " +->* " << defaultCertList[k] << std::endl;
117 std::vector<Name> otherCertList;
118 keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700119 for(size_t k = 0; k < otherCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800120 std::cout << " +-> " << otherCertList[k] << std::endl;
121 }
122 std::vector<Name> otherKeyList;
123 keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700124 for(size_t j = 0; j < otherKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800125 {
126 std::cout << " +-> " << otherKeyList[j] << std::endl;
127 std::vector<Name> defaultCertList;
128 keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700129 for(size_t k = 0; k < defaultCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800130 std::cout << " +->* " << defaultCertList[k] << std::endl;
131 std::vector<Name> otherCertList;
132 keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700133 for(size_t k = 0; k < otherCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800134 std::cout << " +-> " << otherCertList[k] << std::endl;
135 }
136
137 std::cout << std::endl;
138 }
139 std::vector<Name> otherIdList;
140 keyChain.getAllIdentities(otherIdList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700141 for(size_t i = 0; i < otherIdList.size(); i++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800142 {
143 std::cout << " " << otherIdList[i] << std::endl;
144 std::vector<Name> defaultKeyList;
145 keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700146 for(size_t j = 0; j < defaultKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800147 {
148 std::cout << " +->* " << defaultKeyList[j] << std::endl;
149 std::vector<Name> defaultCertList;
150 keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700151 for(size_t k = 0; k < defaultCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800152 std::cout << " +->* " << defaultCertList[k] << std::endl;
153 std::vector<Name> otherCertList;
154 keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700155 for(size_t k = 0; k < otherCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800156 std::cout << " +-> " << otherCertList[k] << std::endl;
157 }
158 std::vector<Name> otherKeyList;
159 keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700160 for(size_t j = 0; j < otherKeyList.size(); j++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800161 {
162 std::cout << " +-> " << otherKeyList[j] << std::endl;
163 std::vector<Name> defaultCertList;
164 keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700165 for(size_t k = 0; k < defaultCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800166 std::cout << " +->* " << defaultCertList[k] << std::endl;
167 std::vector<Name> otherCertList;
168 keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false);
Alexander Afanasyev1dd95c52014-03-22 19:11:36 -0700169 for(size_t k = 0; k < otherCertList.size(); k++)
Yingdi Yu8d7468f2014-02-21 14:49:45 -0800170 std::cout << " +-> " << otherCertList[k] << std::endl;
171 }
172 std::cout << std::endl;
173 }
174 return 0;
175 }
176 return 1;
177 }
178 catch(const SecPublicInfo::Error& e)
179 {
180 std::cerr << "ERROR: " << e.what() << std::endl;
181 return 1;
182 }
183 catch(const SecTpm::Error& e)
184 {
185 std::cerr << "ERROR: " << e.what() << std::endl;
186 return 1;
187 }
188}
189
190#endif //NDNSEC_LIST_HPP