Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [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 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame^] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/> |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #ifndef NDNSEC_LIST_HPP |
| 25 | #define NDNSEC_LIST_HPP |
| 26 | |
| 27 | #include "ndnsec-util.hpp" |
| 28 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 29 | int |
| 30 | ndnsec_list(int argc, char** argv) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 31 | { |
| 32 | using namespace ndn; |
| 33 | namespace po = boost::program_options; |
| 34 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 35 | bool isGetId = true; |
| 36 | bool isGetKey = false; |
| 37 | bool isGetCert = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 38 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 39 | po::options_description description("General Usage\n ndnsec list [-h] [-k|c]\nGeneral options"); |
| 40 | description.add_options() |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 41 | ("help,h", "produce help message") |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 42 | ("key,k", "granularity: key") |
| 43 | ("key2,K", "granularity: key") |
| 44 | ("cert,c", "granularity: certificate") |
| 45 | ("cert2,C", "granularity: certificate") |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 46 | ; |
| 47 | |
| 48 | po::variables_map vm; |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 49 | try |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 50 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 51 | po::store(po::parse_command_line(argc, argv, description), vm); |
| 52 | po::notify(vm); |
| 53 | } |
| 54 | catch (const std::exception& e) |
| 55 | { |
| 56 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 57 | std::cerr << description << std::endl; |
| 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | if (vm.count("help") != 0) |
| 62 | { |
| 63 | std::cerr << description << std::endl;; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 67 | if (vm.count("cert") != 0 || vm.count("cert2") != 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 68 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 69 | isGetCert = true; |
| 70 | isGetId = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 71 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 72 | else if(vm.count("key") != 0 || vm.count("key2") != 0) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 73 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 74 | isGetKey = true; |
| 75 | isGetId = false; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 78 | KeyChain keyChain; |
| 79 | |
| 80 | if (isGetId) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 81 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 82 | std::vector<Name> defaultIdentities; |
| 83 | keyChain.getAllIdentities(defaultIdentities, true); |
| 84 | |
| 85 | for (size_t i = 0; i < defaultIdentities.size(); i++) |
| 86 | std::cout << "* " << defaultIdentities[i] << std::endl; |
| 87 | |
| 88 | std::vector<Name> otherIdentities; |
| 89 | keyChain.getAllIdentities(otherIdentities, false); |
| 90 | for (size_t i = 0; i < otherIdentities.size(); i++) |
| 91 | std::cout << " " << otherIdentities[i] << std::endl; |
| 92 | |
| 93 | return 0; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 94 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 95 | if (isGetKey) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 96 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 97 | std::vector<Name> defaultIdentities; |
| 98 | keyChain.getAllIdentities(defaultIdentities, true); |
| 99 | |
| 100 | for (size_t i = 0; i < defaultIdentities.size(); i++) |
| 101 | { |
| 102 | std::cout << "* " << defaultIdentities[i] << std::endl; |
| 103 | |
| 104 | std::vector<Name> defaultKeys; |
| 105 | keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true); |
| 106 | |
| 107 | for (size_t j = 0; j < defaultKeys.size(); j++) |
| 108 | std::cout << " +->* " << defaultKeys[j] << std::endl; |
| 109 | |
| 110 | std::vector<Name> otherKeys; |
| 111 | keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false); |
| 112 | |
| 113 | for (size_t j = 0; j < otherKeys.size(); j++) |
| 114 | std::cout << " +-> " << otherKeys[j] << std::endl; |
| 115 | |
| 116 | std::cout << std::endl; |
| 117 | } |
| 118 | |
| 119 | std::vector<Name> otherIdentities; |
| 120 | keyChain.getAllIdentities(otherIdentities, false); |
| 121 | |
| 122 | for (size_t i = 0; i < otherIdentities.size(); i++) |
| 123 | { |
| 124 | std::cout << " " << otherIdentities[i] << std::endl; |
| 125 | |
| 126 | std::vector<Name> defaultKeys; |
| 127 | keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true); |
| 128 | |
| 129 | for (size_t j = 0; j < defaultKeys.size(); j++) |
| 130 | std::cout << " +->* " << defaultKeys[j] << std::endl; |
| 131 | |
| 132 | std::vector<Name> otherKeys; |
| 133 | keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false); |
| 134 | |
| 135 | for (size_t j = 0; j < otherKeys.size(); j++) |
| 136 | std::cout << " +-> " << otherKeys[j] << std::endl; |
| 137 | |
| 138 | std::cout << std::endl; |
| 139 | } |
| 140 | return 0; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 141 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 142 | if (isGetCert) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 143 | { |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 144 | std::vector<Name> defaultIdentities; |
| 145 | keyChain.getAllIdentities(defaultIdentities, true); |
| 146 | |
| 147 | for (size_t i = 0; i < defaultIdentities.size(); i++) |
| 148 | { |
| 149 | std::cout << "* " << defaultIdentities[i] << std::endl; |
| 150 | |
| 151 | std::vector<Name> defaultKeys; |
| 152 | keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], defaultKeys, true); |
| 153 | |
| 154 | for (size_t j = 0; j < defaultKeys.size(); j++) |
| 155 | { |
| 156 | std::cout << " +->* " << defaultKeys[j] << std::endl; |
| 157 | |
| 158 | std::vector<Name> defaultCertificates; |
| 159 | keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true); |
| 160 | |
| 161 | for (size_t k = 0; k < defaultCertificates.size(); k++) |
| 162 | std::cout << " +->* " << defaultCertificates[k] << std::endl; |
| 163 | |
| 164 | std::vector<Name> otherCertificates; |
| 165 | keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false); |
| 166 | |
| 167 | for (size_t k = 0; k < otherCertificates.size(); k++) |
| 168 | std::cout << " +-> " << otherCertificates[k] << std::endl; |
| 169 | } |
| 170 | |
| 171 | std::vector<Name> otherKeys; |
| 172 | keyChain.getAllKeyNamesOfIdentity(defaultIdentities[i], otherKeys, false); |
| 173 | |
| 174 | for (size_t j = 0; j < otherKeys.size(); j++) |
| 175 | { |
| 176 | std::cout << " +-> " << otherKeys[j] << std::endl; |
| 177 | |
| 178 | std::vector<Name> defaultCertificates; |
| 179 | keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true); |
| 180 | |
| 181 | for (size_t k = 0; k < defaultCertificates.size(); k++) |
| 182 | std::cout << " +->* " << defaultCertificates[k] << std::endl; |
| 183 | |
| 184 | std::vector<Name> otherCertificates; |
| 185 | keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false); |
| 186 | |
| 187 | for (size_t k = 0; k < otherCertificates.size(); k++) |
| 188 | std::cout << " +-> " << otherCertificates[k] << std::endl; |
| 189 | } |
| 190 | std::cout << std::endl; |
| 191 | } |
| 192 | |
| 193 | std::vector<Name> otherIdentities; |
| 194 | keyChain.getAllIdentities(otherIdentities, false); |
| 195 | |
| 196 | for (size_t i = 0; i < otherIdentities.size(); i++) |
| 197 | { |
| 198 | std::cout << " " << otherIdentities[i] << std::endl; |
| 199 | |
| 200 | std::vector<Name> defaultKeys; |
| 201 | keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], defaultKeys, true); |
| 202 | |
| 203 | for (size_t j = 0; j < defaultKeys.size(); j++) |
| 204 | { |
| 205 | std::cout << " +->* " << defaultKeys[j] << std::endl; |
| 206 | |
| 207 | std::vector<Name> defaultCertificates; |
| 208 | keyChain.getAllCertificateNamesOfKey(defaultKeys[j], defaultCertificates, true); |
| 209 | |
| 210 | for (size_t k = 0; k < defaultCertificates.size(); k++) |
| 211 | std::cout << " +->* " << defaultCertificates[k] << std::endl; |
| 212 | |
| 213 | std::vector<Name> otherCertificates; |
| 214 | keyChain.getAllCertificateNamesOfKey(defaultKeys[j], otherCertificates, false); |
| 215 | |
| 216 | for (size_t k = 0; k < otherCertificates.size(); k++) |
| 217 | std::cout << " +-> " << otherCertificates[k] << std::endl; |
| 218 | } |
| 219 | |
| 220 | std::vector<Name> otherKeys; |
| 221 | keyChain.getAllKeyNamesOfIdentity(otherIdentities[i], otherKeys, false); |
| 222 | |
| 223 | for (size_t j = 0; j < otherKeys.size(); j++) |
| 224 | { |
| 225 | std::cout << " +-> " << otherKeys[j] << std::endl; |
| 226 | |
| 227 | std::vector<Name> defaultCertificates; |
| 228 | keyChain.getAllCertificateNamesOfKey(otherKeys[j], defaultCertificates, true); |
| 229 | |
| 230 | for (size_t k = 0; k < defaultCertificates.size(); k++) |
| 231 | std::cout << " +->* " << defaultCertificates[k] << std::endl; |
| 232 | |
| 233 | std::vector<Name> otherCertificates; |
| 234 | keyChain.getAllCertificateNamesOfKey(otherKeys[j], otherCertificates, false); |
| 235 | |
| 236 | for (size_t k = 0; k < otherCertificates.size(); k++) |
| 237 | std::cout << " +-> " << otherCertificates[k] << std::endl; |
| 238 | } |
| 239 | |
| 240 | std::cout << std::endl; |
| 241 | } |
| 242 | return 0; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 243 | } |
Yingdi Yu | b61f540 | 2014-02-26 17:46:11 -0800 | [diff] [blame] | 244 | return 1; |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | #endif //NDNSEC_LIST_HPP |