Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 1 | /* -*- 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 Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 13 | int |
| 14 | ndnsec_list(int argc, char** argv) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 15 | { |
| 16 | using namespace ndn; |
| 17 | namespace po = boost::program_options; |
| 18 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 19 | bool isGetId = true; |
| 20 | bool isGetKey = false; |
| 21 | bool isGetCert = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 22 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 23 | po::options_description description("General Usage\n ndnsec list [-h] [-k|c]\nGeneral options"); |
| 24 | description.add_options() |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 25 | ("help,h", "produce help message") |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 26 | ("key,k", "granularity: key") |
| 27 | ("key2,K", "granularity: key") |
| 28 | ("cert,c", "granularity: certificate") |
| 29 | ("cert2,C", "granularity: certificate") |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 30 | ; |
| 31 | |
| 32 | po::variables_map vm; |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 33 | try |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 34 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 35 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 51 | if (vm.count("cert") != 0 || vm.count("cert2") != 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 52 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 53 | isGetCert = true; |
| 54 | isGetId = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 55 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 56 | else if(vm.count("key") != 0 || vm.count("key2") != 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 57 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 58 | isGetKey = true; |
| 59 | isGetId = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 62 | KeyChain keyChain; |
| 63 | |
| 64 | if (isGetId) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 65 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 66 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 78 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 79 | if (isGetKey) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 80 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 81 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 125 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 126 | if (isGetCert) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 127 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 128 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 227 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame^] | 228 | return 1; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | #endif //NDNSEC_LIST_HPP |