Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 3 | * Copyright (c) 2017-2018, Regents of the University of California. |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
| 21 | #include "client-module.hpp" |
| 22 | #include "challenge-module.hpp" |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 23 | |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 24 | #include <iostream> |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 25 | #include <string> |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 26 | |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 27 | #include <boost/program_options/options_description.hpp> |
| 28 | #include <boost/program_options/variables_map.hpp> |
| 29 | #include <boost/program_options/parsers.hpp> |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 30 | #include <ndn-cxx/security/verification-helpers.hpp> |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 31 | |
| 32 | namespace ndn { |
| 33 | namespace ndncert { |
| 34 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 35 | int nStep; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 36 | |
| 37 | class ClientTool |
| 38 | { |
| 39 | public: |
| 40 | ClientTool(ClientModule& clientModule) |
| 41 | : client(clientModule) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | errorCb(const std::string& errorInfo) |
| 47 | { |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 48 | std::cerr << "Error: " << errorInfo << std::endl; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 52 | downloadCb(const shared_ptr<RequestState>& state) |
Zhiyi Zhang | 4d89fe0 | 2017-04-28 18:51:51 -0700 | [diff] [blame] | 53 | { |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 54 | std::cerr << "Step " << nStep++ |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 55 | << "DONE! Certificate has already been installed to local keychain\n"; |
Zhiyi Zhang | 4d89fe0 | 2017-04-28 18:51:51 -0700 | [diff] [blame] | 56 | return; |
| 57 | } |
| 58 | |
| 59 | void |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 60 | anchorCb(const Interest& request, const Data& reply, |
| 61 | const ClientCaItem& anchorItem, const Name& assignedName) |
| 62 | { |
| 63 | auto contentJson = ClientModule::getJsonFromData(reply); |
| 64 | auto caItem = ClientConfig::extractCaItem(contentJson); |
| 65 | |
| 66 | if (!security::verifySignature(caItem.m_anchor, anchorItem.m_anchor)) { |
| 67 | std::cerr << "Fail to verify fetched anchor" << std::endl; |
| 68 | return; |
| 69 | } |
| 70 | client.getClientConf().m_caItems.push_back(caItem); |
| 71 | |
| 72 | if (assignedName.toUri() != "/") { |
| 73 | client.sendNew(caItem, assignedName, |
| 74 | bind(&ClientTool::newCb, this, _1), |
| 75 | bind(&ClientTool::errorCb, this, _1)); |
| 76 | } |
| 77 | else { |
| 78 | if (caItem.m_probe != "") { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 79 | std::cerr << "Step " << nStep++ << ": Probe Requirement-" << caItem.m_probe << std::endl; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 80 | std::string probeInfo; |
| 81 | getline(std::cin, probeInfo); |
| 82 | client.sendProbe(caItem, probeInfo, |
| 83 | bind(&ClientTool::newCb, this, _1), |
| 84 | bind(&ClientTool::errorCb, this, _1)); |
| 85 | } |
| 86 | else { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 87 | std::cerr << "Step " << nStep++ << ": Please type in the identity name\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 88 | std::string nameComponent; |
| 89 | getline(std::cin, nameComponent); |
| 90 | Name identityName = caItem.m_caName.getPrefix(-1); |
| 91 | identityName.append(nameComponent); |
| 92 | client.sendNew(caItem, identityName, |
| 93 | bind(&ClientTool::newCb, this, _1), |
| 94 | bind(&ClientTool::errorCb, this, _1)); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | void |
| 100 | listCb(const std::list<Name>& caList, const Name& assignedName, const Name& schema, |
| 101 | const ClientCaItem& caItem) |
| 102 | { |
| 103 | if (assignedName.toUri() != "" && caList.size() == 1) { |
| 104 | // with recommendation |
| 105 | |
| 106 | std::cerr << "Get recommended CA: " << caList.front() |
| 107 | << "Get recommended Identity: " << assignedName << std::endl; |
| 108 | client.requestCaTrustAnchor(caList.front(), |
| 109 | bind(&ClientTool::anchorCb, this, _1, _2, caItem, assignedName), |
| 110 | bind(&ClientTool::errorCb, this, _1)); |
| 111 | } |
| 112 | else { |
| 113 | // without recommendation |
| 114 | int count = 0; |
| 115 | for (auto name : caList) { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 116 | std::cerr << "***************************************\n" |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 117 | << "Index: " << count++ << "\n" |
| 118 | << "CA prefix:" << name << "\n" |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 119 | << "***************************************\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 120 | } |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 121 | std::cerr << "Select an index to apply for a certificate\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 122 | |
| 123 | std::string option; |
| 124 | getline(std::cin, option); |
| 125 | int caIndex = std::stoi(option); |
| 126 | |
| 127 | std::vector<Name> caVector{std::begin(caList), std::end(caList)}; |
| 128 | Name targetCaName = caVector[caIndex]; |
| 129 | |
| 130 | client.requestCaTrustAnchor(targetCaName, |
| 131 | bind(&ClientTool::anchorCb, this, _1, _2, caItem, Name("")), |
| 132 | bind(&ClientTool::errorCb, this, _1)); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | validateCb(const shared_ptr<RequestState>& state) |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 138 | { |
| 139 | if (state->m_status == ChallengeModule::SUCCESS) { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 140 | std::cerr << "DONE! Certificate has already been issued \n"; |
Zhiyi Zhang | 4d89fe0 | 2017-04-28 18:51:51 -0700 | [diff] [blame] | 141 | client.requestDownload(state, |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 142 | bind(&ClientTool::downloadCb, this, _1), |
Zhiyi Zhang | 4d89fe0 | 2017-04-28 18:51:51 -0700 | [diff] [blame] | 143 | bind(&ClientTool::errorCb, this, _1)); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | |
| 147 | auto challenge = ChallengeModule::createChallengeModule(state->m_challengeType); |
| 148 | auto requirementList = challenge->getRequirementForValidate(state->m_status); |
| 149 | |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 150 | std::cerr << "Step " << nStep++ << ": Please satisfy following instruction(s)\n"; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 151 | for (auto requirement : requirementList) { |
| 152 | std::cerr << "\t" << requirement << std::endl; |
| 153 | } |
| 154 | std::list<std::string> paraList; |
| 155 | for (size_t i = 0; i < requirementList.size(); i++) { |
| 156 | std::string tempParam; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 157 | getline(std::cin, tempParam); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 158 | paraList.push_back(tempParam); |
| 159 | } |
| 160 | auto paramJson = challenge->genValidateParamsJson(state->m_status, paraList); |
| 161 | client.sendValidate(state, paramJson, |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 162 | bind(&ClientTool::validateCb, this, _1), |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 163 | bind(&ClientTool::errorCb, this, _1)); |
| 164 | } |
| 165 | |
| 166 | void |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 167 | selectCb(const shared_ptr<RequestState>& state) |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 168 | { |
| 169 | auto challenge = ChallengeModule::createChallengeModule(state->m_challengeType); |
| 170 | auto requirementList = challenge->getRequirementForValidate(state->m_status); |
| 171 | |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 172 | std::cerr << "Step " << nStep++ << ": Please satisfy following instruction(s)" << std::endl; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 173 | for (auto item : requirementList) { |
| 174 | std::cerr << "\t" << item << std::endl; |
| 175 | } |
| 176 | std::list<std::string> paraList; |
| 177 | for (size_t i = 0; i < requirementList.size(); i++) { |
| 178 | std::string tempParam; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 179 | getline(std::cin, tempParam); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 180 | paraList.push_back(tempParam); |
| 181 | } |
| 182 | |
| 183 | auto paramJson = challenge->genValidateParamsJson(state->m_status, paraList); |
| 184 | client.sendValidate(state, paramJson, |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 185 | bind(&ClientTool::validateCb, this, _1), |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 186 | bind(&ClientTool::errorCb, this, _1)); |
| 187 | } |
| 188 | |
| 189 | void |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 190 | newCb(const shared_ptr<RequestState>& state) |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 191 | { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 192 | std::cerr << "Step " << nStep++ << ": Please select one challenge from following types\n"; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 193 | for (auto item : state->m_challengeList) { |
| 194 | std::cerr << "\t" << item << std::endl; |
| 195 | } |
| 196 | std::string choice; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 197 | getline(std::cin, choice); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 198 | |
| 199 | auto challenge = ChallengeModule::createChallengeModule(choice); |
| 200 | auto requirementList = challenge->getRequirementForSelect(); |
| 201 | std::list<std::string> paraList; |
| 202 | if (requirementList.size() != 0) { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 203 | std::cerr << "Step " << nStep++ << ": Please satisfy following instruction(s)\n"; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 204 | for (auto item : requirementList) { |
| 205 | std::cerr << "\t" << item << std::endl; |
| 206 | } |
| 207 | for (size_t i = 0; i < requirementList.size(); i++) { |
| 208 | std::string tempParam; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 209 | getline(std::cin, tempParam); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 210 | paraList.push_back(tempParam); |
| 211 | } |
| 212 | } |
| 213 | auto paramJson = challenge->genSelectParamsJson(state->m_status, paraList); |
| 214 | client.sendSelect(state, choice, paramJson, |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 215 | bind(&ClientTool::selectCb, this, _1), |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 216 | bind(&ClientTool::errorCb, this, _1)); |
| 217 | } |
| 218 | |
| 219 | public: |
| 220 | ClientModule& client; |
| 221 | }; |
| 222 | |
| 223 | int |
| 224 | main(int argc, char* argv[]) |
| 225 | { |
| 226 | namespace po = boost::program_options; |
| 227 | std::string configFilePath = std::string(SYSCONFDIR) + "/ndncert/client.conf"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 228 | bool isIntra = false; |
| 229 | po::options_description description("General Usage\n ndncert-client [-h] [-i] [-f]\n"); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 230 | description.add_options() |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 231 | ("help,h", |
| 232 | "produce help message") |
| 233 | ("intra-node,i", |
| 234 | "optional, if specified, switch on the intra-node mode") |
| 235 | ("config-file,f", po::value<std::string>(&configFilePath), |
| 236 | "config file name"); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 237 | po::positional_options_description p; |
| 238 | |
| 239 | po::variables_map vm; |
| 240 | try { |
| 241 | po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm); |
| 242 | po::notify(vm); |
| 243 | } |
| 244 | catch (const std::exception& e) { |
| 245 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 246 | return 1; |
| 247 | } |
| 248 | if (vm.count("help") != 0) { |
| 249 | std::cerr << description << std::endl; |
| 250 | return 0; |
| 251 | } |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 252 | if (vm.count("intra-node") != 0) { |
| 253 | isIntra = true; |
| 254 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 255 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 256 | nStep = 0; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 257 | Face face; |
| 258 | security::v2::KeyChain keyChain; |
| 259 | ClientModule client(face, keyChain); |
| 260 | client.getClientConf().load(configFilePath); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 261 | ClientTool tool(client); |
| 262 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 263 | if (isIntra) { |
| 264 | client.requestLocalhostList([&](const ClientConfig& config) { |
| 265 | auto caList = config.m_caItems; |
| 266 | int count = 0; |
| 267 | for (auto item : caList) { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 268 | std::cerr << "***************************************\n" |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 269 | << "Index: " << count++ << "\n" |
| 270 | << "CA prefix:" << item.m_caName << "\n" |
| 271 | << "Introduction: " << item.m_caInfo << "\n" |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 272 | << "***************************************\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 273 | } |
| 274 | std::vector<ClientCaItem> caVector{std::begin(caList), std::end(caList)}; |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 275 | std::cerr << "Step " << nStep++ |
| 276 | << ": Please type in the CA namespace index that you want to apply\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 277 | std::string caIndexS; |
| 278 | getline(std::cin, caIndexS); |
| 279 | int caIndex = std::stoi(caIndexS); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 280 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 281 | BOOST_ASSERT(caIndex <= count); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 282 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 283 | auto targetCaItem = caVector[caIndex]; |
| 284 | if (targetCaItem.m_probe != "") { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 285 | std::cerr << "Step " << nStep++ << ": Probe Requirement-" << targetCaItem.m_probe << std::endl; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 286 | std::string probeInfo; |
| 287 | getline(std::cin, probeInfo); |
| 288 | client.sendProbe(targetCaItem, probeInfo, |
| 289 | bind(&ClientTool::newCb, &tool, _1), |
| 290 | bind(&ClientTool::errorCb, &tool, _1)); |
| 291 | } |
| 292 | else { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 293 | std::cerr << "Step " << nStep++ << ": Please type in the identity name\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 294 | std::string nameComponent; |
| 295 | getline(std::cin, nameComponent); |
| 296 | Name identityName = targetCaItem.m_caName.getPrefix(-1); |
| 297 | identityName.append(nameComponent); |
| 298 | client.sendNew(targetCaItem, identityName, |
| 299 | bind(&ClientTool::newCb, &tool, _1), |
| 300 | bind(&ClientTool::errorCb, &tool, _1)); |
| 301 | } |
| 302 | }, |
| 303 | bind(&ClientTool::errorCb, &tool, _1)); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 304 | } |
| 305 | else { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 306 | // Inter-node Application |
| 307 | bool listFirst = false; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 308 | auto caList = client.getClientConf().m_caItems; |
| 309 | int count = 0; |
| 310 | for (auto item : caList) { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 311 | std::cerr << "***************************************\n" |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 312 | << "Index: " << count++ << "\n" |
| 313 | << "CA prefix:" << item.m_caName << "\n" |
| 314 | << "Introduction: " << item.m_caInfo << "\n" |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 315 | << "***************************************\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 316 | } |
| 317 | std::vector<ClientCaItem> caVector{std::begin(caList), std::end(caList)}; |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 318 | std::cerr << "Step " << nStep++ << ": Please type in the CA namespace index that you want to apply\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 319 | |
| 320 | std::string caIndexS; |
| 321 | getline(std::cin, caIndexS); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 322 | int caIndex = std::stoi(caIndexS); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 323 | BOOST_ASSERT(caIndex <= count); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 324 | auto targetCaItem = caVector[caIndex]; |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 325 | |
| 326 | if (targetCaItem.m_isListEnabled) { |
| 327 | std::cerr << "This CA provides several sub-namepace CAs \n" |
| 328 | << "Do you want to (A) get a certificate from " << targetCaItem.m_caName << "directly? \n" |
| 329 | << "Or (B) get a certificate from one of its sub-namespace CAs? \n" |
| 330 | << "Please type in your choice (A or B) \n"; |
| 331 | std::string listOption; |
| 332 | getline(std::cin, listOption); |
| 333 | if (listOption == "A" || listOption == "a") { |
| 334 | listFirst = false; |
| 335 | } |
| 336 | else if (listOption == "B" || listOption == "b") { |
| 337 | listFirst = true; |
| 338 | std::string additionalInfo = ""; |
| 339 | if (targetCaItem.m_targetedList != "") { |
| 340 | std::cerr << "Step " << nStep++ |
| 341 | << ": Enter nothing if you want to see all available sub-namespace CAs" |
| 342 | << " or follow the instruction to get a recommended CA\n" |
| 343 | << "\t" << targetCaItem.m_targetedList << std::endl; |
| 344 | getline(std::cin, additionalInfo); |
| 345 | } |
| 346 | client.requestList(targetCaItem, additionalInfo, |
| 347 | bind(&ClientTool::listCb, &tool, _1, _2, _3, targetCaItem), |
| 348 | bind(&ClientTool::errorCb, &tool, _1)); |
| 349 | } |
| 350 | else { |
| 351 | std::cerr << "Your input is not an option." << std::endl; |
| 352 | return 1; |
| 353 | } |
| 354 | } |
| 355 | if (!listFirst) { |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 356 | if (targetCaItem.m_probe != "") { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 357 | std::cerr << "Step " << nStep++ << ": Probe Requirement-" << targetCaItem.m_probe << std::endl; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 358 | std::string probeInfo; |
| 359 | getline(std::cin, probeInfo); |
| 360 | client.sendProbe(targetCaItem, probeInfo, |
| 361 | bind(&ClientTool::newCb, &tool, _1), |
| 362 | bind(&ClientTool::errorCb, &tool, _1)); |
| 363 | } |
| 364 | else { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 365 | std::cerr << "Step " << nStep++ << ": Please type in the identity name\n"; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 366 | std::string nameComponent; |
| 367 | getline(std::cin, nameComponent); |
| 368 | Name identityName = targetCaItem.m_caName.getPrefix(-1); |
| 369 | identityName.append(nameComponent); |
| 370 | client.sendNew(targetCaItem, identityName, |
| 371 | bind(&ClientTool::newCb, &tool, _1), |
| 372 | bind(&ClientTool::errorCb, &tool, _1)); |
| 373 | } |
| 374 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 375 | } |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 376 | |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 377 | face.processEvents(); |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | } // namespace ndncert |
| 382 | } // namespace ndn |
| 383 | |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 384 | int main(int argc, char* argv[]) |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 385 | { |
| 386 | return ndn::ndncert::main(argc, argv); |
| 387 | } |