Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -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 | /* |
Davide Pesavento | 9510c91 | 2024-02-25 17:50:05 -0500 | [diff] [blame] | 3 | * Copyright (c) 2017-2024, Regents of the University of California. |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -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 | |
Zhiyi Zhang | aeab497 | 2020-10-22 22:20:40 -0700 | [diff] [blame] | 21 | #ifndef NDNCERT_DETAIL_NDNCERT_COMMON_HPP |
| 22 | #define NDNCERT_DETAIL_NDNCERT_COMMON_HPP |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 23 | |
Zhiyi Zhang | 840afd9 | 2020-10-21 13:24:08 -0700 | [diff] [blame] | 24 | #include "detail/ndncert-config.hpp" |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 25 | |
Davide Pesavento | 9510c91 | 2024-02-25 17:50:05 -0500 | [diff] [blame] | 26 | #ifdef NDNCERT_WITH_TESTS |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 27 | #define NDNCERT_VIRTUAL_WITH_TESTS virtual |
| 28 | #define NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED public |
| 29 | #define NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE public |
| 30 | #define NDNCERT_PROTECTED_WITH_TESTS_ELSE_PRIVATE protected |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 31 | #else |
tylerliu | dd35991 | 2020-10-20 13:05:22 -0700 | [diff] [blame] | 32 | #define NDNCERT_VIRTUAL_WITH_TESTS |
| 33 | #define NDNCERT_PUBLIC_WITH_TESTS_ELSE_PROTECTED protected |
| 34 | #define NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE private |
| 35 | #define NDNCERT_PROTECTED_WITH_TESTS_ELSE_PRIVATE private |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 36 | #endif |
| 37 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 38 | #include <cstddef> |
| 39 | #include <cstdint> |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 40 | #include <memory> |
Davide Pesavento | 9510c91 | 2024-02-25 17:50:05 -0500 | [diff] [blame] | 41 | #include <stdexcept> |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 42 | #include <string> |
Davide Pesavento | 0d1d11c | 2022-04-11 22:11:34 -0400 | [diff] [blame] | 43 | #include <vector> |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 44 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 45 | #include <ndn-cxx/data.hpp> |
Zhiyi Zhang | aeab497 | 2020-10-22 22:20:40 -0700 | [diff] [blame] | 46 | #include <ndn-cxx/encoding/block.hpp> |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 47 | #include <ndn-cxx/encoding/block-helpers.hpp> |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 48 | #include <ndn-cxx/interest.hpp> |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 49 | #include <ndn-cxx/name.hpp> |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 50 | #include <ndn-cxx/security/certificate.hpp> |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 51 | #include <ndn-cxx/util/exception.hpp> |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 52 | #include <ndn-cxx/util/time.hpp> |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 53 | |
Zhiyi Zhang | c87d52b | 2020-09-28 22:07:18 -0700 | [diff] [blame] | 54 | #include <boost/assert.hpp> |
Davide Pesavento | 9510c91 | 2024-02-25 17:50:05 -0500 | [diff] [blame] | 55 | #include <boost/core/noncopyable.hpp> |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 56 | #include <boost/property_tree/ptree.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 57 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 58 | namespace ndncert { |
| 59 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 60 | using ndn::Block; |
| 61 | using ndn::Data; |
| 62 | using ndn::Interest; |
| 63 | using ndn::Name; |
| 64 | using ndn::SignatureInfo; |
| 65 | using ndn::security::Certificate; |
| 66 | |
Davide Pesavento | 0dc0201 | 2021-11-23 22:55:03 -0500 | [diff] [blame] | 67 | namespace time = ndn::time; |
| 68 | using namespace ndn::time_literals; |
| 69 | using namespace std::string_literals; |
| 70 | |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 71 | namespace tlv { |
| 72 | |
| 73 | enum : uint32_t { |
| 74 | CaPrefix = 129, |
| 75 | CaInfo = 131, |
| 76 | ParameterKey = 133, |
| 77 | ParameterValue = 135, |
| 78 | CaCertificate = 137, |
| 79 | MaxValidityPeriod = 139, |
| 80 | ProbeResponse = 141, |
| 81 | MaxSuffixLength = 143, |
| 82 | EcdhPub = 145, |
| 83 | CertRequest = 147, |
| 84 | Salt = 149, |
| 85 | RequestId = 151, |
| 86 | Challenge = 153, |
| 87 | Status = 155, |
| 88 | InitializationVector = 157, |
| 89 | EncryptedPayload = 159, |
| 90 | SelectedChallenge = 161, |
| 91 | ChallengeStatus = 163, |
| 92 | RemainingTries = 165, |
| 93 | RemainingTime = 167, |
| 94 | IssuedCertName = 169, |
| 95 | ErrorCode = 171, |
| 96 | ErrorInfo = 173, |
| 97 | AuthenticationTag = 175, |
| 98 | CertToRevoke = 177, |
Davide Pesavento | 9510c91 | 2024-02-25 17:50:05 -0500 | [diff] [blame] | 99 | ProbeRedirect = 179, |
Zhiyi Zhang | 8f1ade3 | 2020-10-14 16:42:57 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } // namespace tlv |
| 103 | |
Davide Pesavento | e5b4369 | 2021-11-15 22:05:03 -0500 | [diff] [blame] | 104 | using JsonSection = boost::property_tree::ptree; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 105 | |
Zhiyi Zhang | 4b11809 | 2020-10-10 10:28:38 -0700 | [diff] [blame] | 106 | // NDNCERT error code |
tylerliu | 96a67e8 | 2020-10-15 13:37:12 -0700 | [diff] [blame] | 107 | enum class ErrorCode : uint64_t { |
Zhiyi Zhang | 4604983 | 2020-09-28 17:08:12 -0700 | [diff] [blame] | 108 | NO_ERROR = 0, |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 109 | BAD_INTEREST_FORMAT = 1, |
| 110 | BAD_PARAMETER_FORMAT = 2, |
| 111 | BAD_SIGNATURE = 3, |
| 112 | INVALID_PARAMETER = 4, |
| 113 | NAME_NOT_ALLOWED = 5, |
| 114 | BAD_VALIDITY_PERIOD = 6, |
| 115 | OUT_OF_TRIES = 7, |
| 116 | OUT_OF_TIME = 8, |
Davide Pesavento | 9510c91 | 2024-02-25 17:50:05 -0500 | [diff] [blame] | 117 | NO_AVAILABLE_NAMES = 9, |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Zhiyi Zhang | 4b11809 | 2020-10-10 10:28:38 -0700 | [diff] [blame] | 120 | // Convert error code to string |
tylerliu | 96a67e8 | 2020-10-15 13:37:12 -0700 | [diff] [blame] | 121 | std::ostream& |
| 122 | operator<<(std::ostream& os, ErrorCode code); |
Zhiyi Zhang | 4b11809 | 2020-10-10 10:28:38 -0700 | [diff] [blame] | 123 | |
| 124 | // NDNCERT request type |
tylerliu | 96a67e8 | 2020-10-15 13:37:12 -0700 | [diff] [blame] | 125 | enum class RequestType : uint64_t { |
Zhiyi Zhang | c87d52b | 2020-09-28 22:07:18 -0700 | [diff] [blame] | 126 | NOTINITIALIZED = 0, |
| 127 | NEW = 1, |
| 128 | RENEW = 2, |
Davide Pesavento | 9510c91 | 2024-02-25 17:50:05 -0500 | [diff] [blame] | 129 | REVOKE = 3, |
Zhiyi Zhang | c87d52b | 2020-09-28 22:07:18 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
Zhiyi Zhang | 4b11809 | 2020-10-10 10:28:38 -0700 | [diff] [blame] | 132 | // Convert request type to string |
tylerliu | 96a67e8 | 2020-10-15 13:37:12 -0700 | [diff] [blame] | 133 | std::ostream& |
| 134 | operator<<(std::ostream& out, RequestType type); |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 135 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 136 | } // namespace ndncert |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 137 | |
Zhiyi Zhang | aeab497 | 2020-10-22 22:20:40 -0700 | [diff] [blame] | 138 | #endif // NDNCERT_DETAIL_NDNCERT_COMMON_HPP |