Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017-2021, 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 | |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 21 | #include "requester-request.hpp" |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 22 | |
Zhiyi Zhang | 90c7578 | 2020-10-06 15:04:03 -0700 | [diff] [blame] | 23 | #include <ndn-cxx/security/verification-helpers.hpp> |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 24 | |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 25 | #include <boost/asio.hpp> |
Davide Pesavento | b48bbda | 2020-07-27 19:41:37 -0400 | [diff] [blame] | 26 | #include <boost/program_options/options_description.hpp> |
| 27 | #include <boost/program_options/parsers.hpp> |
| 28 | #include <boost/program_options/variables_map.hpp> |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 29 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 30 | #include <iostream> |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 31 | |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 32 | namespace ndn { |
| 33 | namespace ndncert { |
Zhiyi Zhang | 3002e6b | 2020-10-29 18:54:07 -0700 | [diff] [blame] | 34 | namespace requester { |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 35 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 36 | static void |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 37 | selectCaProfile(std::string configFilePath); |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 38 | |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 39 | static void |
| 40 | runProbe(CaProfile profile); |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 41 | |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 42 | static void |
| 43 | runNew(CaProfile profile, Name identityName); |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 44 | |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 45 | static void |
| 46 | runChallenge(const std::string& challengeType); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 47 | |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 48 | static size_t nStep = 1; |
| 49 | static Face face; |
| 50 | static security::KeyChain keyChain; |
| 51 | static shared_ptr<Request> requesterState; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 52 | |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 53 | static void |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 54 | captureParams(std::multimap<std::string, std::string>& requirement) |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 55 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 56 | std::list<std::string> results; |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 57 | for (auto& item : requirement) { |
| 58 | std::cerr << std::get<1>(item) << std::endl; |
| 59 | std::string captured; |
| 60 | getline(std::cin, captured); |
| 61 | std::get<1>(item) = captured; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 62 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 63 | std::cerr << "Got it. This is what you've provided:" << std::endl; |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 64 | for (const auto& item : requirement) { |
| 65 | std::cerr << std::get<0>(item) << " : " << std::get<1>(item) << std::endl; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 66 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 67 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 68 | |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 69 | static std::multimap<std::string, std::string> |
Zhiyi Zhang | 2de4ea3 | 2020-12-13 17:45:25 -0800 | [diff] [blame] | 70 | captureParams(const std::vector<std::string>& requirement) |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 71 | { |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 72 | std::multimap<std::string, std::string> results; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 73 | for (const auto& r : requirement) { |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 74 | results.emplace(r, "Please input: " + r); |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 75 | } |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 76 | captureParams(results); |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 77 | return results; |
| 78 | } |
| 79 | |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 80 | static int |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 81 | captureValidityPeriod() |
| 82 | { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 83 | std::cerr << "\n***************************************\n" |
| 84 | << "Step " << nStep++ |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 85 | << ": Please type in your expected validity period of your certificate." |
| 86 | << " Type the number of hours (168 for week, 730 for month, 8760 for year)." |
| 87 | << " The CA may reject your application if your expected period is too long." << std::endl; |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 88 | size_t count = 0; |
| 89 | while (true && count < 3) { |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 90 | std::string periodStr = ""; |
| 91 | getline(std::cin, periodStr); |
| 92 | try { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 93 | return std::stoul(periodStr); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 94 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 95 | catch (const std::exception& e) { |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 96 | std::cerr << "Your input is invalid. Try again: " << std::endl; |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 97 | count++; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 98 | } |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 99 | } |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 100 | std::cerr << "Invalid input for too many times, exit. " << std::endl; |
| 101 | exit(1); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 105 | onNackCb() |
| 106 | { |
| 107 | std::cerr << "Got NACK\n"; |
| 108 | } |
| 109 | |
| 110 | static void |
| 111 | timeoutCb() |
| 112 | { |
| 113 | std::cerr << "Interest sent time out\n"; |
| 114 | } |
| 115 | |
| 116 | static void |
swa770 | cf1d8f7 | 2020-04-21 23:12:39 -0700 | [diff] [blame] | 117 | certFetchCb(const Data& reply) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 118 | { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 119 | auto item = Request::onCertFetchResponse(reply); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 120 | if (item) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 121 | keyChain.addCertificate(keyChain.getPib().getIdentity(item->getIdentity()).getKey(item->getKeyName()), *item); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 122 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 123 | std::cerr << "\n***************************************\n" |
| 124 | << "Step " << nStep++ |
| 125 | << ": DONE\nCertificate with Name: " << reply.getName().toUri() |
| 126 | << "has already been installed to your local keychain" << std::endl |
| 127 | << "Exit now"; |
| 128 | face.getIoService().stop(); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void |
| 132 | challengeCb(const Data& reply) |
| 133 | { |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 134 | try { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 135 | requesterState->onChallengeResponse(reply); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 136 | } |
| 137 | catch (const std::exception& e) { |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 138 | std::cerr << "Error when decoding challenge step: " << e.what() << std::endl; |
| 139 | exit(1); |
| 140 | } |
Zhiyi Zhang | 6499edd | 2021-02-17 22:37:21 -0800 | [diff] [blame] | 141 | if (requesterState->m_status == Status::SUCCESS) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 142 | std::cerr << "Certificate has already been issued, downloading certificate..." << std::endl; |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 143 | face.expressInterest(*requesterState->genCertFetchInterest(), |
| 144 | [] (const auto&, const auto& data) { certFetchCb(data); }, |
| 145 | [] (auto&&...) { onNackCb(); }, |
| 146 | [] (auto&&...) { timeoutCb(); }); |
Zhiyi Zhang | 4d89fe0 | 2017-04-28 18:51:51 -0700 | [diff] [blame] | 147 | return; |
| 148 | } |
Zhiyi Zhang | 6499edd | 2021-02-17 22:37:21 -0800 | [diff] [blame] | 149 | runChallenge(requesterState->m_challengeType); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 150 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 151 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 152 | static void |
| 153 | newCb(const Data& reply) |
| 154 | { |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 155 | std::list<std::string> challengeList; |
| 156 | try { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 157 | challengeList = requesterState->onNewRenewRevokeResponse(reply); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 158 | } |
| 159 | catch (const std::exception& e) { |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 160 | std::cerr << "Error on decoding NEW step reply because: " << e.what() << std::endl; |
| 161 | exit(1); |
| 162 | } |
| 163 | |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 164 | size_t challengeIndex = 0; |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 165 | if (challengeList.size() < 1) { |
| 166 | std::cerr << "There is no available challenge provided by the CA. Exit" << std::endl; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 167 | exit(1); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 168 | } |
Zhiyi Zhang | 48f546f | 2020-12-24 17:31:02 -0800 | [diff] [blame] | 169 | else if (challengeList.size() >= 1) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 170 | std::cerr << "\n***************************************\n" |
| 171 | << "Step " << nStep++ |
| 172 | << ": CHALLENGE SELECTION" << std::endl; |
| 173 | size_t count = 0; |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 174 | std::string choice = ""; |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 175 | for (auto item : challengeList) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 176 | std::cerr << "> Index: " << count++ << std::endl |
| 177 | << ">> Challenge:" << item << std::endl; |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 178 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 179 | std::cerr << "Please type in the challenge index that you want to perform:" << std::endl; |
Zhiyi Zhang | 17720f2 | 2021-01-08 14:12:56 -0800 | [diff] [blame] | 180 | size_t inputCount = 0; |
| 181 | while (inputCount < 3) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 182 | getline(std::cin, choice); |
| 183 | try { |
| 184 | challengeIndex = std::stoul(choice); |
| 185 | } |
| 186 | catch (const std::exception& e) { |
| 187 | std::cerr << "Your input is not valid. Try again:" << std::endl; |
Zhiyi Zhang | 17720f2 | 2021-01-08 14:12:56 -0800 | [diff] [blame] | 188 | inputCount++; |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 189 | continue; |
| 190 | } |
| 191 | if (challengeIndex >= count) { |
| 192 | std::cerr << "Your input index is out of range. Try again:" << std::endl; |
Zhiyi Zhang | 17720f2 | 2021-01-08 14:12:56 -0800 | [diff] [blame] | 193 | inputCount++; |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 194 | continue; |
| 195 | } |
| 196 | break; |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 197 | } |
Zhiyi Zhang | 17720f2 | 2021-01-08 14:12:56 -0800 | [diff] [blame] | 198 | if (inputCount == 3) { |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 199 | std::cerr << "Invalid input for too many times, exit. " << std::endl; |
| 200 | exit(1); |
| 201 | } |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 202 | } |
| 203 | auto it = challengeList.begin(); |
| 204 | std::advance(it, challengeIndex); |
Zhiyi Zhang | c5d93a9 | 2020-10-14 17:07:35 -0700 | [diff] [blame] | 205 | std::cerr << "The challenge has been selected: " << *it << std::endl; |
| 206 | runChallenge(*it); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 207 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 208 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 209 | static void |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 210 | infoCb(const Data& reply, const Name& certFullName) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 211 | { |
Zhiyi Zhang | 997669a | 2020-10-28 21:15:40 -0700 | [diff] [blame] | 212 | optional<CaProfile> profile; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 213 | try { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 214 | if (certFullName.empty()) { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 215 | profile = Request::onCaProfileResponse(reply); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 216 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 217 | else { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 218 | profile = Request::onCaProfileResponseAfterRedirection(reply, certFullName); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | catch (const std::exception& e) { |
| 222 | std::cerr << "The fetched CA information cannot be used because: " << e.what() << std::endl; |
| 223 | return; |
Zhiyi Zhang | caab546 | 2019-10-18 13:41:02 -0700 | [diff] [blame] | 224 | } |
Zhiyi Zhang | 6bb1d08 | 2020-10-08 14:25:21 -0700 | [diff] [blame] | 225 | std::cerr << "\n***************************************\n" |
| 226 | << "Step " << nStep++ |
| 227 | << ": Will use a new trust anchor, please double check the identity info:" << std::endl |
Zhiyi Zhang | 44c6a35 | 2020-12-14 10:57:17 -0800 | [diff] [blame] | 228 | << "> New CA name: " << profile->caPrefix.toUri() << std::endl |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 229 | << "> This trust anchor information is signed by: " << reply.getSignatureInfo().getKeyLocator() << std::endl |
Zhiyi Zhang | ec4aa3a | 2021-01-08 14:26:37 -0800 | [diff] [blame] | 230 | << "> The certificate: " << *profile->cert << std::endl |
Davide Pesavento | b48bbda | 2020-07-27 19:41:37 -0400 | [diff] [blame] | 231 | << "Do you trust the information? Type in YES or NO" << std::endl; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 232 | |
| 233 | std::string answer; |
| 234 | getline(std::cin, answer); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 235 | boost::algorithm::to_lower(answer); |
| 236 | if (answer == "yes") { |
Zhiyi Zhang | 44c6a35 | 2020-12-14 10:57:17 -0800 | [diff] [blame] | 237 | std::cerr << "You answered YES: new CA " << profile->caPrefix.toUri() << " will be used" << std::endl; |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 238 | runProbe(*profile); |
Zhiyi Zhang | caab546 | 2019-10-18 13:41:02 -0700 | [diff] [blame] | 239 | // client.getClientConf().save(std::string(SYSCONFDIR) + "/ndncert/client.conf"); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 240 | } |
| 241 | else { |
Zhiyi Zhang | 44c6a35 | 2020-12-14 10:57:17 -0800 | [diff] [blame] | 242 | std::cerr << "You answered NO: new CA " << profile->caPrefix.toUri() << " will not be used" << std::endl; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 243 | exit(0); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | static void |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 248 | probeCb(const Data& reply, CaProfile profile) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 249 | { |
tylerliu | b47dad7 | 2020-10-08 21:36:55 -0700 | [diff] [blame] | 250 | std::vector<std::pair<Name, int>> names; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 251 | std::vector<Name> redirects; |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 252 | Request::onProbeResponse(reply, profile, names, redirects); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 253 | size_t count = 0; |
| 254 | std::cerr << "\n***************************************\n" |
| 255 | << "Step " << nStep++ |
| 256 | << ": You can either select one of the following names suggested by the CA: " << std::endl; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 257 | for (const auto& name : names) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 258 | std::cerr << "> Index: " << count++ << std::endl |
tylerliu | b47dad7 | 2020-10-08 21:36:55 -0700 | [diff] [blame] | 259 | << ">> Suggested name: " << name.first.toUri() << std::endl |
| 260 | << ">> Corresponding Max sufiix length: " << name.second << std::endl; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 261 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 262 | std::cerr << "\nOr choose another trusted CA suggested by the CA: " << std::endl; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 263 | for (const auto& redirect : redirects) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 264 | std::cerr << "> Index: " << count++ << std::endl |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 265 | << ">> Suggested CA: " << security::extractIdentityFromCertName(redirect.getPrefix(-1)) << std::endl; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 266 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 267 | std::cerr << "Please type in the index of your choice:" << std::endl; |
| 268 | size_t index = 0; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 269 | try { |
| 270 | std::string input; |
| 271 | getline(std::cin, input); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 272 | index = std::stoul(input); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 273 | } |
| 274 | catch (const std::exception& e) { |
| 275 | std::cerr << "Your input is Invalid. Exit" << std::endl; |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 276 | exit(1); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 277 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 278 | if (index >= names.size() + redirects.size()) { |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 279 | std::cerr << "Your input is not an existing index. Exit" << std::endl; |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 280 | exit(1); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 281 | } |
| 282 | if (index < names.size()) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 283 | //names |
tylerliu | d82cc5c | 2020-12-21 23:58:39 -0800 | [diff] [blame] | 284 | auto selectedName = names[index].first; |
| 285 | std::cerr << "You selected name: " << selectedName.toUri() << std::endl; |
| 286 | std::cerr << "Enter Suffix if you would like one (Enter to skip): "; |
| 287 | try { |
| 288 | std::string input; |
| 289 | getline(std::cin, input); |
| 290 | auto inputName = Name(input); |
| 291 | if (!inputName.empty()) { |
| 292 | selectedName.append(inputName); |
| 293 | std::cerr << "You are applying name: " << selectedName.toUri() << std::endl; |
| 294 | } |
| 295 | } |
| 296 | catch (const std::exception& e) { |
| 297 | std::cerr << "Your input is Invalid. Exit" << std::endl; |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 298 | exit(1); |
tylerliu | d82cc5c | 2020-12-21 23:58:39 -0800 | [diff] [blame] | 299 | } |
| 300 | runNew(profile, selectedName); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 301 | } |
| 302 | else { |
| 303 | //redirects |
Zhiyi Zhang | fbcab84 | 2020-10-07 15:17:13 -0700 | [diff] [blame] | 304 | auto redirectedCaFullName = redirects[index - names.size()]; |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 305 | auto redirectedCaName = security::extractIdentityFromCertName(redirectedCaFullName.getPrefix(-1)); |
Zhiyi Zhang | 696cd04 | 2020-10-07 21:27:36 -0700 | [diff] [blame] | 306 | std::cerr << "You selected to be redirected to CA: " << redirectedCaName.toUri() << std::endl; |
Zhiyi Zhang | fbcab84 | 2020-10-07 15:17:13 -0700 | [diff] [blame] | 307 | face.expressInterest( |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 308 | *Request::genCaProfileDiscoveryInterest(redirectedCaName), |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 309 | [&] (const auto&, const auto& data) { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 310 | auto fetchingInterest = Request::genCaProfileInterestFromDiscoveryResponse(data); |
Zhiyi Zhang | fbcab84 | 2020-10-07 15:17:13 -0700 | [diff] [blame] | 311 | face.expressInterest(*fetchingInterest, |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 312 | [=] (const auto&, const auto& data2) { infoCb(data2, redirectedCaFullName); }, |
| 313 | [] (auto&&...) { onNackCb(); }, |
| 314 | [] (auto&&...) { timeoutCb(); }); |
Zhiyi Zhang | fbcab84 | 2020-10-07 15:17:13 -0700 | [diff] [blame] | 315 | }, |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 316 | [] (auto&&...) { onNackCb(); }, |
| 317 | [] (auto&&...) { timeoutCb(); }); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
| 321 | static void |
| 322 | selectCaProfile(std::string configFilePath) |
| 323 | { |
Zhiyi Zhang | a16b758 | 2020-10-29 18:59:46 -0700 | [diff] [blame] | 324 | ProfileStorage profileStorage; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 325 | try { |
Zhiyi Zhang | a16b758 | 2020-10-29 18:59:46 -0700 | [diff] [blame] | 326 | profileStorage.load(configFilePath); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 327 | } |
| 328 | catch (const std::exception& e) { |
| 329 | std::cerr << "Cannot load the configuration file: " << e.what() << std::endl; |
| 330 | exit(1); |
| 331 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 332 | size_t count = 0; |
| 333 | std::cerr << "***************************************\n" |
| 334 | << "Step " << nStep++ << ": CA SELECTION" << std::endl; |
Zhiyi Zhang | 84e1184 | 2020-11-19 20:03:23 -0800 | [diff] [blame] | 335 | for (auto item : profileStorage.getKnownProfiles()) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 336 | std::cerr << "> Index: " << count++ << std::endl |
Zhiyi Zhang | 44c6a35 | 2020-12-14 10:57:17 -0800 | [diff] [blame] | 337 | << ">> CA prefix:" << item.caPrefix << std::endl |
| 338 | << ">> Introduction: " << item.caInfo << std::endl; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 339 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 340 | std::cerr << "Please type in the CA's index that you want to apply or type in NONE if your expected CA is not in the list:\n"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 341 | |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 342 | std::string caIndexS, caIndexSLower; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 343 | getline(std::cin, caIndexS); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 344 | caIndexSLower = caIndexS; |
| 345 | boost::algorithm::to_lower(caIndexSLower); |
| 346 | if (caIndexSLower == "none") { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 347 | std::cerr << "\n***************************************\n" |
| 348 | << "Step " << nStep << ": ADD NEW CA\nPlease type in the CA's Name:" << std::endl; |
Zhiyi Zhang | caab546 | 2019-10-18 13:41:02 -0700 | [diff] [blame] | 349 | std::string expectedCAName; |
| 350 | getline(std::cin, expectedCAName); |
Zhiyi Zhang | fbcab84 | 2020-10-07 15:17:13 -0700 | [diff] [blame] | 351 | face.expressInterest( |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 352 | *Request::genCaProfileDiscoveryInterest(Name(expectedCAName)), |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 353 | [&] (const auto&, const auto& data) { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 354 | auto fetchingInterest = Request::genCaProfileInterestFromDiscoveryResponse(data); |
Zhiyi Zhang | fbcab84 | 2020-10-07 15:17:13 -0700 | [diff] [blame] | 355 | face.expressInterest(*fetchingInterest, |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 356 | [] (const auto&, const auto& data2) { infoCb(data2, {}); }, |
| 357 | [] (auto&&...) { onNackCb(); }, |
| 358 | [] (auto&&...) { timeoutCb(); }); |
Zhiyi Zhang | fbcab84 | 2020-10-07 15:17:13 -0700 | [diff] [blame] | 359 | }, |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 360 | [] (auto&&...) { onNackCb(); }, |
| 361 | [] (auto&&...) { timeoutCb(); }); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 362 | } |
| 363 | else { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 364 | size_t caIndex; |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 365 | try { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 366 | caIndex = std::stoul(caIndexS); |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 367 | } |
| 368 | catch (const std::exception& e) { |
| 369 | std::cerr << "Your input is neither NONE nor a valid index. Exit" << std::endl; |
| 370 | return; |
| 371 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 372 | if (caIndex >= count) { |
Zhiyi Zhang | 3670683 | 2019-07-04 21:33:03 -0700 | [diff] [blame] | 373 | std::cerr << "Your input is not an existing index. Exit" << std::endl; |
| 374 | return; |
| 375 | } |
Zhiyi Zhang | 84e1184 | 2020-11-19 20:03:23 -0800 | [diff] [blame] | 376 | auto itemIterator = profileStorage.getKnownProfiles().cbegin(); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 377 | std::advance(itemIterator, caIndex); |
| 378 | auto targetCaItem = *itemIterator; |
| 379 | runProbe(targetCaItem); |
| 380 | } |
| 381 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 382 | |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 383 | static void |
| 384 | runProbe(CaProfile profile) |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 385 | { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 386 | std::cerr << "\n***************************************\n" |
Zhiyi Zhang | 6bb1d08 | 2020-10-08 14:25:21 -0700 | [diff] [blame] | 387 | << "Step " << nStep++ |
| 388 | << ": Do you know your identity name to be certified by CA " |
Zhiyi Zhang | 44c6a35 | 2020-12-14 10:57:17 -0800 | [diff] [blame] | 389 | << profile.caPrefix.toUri() |
Zhiyi Zhang | 6bb1d08 | 2020-10-08 14:25:21 -0700 | [diff] [blame] | 390 | << " already? Type in YES or NO" << std::endl; |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 391 | bool validAnswer = false; |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 392 | size_t count = 0; |
| 393 | while (!validAnswer && count < 3) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 394 | std::string answer; |
| 395 | getline(std::cin, answer); |
| 396 | boost::algorithm::to_lower(answer); |
| 397 | if (answer == "yes") { |
| 398 | validAnswer = true; |
| 399 | std::cerr << "You answered YES" << std::endl; |
| 400 | std::cerr << "\n***************************************\n" |
| 401 | << "Step " << nStep++ |
Zhiyi Zhang | 6bb1d08 | 2020-10-08 14:25:21 -0700 | [diff] [blame] | 402 | << ": Please type in the full identity name you want to get (with CA prefix " |
Zhiyi Zhang | 44c6a35 | 2020-12-14 10:57:17 -0800 | [diff] [blame] | 403 | << profile.caPrefix.toUri() |
Zhiyi Zhang | 6bb1d08 | 2020-10-08 14:25:21 -0700 | [diff] [blame] | 404 | << "):" << std::endl; |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 405 | std::string identityNameStr; |
| 406 | getline(std::cin, identityNameStr); |
| 407 | runNew(profile, Name(identityNameStr)); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 408 | } |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 409 | else if (answer == "no") { |
| 410 | validAnswer = true; |
| 411 | std::cerr << "You answered NO" << std::endl; |
| 412 | std::cerr << "\n***************************************\n" |
| 413 | << "Step " << nStep++ << ": Please provide information for name assignment" << std::endl; |
Zhiyi Zhang | 44c6a35 | 2020-12-14 10:57:17 -0800 | [diff] [blame] | 414 | auto capturedParams = captureParams(profile.probeParameterKeys); |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 415 | face.expressInterest(*Request::genProbeInterest(profile, std::move(capturedParams)), |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 416 | [profile] (const auto&, const auto& data) { probeCb(data, profile); }, |
| 417 | [] (auto&&...) { onNackCb(); }, |
| 418 | [] (auto&&...) { timeoutCb(); }); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 419 | } |
| 420 | else { |
| 421 | std::cerr << "Invalid answer. Type in YES or NO" << std::endl; |
Zhiyi Zhang | 87ded73 | 2021-01-08 14:05:24 -0800 | [diff] [blame] | 422 | count++; |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
Zhiyi Zhang | 17720f2 | 2021-01-08 14:12:56 -0800 | [diff] [blame] | 425 | if (count == 3) { |
| 426 | std::cerr << "Invalid input for too many times, exit. " << std::endl; |
| 427 | exit(1); |
| 428 | } |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static void |
| 432 | runNew(CaProfile profile, Name identityName) |
| 433 | { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 434 | int validityPeriod = captureValidityPeriod(); |
| 435 | auto now = time::system_clock::now(); |
| 436 | std::cerr << "The validity period of your certificate will be: " << validityPeriod << " hours" << std::endl; |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 437 | requesterState = std::make_shared<Request>(keyChain, profile, RequestType::NEW); |
| 438 | auto interest = requesterState->genNewInterest(identityName, now, now + time::hours(validityPeriod)); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 439 | if (interest != nullptr) { |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 440 | face.expressInterest(*interest, |
| 441 | [] (const auto&, const auto& data) { newCb(data); }, |
| 442 | [] (auto&&...) { onNackCb(); }, |
| 443 | [] (auto&&...) { timeoutCb(); }); |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 444 | } |
| 445 | else { |
| 446 | std::cerr << "Cannot generate the Interest for NEW step. Exit" << std::endl; |
| 447 | } |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static void |
| 451 | runChallenge(const std::string& challengeType) |
| 452 | { |
tylerliu | 4022633 | 2020-11-11 15:37:16 -0800 | [diff] [blame] | 453 | std::multimap<std::string, std::string> requirement; |
Zhiyi Zhang | c5d93a9 | 2020-10-14 17:07:35 -0700 | [diff] [blame] | 454 | try { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 455 | requirement = requesterState->selectOrContinueChallenge(challengeType); |
Zhiyi Zhang | c5d93a9 | 2020-10-14 17:07:35 -0700 | [diff] [blame] | 456 | } |
| 457 | catch (const std::exception& e) { |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 458 | std::cerr << "Error. Cannot successfully load the Challenge Module with error: " << e.what() |
| 459 | << "\nExit." << std::endl; |
Zhiyi Zhang | c5d93a9 | 2020-10-14 17:07:35 -0700 | [diff] [blame] | 460 | exit(1); |
| 461 | } |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 462 | if (requirement.size() > 0) { |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 463 | std::cerr << "\n***************************************\n" |
| 464 | << "Step " << nStep |
| 465 | << ": Please provide parameters used for Identity Verification Challenge" << std::endl; |
| 466 | captureParams(requirement); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 467 | } |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 468 | face.expressInterest(*requesterState->genChallengeInterest(std::move(requirement)), |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 469 | [] (const auto&, const auto& data) { challengeCb(data); }, |
| 470 | [] (auto&&...) { onNackCb(); }, |
| 471 | [] (auto&&...) { timeoutCb(); }); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 474 | static void |
| 475 | handleSignal(const boost::system::error_code& error, int signalNum) |
| 476 | { |
| 477 | if (error) { |
| 478 | return; |
| 479 | } |
| 480 | const char* signalName = ::strsignal(signalNum); |
| 481 | std::cerr << "Exiting on signal "; |
| 482 | if (signalName == nullptr) { |
| 483 | std::cerr << signalNum; |
| 484 | } |
| 485 | else { |
| 486 | std::cerr << signalName; |
| 487 | } |
| 488 | std::cerr << std::endl; |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 489 | if (requesterState) { |
tylerliu | 4140fe8 | 2021-01-27 15:45:44 -0800 | [diff] [blame] | 490 | requesterState->endSession(); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 491 | } |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 492 | face.getIoService().stop(); |
tylerliu | feabfdc | 2020-10-03 15:09:58 -0700 | [diff] [blame] | 493 | exit(1); |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 494 | } |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 495 | |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 496 | static int |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 497 | main(int argc, char* argv[]) |
| 498 | { |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 499 | boost::asio::signal_set terminateSignals(face.getIoService()); |
| 500 | terminateSignals.add(SIGINT); |
| 501 | terminateSignals.add(SIGTERM); |
| 502 | terminateSignals.async_wait(handleSignal); |
| 503 | |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 504 | namespace po = boost::program_options; |
Zhiyi Zhang | 840afd9 | 2020-10-21 13:24:08 -0700 | [diff] [blame] | 505 | std::string configFilePath = std::string(NDNCERT_SYSCONFDIR) + "/ndncert/client.conf"; |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 506 | po::options_description description("Usage: ndncert-client [-h] [-c FILE]\n"); |
| 507 | description.add_options() |
| 508 | ("help,h", "produce help message") |
| 509 | ("config-file,c", po::value<std::string>(&configFilePath), "configuration file name") |
| 510 | ; |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 511 | po::positional_options_description p; |
| 512 | |
| 513 | po::variables_map vm; |
| 514 | try { |
| 515 | po::store(po::command_line_parser(argc, argv).options(description).positional(p).run(), vm); |
| 516 | po::notify(vm); |
| 517 | } |
| 518 | catch (const std::exception& e) { |
| 519 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 520 | return 1; |
| 521 | } |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 522 | |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 523 | if (vm.count("help") != 0) { |
| 524 | std::cerr << description << std::endl; |
| 525 | return 0; |
| 526 | } |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 527 | |
Zhiyi Zhang | 837406d | 2020-10-05 22:01:31 -0700 | [diff] [blame] | 528 | selectCaProfile(configFilePath); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 529 | face.processEvents(); |
| 530 | return 0; |
| 531 | } |
| 532 | |
Zhiyi Zhang | 3002e6b | 2020-10-29 18:54:07 -0700 | [diff] [blame] | 533 | } // namespace requester |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 534 | } // namespace ndncert |
| 535 | } // namespace ndn |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 536 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 537 | int |
| 538 | main(int argc, char* argv[]) |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 539 | { |
Zhiyi Zhang | 3002e6b | 2020-10-29 18:54:07 -0700 | [diff] [blame] | 540 | return ndn::ndncert::requester::main(argc, argv); |
Zhiyi Zhang | 08e0e98 | 2017-03-01 10:10:42 -0800 | [diff] [blame] | 541 | } |