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); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 59 | for(size_t i = 0; i < defaultList.size(); i++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 60 | std::cout << "* " << defaultList[i] << std::endl; |
| 61 | std::vector<Name> otherList; |
| 62 | keyChain.getAllIdentities(otherList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 63 | for(size_t i = 0; i < otherList.size(); i++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 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); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 71 | for(size_t i = 0; i < defaultIdList.size(); i++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 72 | { |
| 73 | std::cout << "* " << defaultIdList[i] << std::endl; |
| 74 | std::vector<Name> defaultKeyList; |
| 75 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 76 | for(size_t j = 0; j < defaultKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 77 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 78 | std::vector<Name> otherKeyList; |
| 79 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 80 | for(size_t j = 0; j < otherKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 81 | std::cout << " +-> " << otherKeyList[j] << std::endl; |
| 82 | std::cout << std::endl; |
| 83 | } |
| 84 | std::vector<Name> otherIdList; |
| 85 | keyChain.getAllIdentities(otherIdList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 86 | for(size_t i = 0; i < otherIdList.size(); i++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 87 | { |
| 88 | std::cout << " " << otherIdList[i] << std::endl; |
| 89 | std::vector<Name> defaultKeyList; |
| 90 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 91 | for(size_t j = 0; j < defaultKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 92 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 93 | std::vector<Name> otherKeyList; |
| 94 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 95 | for(size_t j = 0; j < otherKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 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); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 105 | for(size_t i = 0; i < defaultIdList.size(); i++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 106 | { |
| 107 | std::cout << "* " << defaultIdList[i] << std::endl; |
| 108 | std::vector<Name> defaultKeyList; |
| 109 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 110 | for(size_t j = 0; j < defaultKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 111 | { |
| 112 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 113 | std::vector<Name> defaultCertList; |
| 114 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 115 | for(size_t k = 0; k < defaultCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 116 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 117 | std::vector<Name> otherCertList; |
| 118 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 119 | for(size_t k = 0; k < otherCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 120 | std::cout << " +-> " << otherCertList[k] << std::endl; |
| 121 | } |
| 122 | std::vector<Name> otherKeyList; |
| 123 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 124 | for(size_t j = 0; j < otherKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 125 | { |
| 126 | std::cout << " +-> " << otherKeyList[j] << std::endl; |
| 127 | std::vector<Name> defaultCertList; |
| 128 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 129 | for(size_t k = 0; k < defaultCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 130 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 131 | std::vector<Name> otherCertList; |
| 132 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 133 | for(size_t k = 0; k < otherCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 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); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 141 | for(size_t i = 0; i < otherIdList.size(); i++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 142 | { |
| 143 | std::cout << " " << otherIdList[i] << std::endl; |
| 144 | std::vector<Name> defaultKeyList; |
| 145 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 146 | for(size_t j = 0; j < defaultKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 147 | { |
| 148 | std::cout << " +->* " << defaultKeyList[j] << std::endl; |
| 149 | std::vector<Name> defaultCertList; |
| 150 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 151 | for(size_t k = 0; k < defaultCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 152 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 153 | std::vector<Name> otherCertList; |
| 154 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 155 | for(size_t k = 0; k < otherCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 156 | std::cout << " +-> " << otherCertList[k] << std::endl; |
| 157 | } |
| 158 | std::vector<Name> otherKeyList; |
| 159 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 160 | for(size_t j = 0; j < otherKeyList.size(); j++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 161 | { |
| 162 | std::cout << " +-> " << otherKeyList[j] << std::endl; |
| 163 | std::vector<Name> defaultCertList; |
| 164 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 165 | for(size_t k = 0; k < defaultCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 166 | std::cout << " +->* " << defaultCertList[k] << std::endl; |
| 167 | std::vector<Name> otherCertList; |
| 168 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false); |
Alexander Afanasyev | 1dd95c5 | 2014-03-22 19:11:36 -0700 | [diff] [blame^] | 169 | for(size_t k = 0; k < otherCertList.size(); k++) |
Yingdi Yu | 8d7468f | 2014-02-21 14:49:45 -0800 | [diff] [blame] | 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 |