blob: 5ca6aaa0692f3bf0e2684bd5a1c55dd8a31efcc4 [file] [log] [blame]
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017-2020, Regents of the University of California.
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 "requester.hpp"
Zhiyi Zhang84e11842020-11-19 20:03:23 -080022#include "challenge/challenge-module.hpp"
Zhiyi Zhangdc25ddf2020-10-20 14:28:55 -070023#include "detail/crypto-helpers.hpp"
Zhiyi Zhang062be6d2020-10-14 17:13:43 -070024#include "detail/challenge-encoder.hpp"
25#include "detail/error-encoder.hpp"
26#include "detail/info-encoder.hpp"
27#include "detail/new-renew-revoke-encoder.hpp"
28#include "detail/probe-encoder.hpp"
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070029#include <ndn-cxx/security/signing-helpers.hpp>
30#include <ndn-cxx/security/transform/base64-encode.hpp>
31#include <ndn-cxx/security/transform/buffer-source.hpp>
32#include <ndn-cxx/security/transform/stream-sink.hpp>
33#include <ndn-cxx/security/verification-helpers.hpp>
34#include <ndn-cxx/util/io.hpp>
35#include <ndn-cxx/util/random.hpp>
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070036#include <ndn-cxx/metadata-object.hpp>
tylerliu96a67e82020-10-15 13:37:12 -070037#include <boost/lexical_cast.hpp>
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070038
39namespace ndn {
40namespace ndncert {
Zhiyi Zhang3002e6b2020-10-29 18:54:07 -070041namespace requester {
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070042
Zhiyi Zhangd61b4a82020-10-10 15:18:43 -070043NDN_LOG_INIT(ndncert.client);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070044
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070045shared_ptr<Interest>
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070046Requester::genCaProfileDiscoveryInterest(const Name& caName)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070047{
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070048 Name contentName = caName;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070049 if (readString(caName.at(-1)) != "CA")
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070050 contentName.append("CA");
51 contentName.append("INFO");
52 return std::make_shared<Interest>(MetadataObject::makeDiscoveryInterest(contentName));
53}
54
55shared_ptr<Interest>
56Requester::genCaProfileInterestFromDiscoveryResponse(const Data& reply)
57{
Zhiyi Zhang615b6b72021-01-11 14:25:32 -080058 // set naming convention to be typed
59 auto convention = name::getConventionEncoding();
60 name::setConventionEncoding(name::Convention::TYPED);
61
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070062 auto metaData = MetadataObject(reply);
63 auto interestName= metaData.getVersionedName();
64 interestName.appendSegment(0);
65 auto interest = std::make_shared<Interest>(interestName);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070066 interest->setCanBePrefix(false);
Zhiyi Zhang615b6b72021-01-11 14:25:32 -080067
68 // set back the convention
69 name::setConventionEncoding(convention);
70
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070071 return interest;
72}
73
Zhiyi Zhang997669a2020-10-28 21:15:40 -070074optional<CaProfile>
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070075Requester::onCaProfileResponse(const Data& reply)
76{
Zhiyi Zhangf22ae242020-11-17 10:51:15 -080077 auto caItem = infotlv::decodeDataContent(reply.getContent());
Zhiyi Zhang44c6a352020-12-14 10:57:17 -080078 if (!security::verifySignature(reply, *caItem.cert)) {
Zhiyi Zhangd61b4a82020-10-10 15:18:43 -070079 NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
tylerliu41c11532020-10-10 16:14:45 -070080 NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070081 }
82 return caItem;
83}
84
Zhiyi Zhang997669a2020-10-28 21:15:40 -070085optional<CaProfile>
Zhiyi Zhang837406d2020-10-05 22:01:31 -070086Requester::onCaProfileResponseAfterRedirection(const Data& reply, const Name& caCertFullName)
87{
Zhiyi Zhangf22ae242020-11-17 10:51:15 -080088 auto caItem = infotlv::decodeDataContent(reply.getContent());
Zhiyi Zhang44c6a352020-12-14 10:57:17 -080089 auto certBlock = caItem.cert->wireEncode();
90 caItem.cert = std::make_shared<security::Certificate>(certBlock);
91 if (caItem.cert->getFullName() != caCertFullName) {
Zhiyi Zhangd61b4a82020-10-10 15:18:43 -070092 NDN_LOG_ERROR("Ca profile does not match the certificate information offered by the original CA.");
tylerliu41c11532020-10-10 16:14:45 -070093 NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
Zhiyi Zhang837406d2020-10-05 22:01:31 -070094 }
95 return onCaProfileResponse(reply);
96}
97
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -070098shared_ptr<Interest>
tylerliu40226332020-11-11 15:37:16 -080099Requester::genProbeInterest(const CaProfile& ca, std::multimap<std::string, std::string>&& probeInfo)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700100{
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800101 Name interestName = ca.caPrefix;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700102 interestName.append("CA").append("PROBE");
Zhiyi Zhang32437282020-10-10 16:15:37 -0700103 auto interest =std::make_shared<Interest>(interestName);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700104 interest->setMustBeFresh(true);
105 interest->setCanBePrefix(false);
Zhiyi Zhangf22ae242020-11-17 10:51:15 -0800106 interest->setApplicationParameters(probetlv::encodeApplicationParameters(std::move(probeInfo)));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700107 return interest;
108}
109
110void
111Requester::onProbeResponse(const Data& reply, const CaProfile& ca,
tylerliub47dad72020-10-08 21:36:55 -0700112 std::vector<std::pair<Name, int>>& identityNames, std::vector<Name>& otherCas)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700113{
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800114 if (!security::verifySignature(reply, *ca.cert)) {
Zhiyi Zhangd61b4a82020-10-10 15:18:43 -0700115 NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
tylerliu41c11532020-10-10 16:14:45 -0700116 NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700117 return;
118 }
119 processIfError(reply);
Zhiyi Zhangf22ae242020-11-17 10:51:15 -0800120 probetlv::decodeDataContent(reply.getContent(), identityNames, otherCas);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700121}
122
123shared_ptr<Interest>
tylerliubb630362020-11-10 11:31:35 -0800124Requester::genNewInterest(RequestState& state, const Name& identityName,
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700125 const time::system_clock::TimePoint& notBefore,
126 const time::system_clock::TimePoint& notAfter)
127{
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800128 if (!state.caProfile.caPrefix.isPrefixOf(identityName)) {
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700129 return nullptr;
130 }
131 if (identityName.empty()) {
132 NDN_LOG_TRACE("Randomly create a new name because identityName is empty and the param is empty.");
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800133 state.identityName = state.caProfile.caPrefix;
tylerliuf2e6bb52020-12-13 13:23:05 -0800134 state.identityName.append(std::to_string(random::generateSecureWord64()));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700135 }
136 else {
tylerliuf2e6bb52020-12-13 13:23:05 -0800137 state.identityName = identityName;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700138 }
139
140 // generate a newly key pair or use an existing key
tylerliuf2e6bb52020-12-13 13:23:05 -0800141 const auto& pib = state.keyChain.getPib();
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700142 security::pib::Identity identity;
143 try {
tylerliuf2e6bb52020-12-13 13:23:05 -0800144 identity = pib.getIdentity(state.identityName);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700145 }
146 catch (const security::Pib::Error& e) {
tylerliuf2e6bb52020-12-13 13:23:05 -0800147 identity = state.keyChain.createIdentity(state.identityName);
148 state.isNewlyCreatedIdentity = true;
149 state.isNewlyCreatedKey = true;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700150 }
151 try {
tylerliuf2e6bb52020-12-13 13:23:05 -0800152 state.keyPair = identity.getDefaultKey();
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700153 }
154 catch (const security::Pib::Error& e) {
tylerliuf2e6bb52020-12-13 13:23:05 -0800155 state.keyPair = state.keyChain.createKey(identity);
156 state.isNewlyCreatedKey = true;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700157 }
tylerliuf2e6bb52020-12-13 13:23:05 -0800158 auto& keyName = state.keyPair.getName();
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700159
160 // generate certificate request
tylerliua7bea662020-10-08 18:51:02 -0700161 security::Certificate certRequest;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700162 certRequest.setName(Name(keyName).append("cert-request").appendVersion());
Zhiyi Zhang8f1ade32020-10-14 16:42:57 -0700163 certRequest.setContentType(ndn::tlv::ContentType_Key);
tylerliuf2e6bb52020-12-13 13:23:05 -0800164 certRequest.setContent(state.keyPair.getPublicKey().data(), state.keyPair.getPublicKey().size());
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700165 SignatureInfo signatureInfo;
166 signatureInfo.setValidityPeriod(security::ValidityPeriod(notBefore, notAfter));
tylerliuf2e6bb52020-12-13 13:23:05 -0800167 state.keyChain.sign(certRequest, signingByKey(keyName).setSignatureInfo(signatureInfo));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700168
169 // generate Interest packet
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800170 Name interestName = state.caProfile.caPrefix;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700171 interestName.append("CA").append("NEW");
Zhiyi Zhang32437282020-10-10 16:15:37 -0700172 auto interest =std::make_shared<Interest>(interestName);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700173 interest->setMustBeFresh(true);
174 interest->setCanBePrefix(false);
175 interest->setApplicationParameters(
tylerliuf2e6bb52020-12-13 13:23:05 -0800176 requesttlv::encodeApplicationParameters(RequestType::NEW, state.ecdh.getSelfPubKey(), certRequest));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700177
178 // sign the Interest packet
tylerliuf2e6bb52020-12-13 13:23:05 -0800179 state.keyChain.sign(*interest, signingByKey(keyName));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700180 return interest;
181}
182
183shared_ptr<Interest>
tylerliubb630362020-11-10 11:31:35 -0800184Requester::genRevokeInterest(RequestState& state, const security::Certificate& certificate)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700185{
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800186 if (!state.caProfile.caPrefix.isPrefixOf(certificate.getName())) {
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700187 return nullptr;
188 }
189 // generate Interest packet
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800190 Name interestName = state.caProfile.caPrefix;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700191 interestName.append("CA").append("REVOKE");
Zhiyi Zhang32437282020-10-10 16:15:37 -0700192 auto interest =std::make_shared<Interest>(interestName);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700193 interest->setMustBeFresh(true);
194 interest->setCanBePrefix(false);
195 interest->setApplicationParameters(
tylerliuf2e6bb52020-12-13 13:23:05 -0800196 requesttlv::encodeApplicationParameters(RequestType::REVOKE, state.ecdh.getSelfPubKey(), certificate));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700197 return interest;
198}
199
200std::list<std::string>
tylerliubb630362020-11-10 11:31:35 -0800201Requester::onNewRenewRevokeResponse(RequestState& state, const Data& reply)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700202{
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800203 if (!security::verifySignature(reply, *state.caProfile.cert)) {
Zhiyi Zhangd61b4a82020-10-10 15:18:43 -0700204 NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
tylerliu41c11532020-10-10 16:14:45 -0700205 NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700206 }
207 processIfError(reply);
208
209 auto contentTLV = reply.getContent();
Zhiyi Zhangbed854c2020-10-20 18:25:35 -0700210 std::vector<uint8_t> ecdhKey;
211 std::array<uint8_t, 32> salt;
tylerliuf2e6bb52020-12-13 13:23:05 -0800212 auto challenges = requesttlv::decodeDataContent(contentTLV, ecdhKey, salt, state.requestId, state.status);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700213
Zhiyi Zhang91f86ab2020-10-05 15:36:35 -0700214 // ECDH and HKDF
tylerliuf2e6bb52020-12-13 13:23:05 -0800215 auto sharedSecret = state.ecdh.deriveSecret(ecdhKey);
Zhiyi Zhangbed854c2020-10-20 18:25:35 -0700216 hkdf(sharedSecret.data(), sharedSecret.size(),
tylerliuf2e6bb52020-12-13 13:23:05 -0800217 salt.data(), salt.size(), state.aesKey.data(), state.aesKey.size());
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700218
219 // update state
Zhiyi Zhangbed854c2020-10-20 18:25:35 -0700220 return challenges;
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700221}
222
tylerliu40226332020-11-11 15:37:16 -0800223std::multimap<std::string, std::string>
tylerliubb630362020-11-10 11:31:35 -0800224Requester::selectOrContinueChallenge(RequestState& state, const std::string& challengeSelected)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700225{
226 auto challenge = ChallengeModule::createChallengeModule(challengeSelected);
227 if (challenge == nullptr) {
tylerliu41c11532020-10-10 16:14:45 -0700228 NDN_THROW(std::runtime_error("The challenge selected is not supported by your current version of NDNCERT."));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700229 }
tylerliuf2e6bb52020-12-13 13:23:05 -0800230 state.challengeType = challengeSelected;
231 return challenge->getRequestedParameterList(state.status, state.challengeStatus);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700232}
233
234shared_ptr<Interest>
tylerliubb630362020-11-10 11:31:35 -0800235Requester::genChallengeInterest(RequestState& state,
tylerliu40226332020-11-11 15:37:16 -0800236 std::multimap<std::string, std::string>&& parameters)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700237{
tylerliuf2e6bb52020-12-13 13:23:05 -0800238 if (state.challengeType == "") {
tylerliu41c11532020-10-10 16:14:45 -0700239 NDN_THROW(std::runtime_error("The challenge has not been selected."));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700240 }
tylerliuf2e6bb52020-12-13 13:23:05 -0800241 auto challenge = ChallengeModule::createChallengeModule(state.challengeType);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700242 if (challenge == nullptr) {
tylerliu41c11532020-10-10 16:14:45 -0700243 NDN_THROW(std::runtime_error("The challenge selected is not supported by your current version of NDNCERT."));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700244 }
tylerliuf2e6bb52020-12-13 13:23:05 -0800245 auto challengeParams = challenge->genChallengeRequestTLV(state.status, state.challengeStatus, std::move(parameters));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700246
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800247 Name interestName = state.caProfile.caPrefix;
tylerliuf2e6bb52020-12-13 13:23:05 -0800248 interestName.append("CA").append("CHALLENGE").append(state.requestId.data(), state.requestId.size());
Zhiyi Zhang32437282020-10-10 16:15:37 -0700249 auto interest =std::make_shared<Interest>(interestName);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700250 interest->setMustBeFresh(true);
251 interest->setCanBePrefix(false);
252
253 // encrypt the Interest parameters
tylerliuf2e6bb52020-12-13 13:23:05 -0800254 auto paramBlock = encodeBlockWithAesGcm128(ndn::tlv::ApplicationParameters, state.aesKey.data(),
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700255 challengeParams.value(), challengeParams.value_size(),
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800256 state.requestId.data(), state.requestId.size(),
257 state.encryptionIv);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700258 interest->setApplicationParameters(paramBlock);
tylerliuf2e6bb52020-12-13 13:23:05 -0800259 state.keyChain.sign(*interest, signingByKey(state.keyPair.getName()));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700260 return interest;
261}
262
263void
tylerliubb630362020-11-10 11:31:35 -0800264Requester::onChallengeResponse(RequestState& state, const Data& reply)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700265{
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800266 if (!security::verifySignature(reply, *state.caProfile.cert)) {
Zhiyi Zhangd61b4a82020-10-10 15:18:43 -0700267 NDN_LOG_ERROR("Cannot verify replied Data packet signature.");
tylerliu41c11532020-10-10 16:14:45 -0700268 NDN_THROW(std::runtime_error("Cannot verify replied Data packet signature."));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700269 }
270 processIfError(reply);
Zhiyi Zhangf22ae242020-11-17 10:51:15 -0800271 challengetlv::decodeDataContent(reply.getContent(), state);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700272}
273
274shared_ptr<Interest>
tylerliubb630362020-11-10 11:31:35 -0800275Requester::genCertFetchInterest(const RequestState& state)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700276{
tylerliuf2e6bb52020-12-13 13:23:05 -0800277 Name interestName = state.issuedCertName;
Zhiyi Zhang32437282020-10-10 16:15:37 -0700278 auto interest =std::make_shared<Interest>(interestName);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700279 interest->setMustBeFresh(false);
280 interest->setCanBePrefix(false);
281 return interest;
282}
283
tylerliua7bea662020-10-08 18:51:02 -0700284shared_ptr<security::Certificate>
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700285Requester::onCertFetchResponse(const Data& reply)
286{
287 try {
tylerliua7bea662020-10-08 18:51:02 -0700288 return std::make_shared<security::Certificate>(reply);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700289 }
290 catch (const std::exception& e) {
Zhiyi Zhangd61b4a82020-10-10 15:18:43 -0700291 NDN_LOG_ERROR("Cannot parse replied certificate ");
tylerliu41c11532020-10-10 16:14:45 -0700292 NDN_THROW(std::runtime_error("Cannot parse replied certificate "));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700293 return nullptr;
294 }
295}
296
297void
tylerliubb630362020-11-10 11:31:35 -0800298Requester::endSession(RequestState& state)
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700299{
tylerliuf2e6bb52020-12-13 13:23:05 -0800300 if (state.status == Status::SUCCESS) {
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700301 return;
302 }
tylerliuf2e6bb52020-12-13 13:23:05 -0800303 if (state.isNewlyCreatedIdentity) {
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700304 // put the identity into the if scope is because it may cause an error
305 // outside since when endSession is called, identity may not have been created yet.
tylerliuf2e6bb52020-12-13 13:23:05 -0800306 auto identity = state.keyChain.getPib().getIdentity(state.identityName);
307 state.keyChain.deleteIdentity(identity);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700308 }
tylerliuf2e6bb52020-12-13 13:23:05 -0800309 else if (state.isNewlyCreatedKey) {
310 auto identity = state.keyChain.getPib().getIdentity(state.identityName);
311 state.keyChain.deleteKey(identity, state.keyPair);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700312 }
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700313}
314
315void
316Requester::processIfError(const Data& data)
317{
Zhiyi Zhangf22ae242020-11-17 10:51:15 -0800318 auto errorInfo = errortlv::decodefromDataContent(data.getContent());
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700319 if (std::get<0>(errorInfo) == ErrorCode::NO_ERROR) {
320 return;
321 }
Zhiyi Zhang1a222692020-10-16 11:35:49 -0700322 NDN_LOG_ERROR("Error info replied from the CA with Error code: " << std::get<0>(errorInfo) <<
323 " and Error Info: " << std::get<1>(errorInfo));
tylerliu41c11532020-10-10 16:14:45 -0700324 NDN_THROW(std::runtime_error("Error info replied from the CA with Error code: " +
Zhiyi Zhang1a222692020-10-16 11:35:49 -0700325 boost::lexical_cast<std::string>(std::get<0>(errorInfo)) +
326 " and Error Info: " + std::get<1>(errorInfo)));
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700327}
328
Zhiyi Zhang3002e6b2020-10-29 18:54:07 -0700329} // namespace requester
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700330} // namespace ndncert
331} // namespace ndn