Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -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 | f5246c4 | 2017-01-26 09:39:20 -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 "ca-module.hpp" |
| 22 | #include "challenge-module.hpp" |
| 23 | #include "logging.hpp" |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 24 | #include "crypto-support/enc-tlv.hpp" |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 25 | #include <ndn-cxx/util/io.hpp> |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 26 | #include <ndn-cxx/security/verification-helpers.hpp> |
| 27 | #include <ndn-cxx/security/signing-helpers.hpp> |
Junxiao Shi | 7c06803 | 2017-05-28 13:40:47 +0000 | [diff] [blame] | 28 | #include <ndn-cxx/util/random.hpp> |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -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 const int IS_SUBNAME_MIN_OFFSET = 5; |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 34 | static const time::seconds DEFAULT_DATA_FRESHNESS_PERIOD = 1_s; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 35 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 36 | _LOG_INIT(ndncert.ca); |
| 37 | |
| 38 | CaModule::CaModule(Face& face, security::v2::KeyChain& keyChain, |
| 39 | const std::string& configPath, const std::string& storageType) |
| 40 | : m_face(face) |
| 41 | , m_keyChain(keyChain) |
| 42 | { |
Zhiyi Zhang | a63b737 | 2017-05-17 14:14:34 -0700 | [diff] [blame] | 43 | // load the config and create storage |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 44 | m_config.load(configPath); |
| 45 | m_storage = CaStorage::createCaStorage(storageType); |
| 46 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 47 | registerPrefix(); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | CaModule::~CaModule() |
| 51 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 52 | for (auto handle : m_interestFilterHandles) { |
| 53 | handle.cancel(); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 54 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 55 | for (auto handle : m_registeredPrefixHandles) { |
| 56 | handle.unregister(); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | void |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 61 | CaModule::registerPrefix() |
| 62 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 63 | // register localhop discovery prefix |
| 64 | Name localhopProbePrefix("/localhop/CA/PROBE/INFO"); |
| 65 | auto prefixId = m_face.setInterestFilter(InterestFilter(localhopProbePrefix), |
| 66 | bind(&CaModule::onProbe, this, _2), |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 67 | bind(&CaModule::onRegisterFailed, this, _2)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 68 | m_registeredPrefixHandles.push_back(prefixId); |
| 69 | _LOG_TRACE("Prefix " << localhopProbePrefix << " got registered"); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 70 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 71 | // register prefixes |
| 72 | Name prefix = m_config.m_caName; |
| 73 | prefix.append("CA"); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 74 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 75 | prefixId = m_face.registerPrefix(prefix, |
| 76 | [&] (const Name& name) { |
| 77 | // register PROBE prefix |
| 78 | auto filterId = m_face.setInterestFilter(Name(name).append("_PROBE"), |
| 79 | bind(&CaModule::onProbe, this, _2)); |
| 80 | m_interestFilterHandles.push_back(filterId); |
| 81 | |
| 82 | // register NEW prefix |
| 83 | filterId = m_face.setInterestFilter(Name(name).append("_NEW"), |
| 84 | bind(&CaModule::onNew, this, _2)); |
| 85 | m_interestFilterHandles.push_back(filterId); |
| 86 | |
| 87 | // register SELECT prefix |
| 88 | filterId = m_face.setInterestFilter(Name(name).append("_CHALLENGE"), |
| 89 | bind(&CaModule::onChallenge, this, _2)); |
| 90 | m_interestFilterHandles.push_back(filterId); |
| 91 | |
| 92 | // register DOWNLOAD prefix |
| 93 | filterId = m_face.setInterestFilter(Name(name).append("_DOWNLOAD"), |
| 94 | bind(&CaModule::onDownload, this, _2)); |
| 95 | m_interestFilterHandles.push_back(filterId); |
| 96 | _LOG_TRACE("Prefix " << name << " got registered"); |
| 97 | }, |
| 98 | bind(&CaModule::onRegisterFailed, this, _2)); |
| 99 | m_registeredPrefixHandles.push_back(prefixId); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 100 | } |
| 101 | |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 102 | bool |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 103 | CaModule::setProbeHandler(const ProbeHandler& handler) |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 104 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 105 | m_config.m_probeHandler = handler; |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 106 | return false; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 107 | } |
| 108 | |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 109 | bool |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 110 | CaModule::setStatusUpdateCallback(const StatusUpdateCallback& onUpdateCallback) |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 111 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 112 | m_config.m_statusUpdateCallback = onUpdateCallback; |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 113 | return false; |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 117 | CaModule::onProbe(const Interest& request) |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 118 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 119 | // PROBE Naming Convention: /<CA-Prefix>/CA/PROBE/[ParametersSha256DigestComponent|INFO] |
| 120 | _LOG_TRACE("Receive PROBE request"); |
| 121 | JsonSection contentJson; |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 122 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 123 | // process PROBE INFO requests |
| 124 | if (readString(request.getName().at(-1)) == "INFO") { |
| 125 | contentJson = genProbeResponseJson(); |
| 126 | } |
| 127 | else { |
| 128 | // if not a PROBE INFO, find an available name |
| 129 | std::string availableId = ""; |
| 130 | const auto& parameterJson = jsonFromBlock(request.getApplicationParameters()); |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 131 | if (parameterJson.empty()) { |
| 132 | _LOG_ERROR("Empty JSON obtained from the Interest parameter."); |
| 133 | return; |
| 134 | } |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 135 | //std::string probeInfoStr = parameterJson.get(JSON_CLIENT_PROBE_INFO, ""); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 136 | if (m_config.m_probeHandler) { |
| 137 | try { |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 138 | availableId = m_config.m_probeHandler(parameterJson); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 139 | } |
| 140 | catch (const std::exception& e) { |
| 141 | _LOG_TRACE("Cannot find PROBE input from PROBE parameters " << e.what()); |
| 142 | return; |
| 143 | } |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 144 | } |
| 145 | else { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 146 | // if there is no app-specified name lookup, use a random name id |
| 147 | availableId = std::to_string(random::generateSecureWord64()); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 148 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 149 | Name newIdentityName = m_config.m_caName; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 150 | newIdentityName.append(availableId); |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 151 | _LOG_TRACE("Handle PROBE: generate an identity " << newIdentityName); |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 152 | contentJson = genProbeResponseJson(newIdentityName.toUri(), m_config.m_probe, parameterJson); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 153 | } |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 154 | |
| 155 | Data result; |
| 156 | result.setName(request.getName()); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 157 | result.setContent(dataContentFromJson(contentJson)); |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 158 | result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 159 | m_keyChain.sign(result, signingByIdentity(m_config.m_caName)); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 160 | m_face.put(result); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 161 | _LOG_TRACE("Handle PROBE: send out the PROBE response"); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 165 | CaModule::onNew(const Interest& request) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 166 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 167 | // NEW Naming Convention: /<CA-prefix>/CA/NEW/[SignedInterestParameters_Digest] |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 168 | // get ECDH pub key and cert request |
| 169 | const auto& parameterJson = jsonFromBlock(request.getApplicationParameters()); |
Zhiyi Zhang | 547c851 | 2019-06-18 23:46:14 -0700 | [diff] [blame] | 170 | if (parameterJson.empty()) { |
| 171 | _LOG_ERROR("Empty JSON obtained from the Interest parameter."); |
| 172 | return; |
| 173 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 174 | std::string peerKeyBase64 = parameterJson.get(JSON_CLIENT_ECDH, ""); |
| 175 | |
| 176 | // get server's ECDH pub key |
| 177 | auto myEcdhPubKeyBase64 = m_ecdh.getBase64PubKey(); |
| 178 | m_ecdh.deriveSecret(peerKeyBase64); |
| 179 | // generate salt for HKDF |
| 180 | auto saltInt = random::generateSecureWord64(); |
| 181 | uint8_t salt[sizeof(saltInt)]; |
| 182 | std::memcpy(salt, &saltInt, sizeof(saltInt)); |
| 183 | // hkdf |
| 184 | hkdf(m_ecdh.context->sharedSecret, m_ecdh.context->sharedSecretLen, |
| 185 | salt, sizeof(saltInt), m_aesKey, 32); |
| 186 | |
| 187 | // parse certificate request |
| 188 | std::string certRequestStr = parameterJson.get(JSON_CLIENT_CERT_REQ, ""); |
| 189 | shared_ptr<security::v2::Certificate> clientCert = nullptr; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 190 | try { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 191 | std::stringstream ss(certRequestStr); |
| 192 | clientCert = io::load<security::v2::Certificate>(ss); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 193 | } |
| 194 | catch (const std::exception& e) { |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 195 | _LOG_ERROR("Unrecognized certificate request " << e.what()); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 196 | return; |
| 197 | } |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 198 | |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 199 | // parse probe token if any |
| 200 | std::string probeTokenStr = parameterJson.get("probe-token", ""); |
| 201 | shared_ptr<Data> probeToken = nullptr; |
| 202 | if (probeTokenStr != "") { |
| 203 | try { |
| 204 | std::stringstream ss(probeTokenStr); |
Zhiyi Zhang | a1fc623 | 2019-06-13 14:56:59 -0700 | [diff] [blame] | 205 | probeToken = io::load<Data>(ss); |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 206 | } |
| 207 | catch (const std::exception& e) { |
| 208 | _LOG_ERROR("Unrecognized probe token " << e.what()); |
| 209 | return; |
| 210 | } |
| 211 | } |
Zhiyi Zhang | a1fc623 | 2019-06-13 14:56:59 -0700 | [diff] [blame] | 212 | if (probeToken == nullptr && m_config.m_probe != "") { |
| 213 | // the CA requires PROBE before NEW |
| 214 | _LOG_ERROR("CA requires PROBE but no PROBE token is found in NEW Interest."); |
| 215 | return; |
| 216 | } |
| 217 | else if (probeToken != nullptr) { |
| 218 | // check whether the carried probe token is a PROBE Data packet |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 219 | Name prefix = m_config.m_caName; |
| 220 | prefix.append("CA").append("_PROBE"); |
| 221 | if (!prefix.isPrefixOf(probeToken->getName())) { |
Zhiyi Zhang | a1fc623 | 2019-06-13 14:56:59 -0700 | [diff] [blame] | 222 | _LOG_ERROR("Carried PROBE token is not a valid PROBE Data packet."); |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 223 | return; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | // verify the self-signed certificate, the request, and the token |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 228 | if (!m_config.m_caName.isPrefixOf(clientCert->getName()) // under ca prefix |
| 229 | || !security::v2::Certificate::isValidName(clientCert->getName()) // is valid cert name |
| 230 | || clientCert->getName().size() != m_config.m_caName.size() + IS_SUBNAME_MIN_OFFSET) { |
| 231 | _LOG_ERROR("Invalid self-signed certificate name " << clientCert->getName()); |
| 232 | return; |
| 233 | } |
| 234 | if (!security::verifySignature(*clientCert, *clientCert)) { |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 235 | _LOG_TRACE("Cert request with bad signature."); |
| 236 | return; |
| 237 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 238 | if (!security::verifySignature(request, *clientCert)) { |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 239 | _LOG_TRACE("Interest with bad signature."); |
| 240 | return; |
| 241 | } |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 242 | if (probeToken != nullptr) { |
| 243 | const auto& pib = m_keyChain.getPib(); |
| 244 | const auto& key = pib.getIdentity(m_config.m_caName).getDefaultKey(); |
| 245 | const auto& caCert = key.getDefaultCertificate(); |
| 246 | if (!security::verifySignature(*probeToken, caCert)) { |
Zhiyi Zhang | a1fc623 | 2019-06-13 14:56:59 -0700 | [diff] [blame] | 247 | _LOG_TRACE("PROBE Token with bad signature."); |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 248 | return; |
| 249 | } |
| 250 | } |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 251 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 252 | // create new request instance |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 253 | std::string requestId = std::to_string(random::generateWord64()); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 254 | CertificateRequest certRequest(m_config.m_caName, requestId, STATUS_BEFORE_CHALLENGE, *clientCert); |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 255 | if (probeToken != nullptr) { |
| 256 | certRequest.setProbeToken(probeToken); |
| 257 | } |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 258 | try { |
| 259 | m_storage->addRequest(certRequest); |
| 260 | } |
| 261 | catch (const std::exception& e) { |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 262 | _LOG_TRACE("Cannot add new request instance into the storage " << e.what()); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 263 | return; |
| 264 | } |
| 265 | |
| 266 | Data result; |
| 267 | result.setName(request.getName()); |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 268 | result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 269 | result.setContent(dataContentFromJson(genNewResponseJson(myEcdhPubKeyBase64, |
| 270 | std::to_string(saltInt), |
| 271 | certRequest, |
| 272 | m_config.m_supportedChallenges))); |
| 273 | m_keyChain.sign(result, signingByIdentity(m_config.m_caName)); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 274 | m_face.put(result); |
Zhiyi Zhang | a63b737 | 2017-05-17 14:14:34 -0700 | [diff] [blame] | 275 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 276 | if (m_config.m_statusUpdateCallback) { |
| 277 | m_config.m_statusUpdateCallback(certRequest); |
Zhiyi Zhang | 7420cf5 | 2017-12-18 18:59:21 +0800 | [diff] [blame] | 278 | } |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 282 | CaModule::onChallenge(const Interest& request) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 283 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 284 | // get certificate request state |
| 285 | CertificateRequest certRequest = getCertificateRequest(request); |
| 286 | if (certRequest.m_requestId == "") { |
| 287 | // cannot get the request state |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 288 | return; |
| 289 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 290 | // verify signature |
| 291 | if (!security::verifySignature(request, certRequest.m_cert)) { |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 292 | _LOG_TRACE("Interest with bad signature."); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 293 | return; |
| 294 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 295 | // decrypt the parameters |
| 296 | auto paramJsonPayload = parseEncBlock(m_ecdh.context->sharedSecret, |
| 297 | m_ecdh.context->sharedSecretLen, |
| 298 | request.getApplicationParameters()); |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 299 | if (paramJsonPayload.size() == 0) { |
| 300 | _LOG_ERROR("Got an empty buffer from content decryption."); |
| 301 | return; |
| 302 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 303 | std::string paramJsonStr((const char*)paramJsonPayload.data(), paramJsonPayload.size()); |
| 304 | std::istringstream ss(paramJsonStr); |
| 305 | JsonSection paramJson; |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 306 | try { |
| 307 | boost::property_tree::json_parser::read_json(ss, paramJson); |
| 308 | } |
| 309 | catch (const std::exception& e) { |
| 310 | _LOG_ERROR("Cannot read JSON from decrypted content " << e.what()); |
| 311 | return; |
| 312 | } |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 313 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 314 | // load the corresponding challenge module |
| 315 | std::string challengeType = paramJson.get<std::string>(JSON_CLIENT_SELECTED_CHALLENGE); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 316 | auto challenge = ChallengeModule::createChallengeModule(challengeType); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 317 | JsonSection contentJson; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 318 | if (challenge == nullptr) { |
| 319 | _LOG_TRACE("Unrecognized challenge type " << challengeType); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 320 | certRequest.m_status = STATUS_FAILURE; |
| 321 | certRequest.m_challengeStatus = CHALLENGE_STATUS_UNKNOWN_CHALLENGE; |
| 322 | contentJson = genChallengeResponseJson(certRequest); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 323 | } |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 324 | else { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 325 | _LOG_TRACE("CHALLENGE module to be load: " << challengeType); |
| 326 | // let challenge module handle the request |
| 327 | challenge->handleChallengeRequest(paramJson, certRequest); |
| 328 | if (certRequest.m_status == STATUS_FAILURE) { |
| 329 | // if challenge failed |
| 330 | m_storage->deleteRequest(certRequest.m_requestId); |
| 331 | contentJson = genChallengeResponseJson(certRequest); |
| 332 | _LOG_TRACE("Challenge failed"); |
Zhiyi Zhang | a9bda73 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 333 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 334 | else if (certRequest.m_status == STATUS_PENDING) { |
| 335 | // if challenge succeeded |
| 336 | auto issuedCert = issueCertificate(certRequest); |
| 337 | certRequest.m_cert = issuedCert; |
| 338 | certRequest.m_status = STATUS_SUCCESS; |
| 339 | try { |
| 340 | m_storage->addCertificate(certRequest.m_requestId, issuedCert); |
| 341 | m_storage->deleteRequest(certRequest.m_requestId); |
| 342 | _LOG_TRACE("New Certificate Issued " << issuedCert.getName()); |
| 343 | } |
| 344 | catch (const std::exception& e) { |
| 345 | _LOG_ERROR("Cannot add issued cert and remove the request " << e.what()); |
| 346 | return; |
| 347 | } |
| 348 | if (m_config.m_statusUpdateCallback) { |
| 349 | m_config.m_statusUpdateCallback(certRequest); |
| 350 | } |
| 351 | contentJson = genChallengeResponseJson(certRequest); |
| 352 | contentJson.add(JSON_CA_CERT_ID, readString(issuedCert.getName().at(-1))); |
| 353 | _LOG_TRACE("Challenge succeeded. Certificate has been issued"); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 354 | } |
| 355 | else { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 356 | try { |
| 357 | m_storage->updateRequest(certRequest); |
| 358 | } |
| 359 | catch (const std::exception& e) { |
| 360 | _LOG_TRACE("Cannot update request instance " << e.what()); |
| 361 | return; |
| 362 | } |
| 363 | contentJson = genChallengeResponseJson(certRequest); |
| 364 | _LOG_TRACE("No failure no success. Challenge moves on"); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 365 | } |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 366 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 367 | |
| 368 | Data result; |
| 369 | result.setName(request.getName()); |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 370 | result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 371 | |
| 372 | // encrypt the content |
| 373 | std::stringstream ss2; |
| 374 | boost::property_tree::write_json(ss2, contentJson); |
| 375 | auto payload = ss2.str(); |
| 376 | auto contentBlock = genEncBlock(tlv::Content, m_ecdh.context->sharedSecret, |
| 377 | m_ecdh.context->sharedSecretLen, |
| 378 | (const uint8_t*)payload.c_str(), payload.size()); |
| 379 | result.setContent(contentBlock); |
| 380 | m_keyChain.sign(result, signingByIdentity(m_config.m_caName)); |
| 381 | m_face.put(result); |
| 382 | |
| 383 | if (m_config.m_statusUpdateCallback) { |
| 384 | m_config.m_statusUpdateCallback(certRequest); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 385 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | void |
| 389 | CaModule::onDownload(const Interest& request) |
| 390 | { |
| 391 | auto requestId = readString(request.getName().at(-1)); |
| 392 | security::v2::Certificate signedCert; |
| 393 | try { |
| 394 | signedCert = m_storage->getCertificate(requestId); |
| 395 | } |
| 396 | catch (const std::exception& e) { |
| 397 | _LOG_ERROR("Cannot read signed cert " << requestId << " from ca database " << e.what()); |
| 398 | return; |
| 399 | } |
| 400 | Data result; |
| 401 | result.setName(request.getName()); |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 402 | result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 403 | result.setContent(signedCert.wireEncode()); |
| 404 | m_keyChain.sign(result, signingByIdentity(m_config.m_caName)); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 405 | m_face.put(result); |
| 406 | } |
| 407 | |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 408 | security::v2::Certificate |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 409 | CaModule::issueCertificate(const CertificateRequest& certRequest) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 410 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 411 | auto expectedPeriod = |
| 412 | certRequest.m_cert.getValidityPeriod().getPeriod(); |
| 413 | |
| 414 | time::system_clock::TimePoint startingTime, endingTime; |
| 415 | if (expectedPeriod.first > time::system_clock::now() |
| 416 | && expectedPeriod.first < time::system_clock::now() |
| 417 | + m_config.m_validityPeriod) |
| 418 | { |
| 419 | startingTime = expectedPeriod.first; |
| 420 | } |
| 421 | else { |
| 422 | startingTime = time::system_clock::now(); |
| 423 | } |
| 424 | if (expectedPeriod.second < time::system_clock::now() + m_config.m_validityPeriod) { |
| 425 | endingTime = expectedPeriod.second; |
| 426 | } |
| 427 | else { |
| 428 | endingTime = time::system_clock::now() + m_config.m_validityPeriod; |
| 429 | } |
| 430 | security::ValidityPeriod period(startingTime, endingTime); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 431 | security::v2::Certificate newCert; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 432 | |
| 433 | Name certName = certRequest.m_cert.getKeyName(); |
| 434 | certName.append("NDNCERT").append(std::to_string(random::generateSecureWord64())); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 435 | newCert.setName(certName); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 436 | newCert.setContent(certRequest.m_cert.getContent()); |
| 437 | _LOG_TRACE("cert request content " << certRequest.m_cert); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 438 | SignatureInfo signatureInfo; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 439 | signatureInfo.setValidityPeriod(period); |
Zhiyi Zhang | ad6cf93 | 2017-10-26 16:19:15 -0700 | [diff] [blame] | 440 | security::SigningInfo signingInfo(security::SigningInfo::SIGNER_TYPE_ID, |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 441 | m_config.m_caName, signatureInfo); |
| 442 | newCert.setFreshnessPeriod(m_config.m_freshnessPeriod); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 443 | |
| 444 | m_keyChain.sign(newCert, signingInfo); |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 445 | _LOG_TRACE("new cert got signed" << newCert); |
Zhiyi Zhang | 343cdfb | 2018-01-17 12:04:28 -0800 | [diff] [blame] | 446 | return newCert; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | CertificateRequest |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 450 | CaModule::getCertificateRequest(const Interest& request) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 451 | { |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 452 | std::string requestId = ""; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 453 | CertificateRequest certRequest; |
| 454 | try { |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 455 | requestId = readString(request.getName().at(m_config.m_caName.size() + 2)); |
| 456 | _LOG_TRACE("Request Id to query the database " << requestId); |
| 457 | } |
| 458 | catch (const std::exception& e) { |
| 459 | _LOG_ERROR(e.what()); |
| 460 | } |
| 461 | try { |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 462 | certRequest = m_storage->getRequest(requestId); |
| 463 | } |
| 464 | catch (const std::exception& e) { |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 465 | _LOG_ERROR(e.what()); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 466 | } |
| 467 | return certRequest; |
| 468 | } |
| 469 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 470 | /** |
| 471 | * @brief Generate JSON file to response PROBE insterest |
| 472 | * |
| 473 | * PROBE response JSON format: |
| 474 | * { |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 475 | * "name": "@p identifier" |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 476 | * } |
| 477 | */ |
| 478 | const JsonSection |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 479 | CaModule::genProbeResponseJson(const Name& identifier, const std::string& m_probe, const JsonSection& parameterJson) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 480 | { |
Zhiyi Zhang | 781a560 | 2019-06-26 19:05:04 -0700 | [diff] [blame^] | 481 | std::vector<std::string> fields; |
| 482 | std::string delimiter = ":"; |
| 483 | size_t last = 0; |
| 484 | size_t next = 0; |
| 485 | while ((next = m_probe.find(delimiter, last)) != std::string::npos) { |
| 486 | fields.push_back(m_probe.substr(last, next - last)); |
| 487 | last = next + 1; |
| 488 | } |
| 489 | fields.push_back(m_probe.substr(last)); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 490 | JsonSection root; |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 491 | |
| 492 | for (size_t i = 0; i < fields.size(); ++i) { |
Zhiyi Zhang | 781a560 | 2019-06-26 19:05:04 -0700 | [diff] [blame^] | 493 | root.put(fields.at(i), parameterJson.get(fields.at(i), "")); |
Yufeng Zhang | 424d036 | 2019-06-12 16:48:27 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 496 | root.put(JSON_CA_NAME, identifier.toUri()); |
| 497 | return root; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * @brief Generate JSON file to response NEW interest |
| 502 | * |
| 503 | * Target JSON format: |
| 504 | * { |
| 505 | * "ecdh-pub": "@p echdPub", |
| 506 | * "salt": "@p salt" |
| 507 | * "request-id": "@p requestId", |
| 508 | * "status": "@p status", |
| 509 | * "challenges": [ |
| 510 | * { |
| 511 | * "challenge-id": "" |
| 512 | * }, |
| 513 | * { |
| 514 | * "challenge-id": "" |
| 515 | * }, |
| 516 | * ... |
| 517 | * ] |
| 518 | * } |
| 519 | */ |
| 520 | const JsonSection |
| 521 | CaModule::genProbeResponseJson() |
| 522 | { |
| 523 | JsonSection root; |
| 524 | // ca-prefix |
| 525 | Name caName = m_config.m_caName; |
| 526 | root.put("ca-prefix", caName.toUri()); |
| 527 | |
| 528 | // ca-info |
| 529 | const auto& pib = m_keyChain.getPib(); |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 530 | const auto& identity = pib.getIdentity(m_config.m_caName); |
| 531 | const auto& cert = identity.getDefaultKey().getDefaultCertificate(); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 532 | std::string caInfo = ""; |
| 533 | if (m_config.m_caInfo == "") { |
| 534 | caInfo = "Issued by " + cert.getSignature().getKeyLocator().getName().toUri(); |
| 535 | } |
| 536 | else { |
| 537 | caInfo = m_config.m_caInfo; |
| 538 | } |
| 539 | root.put("ca-info", caInfo); |
| 540 | |
| 541 | // probe |
| 542 | root.put("probe", m_config.m_probe); |
| 543 | |
| 544 | // certificate |
| 545 | std::stringstream ss; |
| 546 | io::save(cert, ss); |
| 547 | root.put("certificate", ss.str()); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 548 | return root; |
| 549 | } |
| 550 | |
| 551 | const JsonSection |
| 552 | CaModule::genNewResponseJson(const std::string& ecdhKey, const std::string& salt, |
| 553 | const CertificateRequest& request, |
| 554 | const std::list<std::string>& challenges) |
| 555 | { |
| 556 | JsonSection root; |
| 557 | JsonSection challengesSection; |
| 558 | root.put(JSON_CA_ECDH, ecdhKey); |
| 559 | root.put(JSON_CA_SALT, salt); |
| 560 | root.put(JSON_CA_EQUEST_ID, request.m_requestId); |
| 561 | root.put(JSON_CA_STATUS, std::to_string(request.m_status)); |
| 562 | |
| 563 | for (const auto& entry : challenges) { |
| 564 | JsonSection challenge; |
| 565 | challenge.put(JSON_CA_CHALLENGE_ID, entry); |
| 566 | challengesSection.push_back(std::make_pair("", challenge)); |
| 567 | } |
| 568 | root.add_child(JSON_CA_CHALLENGES, challengesSection); |
| 569 | return root; |
| 570 | } |
| 571 | |
| 572 | const JsonSection |
| 573 | CaModule::genChallengeResponseJson(const CertificateRequest& request) |
| 574 | { |
| 575 | JsonSection root; |
| 576 | JsonSection challengesSection; |
| 577 | root.put(JSON_CA_STATUS, request.m_status); |
| 578 | root.put(JSON_CHALLENGE_STATUS, request.m_challengeStatus); |
| 579 | root.put(JSON_CHALLENGE_REMAINING_TRIES, std::to_string(request.m_remainingTries)); |
| 580 | root.put(JSON_CHALLENGE_REMAINING_TIME, std::to_string(request.m_remainingTime)); |
| 581 | return root; |
| 582 | } |
| 583 | |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 584 | void |
| 585 | CaModule::onRegisterFailed(const std::string& reason) |
| 586 | { |
Zhiyi Zhang | 693c127 | 2017-05-20 22:58:55 -0700 | [diff] [blame] | 587 | _LOG_ERROR("Failed to register prefix in local hub's daemon, REASON: " << reason); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | Block |
| 591 | CaModule::dataContentFromJson(const JsonSection& jsonSection) |
| 592 | { |
| 593 | std::stringstream ss; |
| 594 | boost::property_tree::write_json(ss, jsonSection); |
| 595 | return makeStringBlock(ndn::tlv::Content, ss.str()); |
| 596 | } |
| 597 | |
| 598 | JsonSection |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 599 | CaModule::jsonFromBlock(const Block& block) |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 600 | { |
| 601 | std::string jsonString; |
| 602 | try { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 603 | jsonString = encoding::readString(block); |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 604 | std::istringstream ss(jsonString); |
| 605 | JsonSection json; |
| 606 | boost::property_tree::json_parser::read_json(ss, json); |
| 607 | return json; |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 608 | } |
| 609 | catch (const std::exception& e) { |
Zhiyi Zhang | 42e1cf3 | 2019-06-22 17:11:42 -0700 | [diff] [blame] | 610 | _LOG_ERROR("Cannot read JSON string from TLV Value " << e.what()); |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 611 | return JsonSection(); |
| 612 | } |
Zhiyi Zhang | f5246c4 | 2017-01-26 09:39:20 -0800 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | } // namespace ndncert |
| 616 | } // namespace ndn |