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 | |
| 13 | int |
| 14 | ndnsec_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); |
| 59 | for(int i = 0; i < defaultList.size(); i++) |
| 60 | std::cout << "* " << defaultList[i] << std::endl; |
| 61 | std::vector<Name> otherList; |
| 62 | keyChain.getAllIdentities(otherList, false); |
| 63 | for(int i = 0; i < otherList.size(); i++) |
| 64 | std::cout << " " << otherList[i] << std::endl; |
| 65 | return 0; |
| 66 | } |
| 67 | if(getKey) |
| 68 | { |
| 69 | std::vector<Name> defaultIdList; |
| 70 | keyChain.getAllIdentities(defaultIdList, true); |
| 71 | for(int i = 0; i < defaultIdList.size(); i++) |
| 72 | { |
| 73 | std::cout << "* " << defaultIdList[i] << std::endl; |
| 74 | std::vector<Name> defaultKeyList; |
| 75 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true); |
| 76 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 77 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 78 | std::vector<Name> otherKeyList; |
| 79 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false); |
| 80 | for(int j = 0; j < otherKeyList.size(); j++) |
| 81 | std::cout << " +-> " << otherKeyList[j] << std::endl; |
| 82 | std::cout << std::endl; |
| 83 | } |
| 84 | std::vector<Name> otherIdList; |
| 85 | keyChain.getAllIdentities(otherIdList, false); |
| 86 | for(int i = 0; i < otherIdList.size(); i++) |
| 87 | { |
| 88 | std::cout << " " << otherIdList[i] << std::endl; |
| 89 | std::vector<Name> defaultKeyList; |
| 90 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true); |
| 91 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 92 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 93 | std::vector<Name> otherKeyList; |
| 94 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false); |
| 95 | for(int j = 0; j < otherKeyList.size(); j++) |
| 96 | 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); |
| 105 | for(int i = 0; i < defaultIdList.size(); i++) |
| 106 | { |
| 107 | std::cout << "* " << defaultIdList[i] << std::endl; |
| 108 | std::vector<Name> defaultKeyList; |
| 109 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true); |
| 110 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 111 | { |
| 112 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 113 | std::vector<Name> defaultCertList; |
| 114 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true); |
| 115 | for(int k = 0; k < defaultCertList.size(); k++) |
| 116 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 117 | std::vector<Name> otherCertList; |
| 118 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false); |
| 119 | for(int k = 0; k < otherCertList.size(); k++) |
| 120 | std::cout << " +-> " << otherCertList[k] << std::endl; |
| 121 | } |
| 122 | std::vector<Name> otherKeyList; |
| 123 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false); |
| 124 | for(int j = 0; j < otherKeyList.size(); j++) |
| 125 | { |
| 126 | std::cout << " +-> " << otherKeyList[j] << std::endl; |
| 127 | std::vector<Name> defaultCertList; |
| 128 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true); |
| 129 | for(int k = 0; k < defaultCertList.size(); k++) |
| 130 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 131 | std::vector<Name> otherCertList; |
| 132 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false); |
| 133 | for(int k = 0; k < otherCertList.size(); k++) |
| 134 | std::cout << " +-> " << otherCertList[k] << std::endl; |
| 135 | } |
| 136 | |
| 137 | std::cout << std::endl; |
| 138 | } |
| 139 | std::vector<Name> otherIdList; |
| 140 | keyChain.getAllIdentities(otherIdList, false); |
| 141 | for(int i = 0; i < otherIdList.size(); i++) |
| 142 | { |
| 143 | std::cout << " " << otherIdList[i] << std::endl; |
| 144 | std::vector<Name> defaultKeyList; |
| 145 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true); |
| 146 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 147 | { |
| 148 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 149 | std::vector<Name> defaultCertList; |
| 150 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true); |
| 151 | for(int k = 0; k < defaultCertList.size(); k++) |
| 152 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 153 | std::vector<Name> otherCertList; |
| 154 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false); |
| 155 | for(int k = 0; k < otherCertList.size(); k++) |
| 156 | std::cout << " +-> " << otherCertList[k] << std::endl; |
| 157 | } |
| 158 | std::vector<Name> otherKeyList; |
| 159 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false); |
| 160 | for(int j = 0; j < otherKeyList.size(); j++) |
| 161 | { |
| 162 | std::cout << " +-> " << otherKeyList[j] << std::endl; |
| 163 | std::vector<Name> defaultCertList; |
| 164 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true); |
| 165 | for(int k = 0; k < defaultCertList.size(); k++) |
| 166 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 167 | std::vector<Name> otherCertList; |
| 168 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false); |
| 169 | for(int k = 0; k < otherCertList.size(); k++) |
| 170 | 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 |