Yingdi Yu | e6bfab2 | 2014-02-06 16:01:19 -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 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
| 11 | #include <iostream> |
| 12 | #include <fstream> |
| 13 | |
| 14 | #include <boost/program_options/options_description.hpp> |
| 15 | #include <boost/program_options/variables_map.hpp> |
| 16 | #include <boost/program_options/parsers.hpp> |
| 17 | #include <boost/date_time/posix_time/posix_time.hpp> |
| 18 | #include <cryptopp/base64.h> |
| 19 | |
| 20 | #include "security/key-chain.hpp" |
| 21 | |
| 22 | using namespace std; |
| 23 | using namespace ndn; |
| 24 | namespace po = boost::program_options; |
| 25 | |
| 26 | int main(int argc, char** argv) |
| 27 | { |
| 28 | bool getId = true; |
| 29 | bool getKey = false; |
| 30 | bool getCert = false; |
| 31 | |
| 32 | po::options_description desc("General Usage\n ndn-ls-identity [-h] [-K|C]\nGeneral options"); |
| 33 | desc.add_options() |
| 34 | ("help,h", "produce help message") |
| 35 | ("key,K", "granularity: key") |
| 36 | ("cert,C", "granularity: certificate") |
| 37 | ; |
| 38 | |
| 39 | po::variables_map vm; |
| 40 | po::store(po::parse_command_line(argc, argv, desc), vm); |
| 41 | po::notify(vm); |
| 42 | |
| 43 | if (vm.count("help")) |
| 44 | { |
| 45 | cerr << desc << endl;; |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | if(vm.count("cert")) |
| 50 | { |
| 51 | getCert = true; |
| 52 | getId = false; |
| 53 | } |
| 54 | else if(vm.count("key")) |
| 55 | { |
| 56 | getKey = true; |
| 57 | getId = false; |
| 58 | } |
| 59 | |
| 60 | KeyChain keyChain; |
| 61 | |
| 62 | if(getId) |
| 63 | { |
| 64 | vector<Name> defaultList; |
| 65 | keyChain.getAllIdentities(defaultList, true); |
| 66 | for(int i = 0; i < defaultList.size(); i++) |
| 67 | cout << "* " << defaultList[i] << endl; |
| 68 | vector<Name> otherList; |
| 69 | keyChain.getAllIdentities(otherList, false); |
| 70 | for(int i = 0; i < otherList.size(); i++) |
| 71 | cout << " " << otherList[i] << endl; |
| 72 | return 0; |
| 73 | } |
| 74 | if(getKey) |
| 75 | { |
| 76 | vector<Name> defaultIdList; |
| 77 | keyChain.getAllIdentities(defaultIdList, true); |
| 78 | for(int i = 0; i < defaultIdList.size(); i++) |
| 79 | { |
| 80 | cout << "* " << defaultIdList[i] << endl; |
| 81 | vector<Name> defaultKeyList; |
| 82 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true); |
| 83 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 84 | cout << " +->* " << defaultKeyList[j] << endl; |
| 85 | vector<Name> otherKeyList; |
| 86 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false); |
| 87 | for(int j = 0; j < otherKeyList.size(); j++) |
| 88 | cout << " +-> " << otherKeyList[j] << endl; |
| 89 | cout << endl; |
| 90 | } |
| 91 | vector<Name> otherIdList; |
| 92 | keyChain.getAllIdentities(otherIdList, false); |
| 93 | for(int i = 0; i < otherIdList.size(); i++) |
| 94 | { |
| 95 | cout << " " << otherIdList[i] << endl; |
| 96 | vector<Name> defaultKeyList; |
| 97 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true); |
| 98 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 99 | cout << " +->* " << defaultKeyList[j] << endl; |
| 100 | vector<Name> otherKeyList; |
| 101 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false); |
| 102 | for(int j = 0; j < otherKeyList.size(); j++) |
| 103 | cout << " +-> " << otherKeyList[j] << endl; |
| 104 | cout << endl; |
| 105 | } |
| 106 | return 0; |
| 107 | } |
| 108 | if(getCert) |
| 109 | { |
| 110 | vector<Name> defaultIdList; |
| 111 | keyChain.getAllIdentities(defaultIdList, true); |
| 112 | for(int i = 0; i < defaultIdList.size(); i++) |
| 113 | { |
| 114 | cout << "* " << defaultIdList[i] << endl; |
| 115 | vector<Name> defaultKeyList; |
| 116 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], defaultKeyList, true); |
| 117 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 118 | { |
| 119 | cout << " +->* " << defaultKeyList[j] << endl; |
| 120 | vector<Name> defaultCertList; |
| 121 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true); |
| 122 | for(int k = 0; k < defaultCertList.size(); k++) |
| 123 | cout << " +->* " << defaultCertList[k] << endl; |
| 124 | vector<Name> otherCertList; |
| 125 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false); |
| 126 | for(int k = 0; k < otherCertList.size(); k++) |
| 127 | cout << " +-> " << otherCertList[k] << endl; |
| 128 | } |
| 129 | vector<Name> otherKeyList; |
| 130 | keyChain.getAllKeyNamesOfIdentity(defaultIdList[i], otherKeyList, false); |
| 131 | for(int j = 0; j < otherKeyList.size(); j++) |
| 132 | { |
| 133 | cout << " +-> " << otherKeyList[j] << endl; |
| 134 | vector<Name> defaultCertList; |
| 135 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true); |
| 136 | for(int k = 0; k < defaultCertList.size(); k++) |
| 137 | cout << " +->* " << defaultCertList[k] << endl; |
| 138 | vector<Name> otherCertList; |
| 139 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false); |
| 140 | for(int k = 0; k < otherCertList.size(); k++) |
| 141 | cout << " +-> " << otherCertList[k] << endl; |
| 142 | } |
| 143 | |
| 144 | cout << endl; |
| 145 | } |
| 146 | vector<Name> otherIdList; |
| 147 | keyChain.getAllIdentities(otherIdList, false); |
| 148 | for(int i = 0; i < otherIdList.size(); i++) |
| 149 | { |
| 150 | cout << " " << otherIdList[i] << endl; |
| 151 | vector<Name> defaultKeyList; |
| 152 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], defaultKeyList, true); |
| 153 | for(int j = 0; j < defaultKeyList.size(); j++) |
| 154 | { |
| 155 | cout << " +->* " << defaultKeyList[j] << endl; |
| 156 | vector<Name> defaultCertList; |
| 157 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], defaultCertList, true); |
| 158 | for(int k = 0; k < defaultCertList.size(); k++) |
| 159 | cout << " +->* " << defaultCertList[k] << endl; |
| 160 | vector<Name> otherCertList; |
| 161 | keyChain.getAllCertificateNamesOfKey(defaultKeyList[j], otherCertList, false); |
| 162 | for(int k = 0; k < otherCertList.size(); k++) |
| 163 | cout << " +-> " << otherCertList[k] << endl; |
| 164 | } |
| 165 | vector<Name> otherKeyList; |
| 166 | keyChain.getAllKeyNamesOfIdentity(otherIdList[i], otherKeyList, false); |
| 167 | for(int j = 0; j < otherKeyList.size(); j++) |
| 168 | { |
| 169 | cout << " +-> " << otherKeyList[j] << endl; |
| 170 | vector<Name> defaultCertList; |
| 171 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], defaultCertList, true); |
| 172 | for(int k = 0; k < defaultCertList.size(); k++) |
| 173 | cout << " +->* " << defaultCertList[k] << endl; |
| 174 | vector<Name> otherCertList; |
| 175 | keyChain.getAllCertificateNamesOfKey(otherKeyList[j], otherCertList, false); |
| 176 | for(int k = 0; k < otherCertList.size(); k++) |
| 177 | cout << " +-> " << otherCertList[k] << endl; |
| 178 | } |
| 179 | |
| 180 | cout << endl; |
| 181 | } |
| 182 | return 0; |
| 183 | } |
| 184 | return 1; |
| 185 | } |