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 | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2019, 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 | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 23 | #include <iostream> |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 24 | #include <string> |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 25 | #include <boost/program_options/options_description.hpp> |
| 26 | #include <boost/program_options/variables_map.hpp> |
| 27 | #include <boost/program_options/parsers.hpp> |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 28 | #include <ndn-cxx/security/verification-helpers.hpp> |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace ndncert { |
| 32 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 33 | static void startApplication(); |
| 34 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 35 | int nStep; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 36 | Face face; |
| 37 | security::v2::KeyChain keyChain; |
| 38 | std::string challengeType; |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 39 | int validityPeriod = -1; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 40 | ClientModule client(keyChain); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 41 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 42 | static std::list<std::string> |
| 43 | captureParams(const JsonSection& requirement) |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 44 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 45 | std::list<std::string> results; |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 46 | for (const auto& item : requirement) { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 47 | std::cerr << item.second.get<std::string>("") << std::endl; |
| 48 | std::cerr << "Please provide the argument: " << item.first << " : " << std::endl; |
| 49 | std::string tempParam; |
| 50 | getline(std::cin, tempParam); |
| 51 | results.push_back(tempParam); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 52 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 53 | std::cerr << "Got it. This is what you've provided:" << std::endl; |
| 54 | auto it1 = results.begin(); |
| 55 | auto it2 = requirement.begin(); |
| 56 | for (; it1 != results.end() && it2 != requirement.end(); it1++, it2++) { |
| 57 | std::cerr << it2->first << " : " << *it1 << std::endl; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 58 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 59 | return results; |
| 60 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 61 | |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 62 | static std::list<std::string> |
| 63 | captureParams(const std::vector<std::string>& requirement) |
| 64 | { |
| 65 | std::list<std::string> results; |
| 66 | for (const auto& item : requirement) { |
| 67 | std::cerr << "Please provide the argument: " << item << " : " << std::endl; |
| 68 | std::string tempParam; |
| 69 | getline(std::cin, tempParam); |
| 70 | results.push_back(tempParam); |
| 71 | } |
| 72 | std::cerr << "Got it. This is what you've provided:" << std::endl; |
| 73 | auto it1 = results.begin(); |
| 74 | auto it2 = requirement.begin(); |
| 75 | for (; it1 != results.end() && it2 != requirement.end(); it1++, it2++) { |
| 76 | std::cerr << *it2 << " : " << *it1 << std::endl; |
| 77 | } |
| 78 | return results; |
| 79 | } |
| 80 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 81 | static void |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 82 | captureValidityPeriod() |
| 83 | { |
| 84 | if (validityPeriod <= 0) { |
| 85 | std::cerr << "Step " << nStep++ |
| 86 | << ": Please type in your expected validity period of your certificate." |
| 87 | << " Type the number of hours (168 for week, 730 for month, 8760 for year). The CA may change the validity" |
| 88 | << " period if your expected period is too long." << std::endl; |
| 89 | std::string periodStr = ""; |
| 90 | do { |
| 91 | getline(std::cin, periodStr); |
| 92 | try { |
| 93 | validityPeriod = std::stoi(periodStr); |
| 94 | } |
| 95 | catch (const std::exception& e) { |
| 96 | validityPeriod = -1; |
| 97 | } |
| 98 | if (validityPeriod > 0) { |
| 99 | break; |
| 100 | } |
| 101 | std::cerr << "Invalid period time. Please input the period again." << std::endl; |
| 102 | } while (true); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | static void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 107 | onNackCb() |
| 108 | { |
| 109 | std::cerr << "Got NACK\n"; |
| 110 | } |
| 111 | |
| 112 | static void |
| 113 | timeoutCb() |
| 114 | { |
| 115 | std::cerr << "Interest sent time out\n"; |
| 116 | } |
| 117 | |
| 118 | static void |
| 119 | downloadCb(const Data& reply) |
| 120 | { |
| 121 | client.onDownloadResponse(reply); |
| 122 | std::cerr << "Step " << nStep++ |
| 123 | << ": DONE! Certificate has already been installed to local keychain\n"; |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | static void |
| 128 | challengeCb(const Data& reply) |
| 129 | { |
| 130 | client.onChallengeResponse(reply); |
| 131 | if (client.getApplicationStatus() == STATUS_SUCCESS) { |
| 132 | std::cerr << "DONE! Certificate has already been issued \n"; |
| 133 | face.expressInterest(*client.generateDownloadInterest(), bind(&downloadCb, _2), |
| 134 | bind(&onNackCb), bind(&timeoutCb)); |
Zhiyi Zhang | 4d89fe0 | 2017-04-28 18:51:51 -0700 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 138 | auto challenge = ChallengeModule::createChallengeModule(challengeType); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 139 | auto requirement = challenge->getRequirementForChallenge(client.getApplicationStatus(), |
| 140 | client.getChallengeStatus()); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 141 | if (requirement.size() > 0) { |
Zhiyi Zhang | 916ba2d | 2018-02-01 18:16:27 -0800 | [diff] [blame] | 142 | std::cerr << "Step " << nStep++ << ": Please satisfy following instruction(s)\n"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 143 | std::string redo = ""; |
| 144 | std::list<std::string> capturedParams; |
| 145 | do { |
| 146 | capturedParams = captureParams(requirement); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 147 | std::cerr << "If everything is correct, please type in OK; otherwise, type in REDO" << std::endl; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 148 | getline(std::cin, redo); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 149 | boost::algorithm::to_lower(redo); |
| 150 | } while (redo != "ok"); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 151 | auto it1 = capturedParams.begin(); |
| 152 | auto it2 = requirement.begin(); |
| 153 | for (; it1 != capturedParams.end() && it2 != requirement.end(); it1++, it2++) { |
| 154 | it2->second.put("", *it1); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 155 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 156 | } |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 157 | face.expressInterest(*client.generateChallengeInterest(challenge->genChallengeRequestJson(client.getApplicationStatus(), |
| 158 | client.getChallengeStatus(), |
| 159 | requirement)), |
| 160 | bind(&challengeCb, _2), bind(&onNackCb), bind(&timeoutCb)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 161 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 162 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 163 | static void |
| 164 | newCb(const Data& reply) |
| 165 | { |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 166 | int challengeIndex = 0; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 167 | auto challengeList = client.onNewResponse(reply); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 168 | if (challengeList.size() < 1) { |
| 169 | std::cerr << "There is no available challenge provided by the CA. Exit" << std::endl; |
| 170 | return; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 171 | } |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 172 | else if (challengeList.size() > 1) { |
| 173 | int count = 0; |
| 174 | std::string choice = ""; |
| 175 | std::cerr << "Step " << nStep++ << ": Please type in the challenge index that you want to perform\n"; |
| 176 | do { |
| 177 | count = 0; |
| 178 | for (auto item : challengeList) { |
| 179 | std::cerr << "\t" << count++ << " : "<< item << std::endl; |
| 180 | } |
| 181 | getline(std::cin, choice); |
| 182 | try { |
| 183 | challengeIndex = std::stoi(choice); |
| 184 | } |
| 185 | catch (const std::exception& e) { |
| 186 | challengeIndex = -1; |
| 187 | } |
| 188 | if (challengeIndex >= 0 && challengeIndex < count) { |
| 189 | break; |
| 190 | } |
| 191 | std::cerr << "Your input index is out of range. Please type in again." << std::endl; |
| 192 | } while (true); |
| 193 | } |
| 194 | auto it = challengeList.begin(); |
| 195 | std::advance(it, challengeIndex); |
| 196 | unique_ptr<ChallengeModule> challenge = ChallengeModule::createChallengeModule(*it); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 197 | if (challenge != nullptr) { |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 198 | challengeType = *it; |
| 199 | std::cerr << "The challenge has been selected: " << challengeType << std::endl; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 200 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 201 | else { |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 202 | std::cerr << "Error. Cannot load selected Challenge Module. Exit." << std::endl; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 203 | return; |
| 204 | } |
| 205 | auto requirement = challenge->getRequirementForChallenge(client.getApplicationStatus(), |
| 206 | client.getChallengeStatus()); |
| 207 | if (requirement.size() > 0) { |
| 208 | std::cerr << "Step " << nStep++ << ": Please satisfy following instruction(s)\n"; |
| 209 | std::string redo = ""; |
| 210 | std::list<std::string> capturedParams; |
| 211 | do { |
| 212 | capturedParams = captureParams(requirement); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 213 | std::cerr << "If everything is correct, please type in OK; otherwise, type in REDO" << std::endl; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 214 | getline(std::cin, redo); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 215 | boost::algorithm::to_lower(redo); |
| 216 | } while (redo != "ok"); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 217 | auto it1 = capturedParams.begin(); |
| 218 | auto it2 = requirement.begin(); |
| 219 | for (; it1 != capturedParams.end() && it2 != requirement.end(); it1++, it2++) { |
| 220 | it2->second.put("", *it1); |
| 221 | } |
| 222 | } |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 223 | face.expressInterest(*client.generateChallengeInterest(challenge->genChallengeRequestJson(client.getApplicationStatus(), |
| 224 | client.getChallengeStatus(), |
| 225 | requirement)), |
| 226 | bind(&challengeCb, _2), bind(&onNackCb), bind(&timeoutCb)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 227 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 228 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 229 | static void |
| 230 | probeInfoCb(const Data& reply) |
| 231 | { |
| 232 | auto contentJson = ClientModule::getJsonFromData(reply); |
| 233 | auto caItem = ClientConfig::extractCaItem(contentJson); |
| 234 | |
| 235 | std::cerr << "Will install new trust anchor, please double check the identity info: \n" |
| 236 | << "This trust anchor packet is signed by " << reply.getSignature().getKeyLocator() << std::endl |
| 237 | << "The signing certificate is " << caItem.m_anchor << std::endl; |
| 238 | std::cerr << "Do you trust the information? Type in YES or NO" << std::endl; |
| 239 | |
| 240 | std::string answer; |
| 241 | getline(std::cin, answer); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 242 | boost::algorithm::to_lower(answer); |
| 243 | if (answer == "yes") { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 244 | client.onProbeInfoResponse(reply); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 245 | std::cerr << "You answered YES: new CA has been installed" << std::endl; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 246 | startApplication(); |
| 247 | } |
| 248 | else { |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 249 | std::cerr << "New CA will not be installed" << std::endl; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | static void |
| 255 | probeCb(const Data& reply) |
| 256 | { |
Zhiyi Zhang | 781a560 | 2019-06-26 19:05:04 -0700 | [diff] [blame] | 257 | client.onProbeResponse(reply); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 258 | captureValidityPeriod(); |
Zhiyi Zhang | 781a560 | 2019-06-26 19:05:04 -0700 | [diff] [blame] | 259 | auto probeToken = make_shared<Data>(reply); |
Zhiyi Zhang | 1a735bc | 2019-07-04 21:36:49 -0700 | [diff] [blame] | 260 | auto now = time::system_clock::now(); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 261 | std::cerr << "The validity period of your certificate will be: " << validityPeriod << " hours" << std::endl; |
| 262 | face.expressInterest(*client.generateNewInterest(now, now + time::hours(validityPeriod), |
Zhiyi Zhang | 781a560 | 2019-06-26 19:05:04 -0700 | [diff] [blame] | 263 | Name(), probeToken), |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 264 | bind(&newCb, _2), bind(&onNackCb), bind(&timeoutCb)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static void |
| 268 | startApplication() |
| 269 | { |
| 270 | nStep = 0; |
| 271 | auto caList = client.getClientConf().m_caItems; |
| 272 | int count = 0; |
| 273 | for (auto item : caList) { |
| 274 | std::cerr << "***************************************\n" |
| 275 | << "Index: " << count++ << "\n" |
| 276 | << "CA prefix:" << item.m_caName << "\n" |
| 277 | << "Introduction: " << item.m_caInfo << "\n" |
| 278 | << "***************************************\n"; |
| 279 | } |
| 280 | std::vector<ClientCaItem> caVector{std::begin(caList), std::end(caList)}; |
| 281 | std::cerr << "Step " |
| 282 | << nStep++ << ": Please type in the CA INDEX that you want to apply" |
| 283 | << " or type in NONE if your expected CA is not in the list\n"; |
| 284 | |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 285 | std::string caIndexS, caIndexSLower; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 286 | getline(std::cin, caIndexS); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 287 | caIndexSLower = caIndexS; |
| 288 | boost::algorithm::to_lower(caIndexSLower); |
| 289 | if (caIndexSLower == "none") { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 290 | std::cerr << "Step " << nStep << ": Please type in the CA Name\n"; |
| 291 | face.expressInterest(*client.generateProbeInfoInterest(Name(caIndexS)), |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 292 | bind(&probeInfoCb, _2), bind(&onNackCb), bind(&timeoutCb)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 293 | } |
| 294 | else { |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 295 | int caIndex; |
| 296 | try { |
| 297 | caIndex = std::stoi(caIndexS); |
| 298 | } |
| 299 | catch (const std::exception& e) { |
| 300 | std::cerr << "Your input is neither NONE nor a valid index. Exit" << std::endl; |
| 301 | return; |
| 302 | } |
| 303 | if (caIndex < 0 || caIndex >= count) { |
| 304 | std::cerr << "Your input is not an existing index. Exit" << std::endl; |
| 305 | return; |
| 306 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 307 | auto targetCaItem = caVector[caIndex]; |
| 308 | |
| 309 | if (targetCaItem.m_probe != "") { |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 310 | std::cerr << "Step " << nStep++ << ": Please provide information for name assignment" << std::endl; |
| 311 | std::vector<std::string> probeFields = ClientModule::parseProbeComponents(targetCaItem.m_probe); |
| 312 | std::string redo = ""; |
| 313 | std::list<std::string> capturedParams; |
| 314 | do { |
| 315 | capturedParams = captureParams(probeFields); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 316 | std::cerr << "If everything is correct, please type in OK; otherwise, type in REDO" << std::endl; |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 317 | getline(std::cin, redo); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 318 | boost::algorithm::to_lower(redo); |
| 319 | } while (redo != "ok"); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 320 | std::string probeInfo; |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 321 | for (const auto& item : capturedParams) { |
| 322 | probeInfo += item; |
| 323 | probeInfo += ":"; |
| 324 | } |
| 325 | probeInfo = probeInfo.substr(0, probeInfo.size() - 1); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 326 | face.expressInterest(*client.generateProbeInterest(targetCaItem, probeInfo), |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 327 | bind(&probeCb, _2), bind(&onNackCb), bind(&timeoutCb)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 328 | } |
| 329 | else { |
| 330 | std::cerr << "Step " << nStep++ << ": Please type in the identity name you want to get (with CA prefix)\n"; |
| 331 | std::string identityNameStr; |
| 332 | getline(std::cin, identityNameStr); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 333 | captureValidityPeriod(); |
| 334 | std::cerr << "The validity period of your certificate will be: " << validityPeriod << " hours" << std::endl; |
Zhiyi Zhang | 1a735bc | 2019-07-04 21:36:49 -0700 | [diff] [blame] | 335 | auto now = time::system_clock::now(); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 336 | face.expressInterest(*client.generateNewInterest(now, now + time::hours(validityPeriod), |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 337 | Name(identityNameStr)), |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 338 | bind(&newCb, _2), bind(&onNackCb), bind(&timeoutCb)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 343 | |
| 344 | int |
| 345 | main(int argc, char* argv[]) |
| 346 | { |
| 347 | namespace po = boost::program_options; |
| 348 | std::string configFilePath = std::string(SYSCONFDIR) + "/ndncert/client.conf"; |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 349 | po::options_description description("General Usage\n ndncert-client [-h] [-c] [-v]\n"); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 350 | description.add_options() |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 351 | ("help,h", "produce help message") |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame^] | 352 | ("config-file,c", po::value<std::string>(&configFilePath), "config file name") |
| 353 | ("validity-period,v", po::value<int>(&validityPeriod)->default_value(-1), "the validity period of your certificate being requested"); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 354 | po::positional_options_description p; |
| 355 | |
| 356 | po::variables_map vm; |
| 357 | try { |
| 358 | po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm); |
| 359 | po::notify(vm); |
| 360 | } |
| 361 | catch (const std::exception& e) { |
| 362 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 363 | return 1; |
| 364 | } |
| 365 | if (vm.count("help") != 0) { |
| 366 | std::cerr << description << std::endl; |
| 367 | return 0; |
| 368 | } |
Zhiyi Zhang | d8993b9 | 2019-07-04 21:58:10 -0700 | [diff] [blame] | 369 | try { |
| 370 | client.getClientConf().load(configFilePath); |
| 371 | } |
| 372 | catch (const std::exception& e) { |
| 373 | std::cerr << "Cannot load the configuration file: " << e.what() << std::endl; |
| 374 | return 1; |
| 375 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 376 | startApplication(); |
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 | } |