Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 21 | #include "info-encoder.hpp" |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 22 | |
| 23 | namespace ndn { |
| 24 | namespace ndncert { |
| 25 | |
| 26 | Block |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 27 | InfoEncoder::encodeDataContent(const CaProfile& caConfig, const security::Certificate& certificate) |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 28 | { |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 29 | auto content = makeEmptyBlock(ndn::tlv::Content); |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 30 | content.push_back(makeNestedBlock(tlv::CaPrefix, caConfig.m_caPrefix)); |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 31 | std::string caInfo = ""; |
| 32 | if (caConfig.m_caInfo == "") { |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 33 | caInfo = "Issued by " + certificate.getSignatureInfo().getKeyLocator().getName().toUri(); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 34 | } |
| 35 | else { |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 36 | caInfo = caConfig.m_caInfo; |
| 37 | } |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 38 | content.push_back(makeStringBlock(tlv::CaInfo, caInfo)); |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 39 | for (const auto& key : caConfig.m_probeParameterKeys) { |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 40 | content.push_back(makeStringBlock(tlv::ParameterKey, key)); |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 41 | } |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 42 | content.push_back(makeNonNegativeIntegerBlock(tlv::MaxValidityPeriod, caConfig.m_maxValidityPeriod.count())); |
| 43 | content.push_back(makeNestedBlock(tlv::CaCertificate, certificate)); |
Suyong Won | 44d0cce | 2020-05-10 04:07:43 -0700 | [diff] [blame] | 44 | content.encode(); |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 45 | return content; |
| 46 | } |
| 47 | |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 48 | CaProfile |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 49 | InfoEncoder::decodeDataContent(const Block& block) |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 50 | { |
Zhiyi Zhang | 1d3dcd2 | 2020-10-01 22:25:43 -0700 | [diff] [blame] | 51 | CaProfile result; |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 52 | block.parse(); |
| 53 | for (auto const& item : block.elements()) { |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 54 | switch (item.type()) { |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 55 | case tlv::CaPrefix: |
Zhiyi Zhang | b940aa1 | 2020-09-30 16:38:57 -0700 | [diff] [blame] | 56 | item.parse(); |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 57 | result.m_caPrefix.wireDecode(item.get(ndn::tlv::Name)); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 58 | break; |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 59 | case tlv::CaInfo: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 60 | result.m_caInfo = readString(item); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 61 | break; |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 62 | case tlv::ParameterKey: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 63 | result.m_probeParameterKeys.push_back(readString(item)); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 64 | break; |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 65 | case tlv::MaxValidityPeriod: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 66 | result.m_maxValidityPeriod = time::seconds(readNonNegativeInteger(item)); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 67 | break; |
tylerliu | 50d679e | 2020-10-14 14:08:39 -0700 | [diff] [blame] | 68 | case tlv::CaCertificate: |
Zhiyi Zhang | b940aa1 | 2020-09-30 16:38:57 -0700 | [diff] [blame] | 69 | item.parse(); |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 70 | result.m_cert = std::make_shared<security::Certificate>(item.get(ndn::tlv::Data)); |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 71 | break; |
| 72 | default: |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 73 | continue; |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 74 | break; |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | return result; |
| 78 | } |
| 79 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 80 | } // namespace ndncert |
| 81 | } // namespace ndn |