Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 2 | /** |
| 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NDNSEC_LIST_HPP |
| 16 | #define NDNSEC_LIST_HPP |
| 17 | |
| 18 | #include "ndnsec-util.hpp" |
| 19 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 20 | int |
| 21 | ndnsec_list(int argc, char** argv) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 22 | { |
| 23 | using namespace ndn; |
| 24 | namespace po = boost::program_options; |
| 25 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 26 | bool isGetId = true; |
| 27 | bool isGetKey = false; |
| 28 | bool isGetCert = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 29 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 30 | po::options_description description("General Usage\n ndnsec list [-h] [-k|c]\nGeneral options"); |
| 31 | description.add_options() |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 32 | ("help,h", "produce help message") |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 33 | ("key,k", "granularity: key") |
| 34 | ("key2,K", "granularity: key") |
| 35 | ("cert,c", "granularity: certificate") |
| 36 | ("cert2,C", "granularity: certificate") |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 37 | ; |
| 38 | |
| 39 | po::variables_map vm; |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 40 | try |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 41 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 42 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 58 | if (vm.count("cert") != 0 || vm.count("cert2") != 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 59 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 60 | isGetCert = true; |
| 61 | isGetId = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 62 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 63 | else if(vm.count("key") != 0 || vm.count("key2") != 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 64 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 65 | isGetKey = true; |
| 66 | isGetId = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 69 | KeyChain keyChain; |
| 70 | |
| 71 | if (isGetId) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 72 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 73 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 85 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 86 | if (isGetKey) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 87 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 88 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 132 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 133 | if (isGetCert) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 134 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 135 | 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 Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 234 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 235 | return 1; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | #endif //NDNSEC_LIST_HPP |