Zhiyi Zhang | 63589b8 | 2020-10-10 10:27:09 -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 | |
| 21 | #ifndef NDNCERT_DETAIL_NDNCERT_COMMON_HPP |
| 22 | #define NDNCERT_DETAIL_NDNCERT_COMMON_HPP |
| 23 | |
| 24 | #include "detail/ndncert-config.hpp" |
| 25 | |
| 26 | #ifdef NDNCERT_HAVE_TESTS |
| 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 |
| 31 | #else |
| 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 |
| 36 | #endif |
| 37 | |
| 38 | #include <cstddef> |
| 39 | #include <cstdint> |
| 40 | #include <ndn-cxx/data.hpp> |
| 41 | #include <ndn-cxx/encoding/block-helpers.hpp> |
| 42 | #include <ndn-cxx/encoding/block.hpp> |
| 43 | #include <ndn-cxx/encoding/tlv.hpp> |
| 44 | #include <ndn-cxx/face.hpp> |
| 45 | #include <ndn-cxx/interest.hpp> |
| 46 | #include <ndn-cxx/lp/nack.hpp> |
| 47 | #include <ndn-cxx/name.hpp> |
| 48 | #include <ndn-cxx/security/certificate.hpp> |
| 49 | #include <ndn-cxx/security/key-chain.hpp> |
| 50 | #include <ndn-cxx/util/logger.hpp> |
| 51 | #include <tuple> |
| 52 | #include <boost/algorithm/string.hpp> |
| 53 | #include <boost/assert.hpp> |
| 54 | #include <boost/noncopyable.hpp> |
| 55 | #include <boost/property_tree/info_parser.hpp> |
| 56 | #include <boost/property_tree/json_parser.hpp> |
| 57 | #include <boost/property_tree/ptree.hpp> |
| 58 | |
| 59 | namespace ndn { |
| 60 | namespace ndncert { |
| 61 | |
| 62 | namespace tlv { |
| 63 | |
| 64 | enum : uint32_t { |
| 65 | CaPrefix = 129, |
| 66 | CaInfo = 131, |
| 67 | ParameterKey = 133, |
| 68 | ParameterValue = 135, |
| 69 | CaCertificate = 137, |
| 70 | MaxValidityPeriod = 139, |
| 71 | ProbeResponse = 141, |
| 72 | MaxSuffixLength = 143, |
| 73 | EcdhPub = 145, |
| 74 | CertRequest = 147, |
| 75 | Salt = 149, |
| 76 | RequestId = 151, |
| 77 | Challenge = 153, |
| 78 | Status = 155, |
| 79 | InitializationVector = 157, |
| 80 | EncryptedPayload = 159, |
| 81 | SelectedChallenge = 161, |
| 82 | ChallengeStatus = 163, |
| 83 | RemainingTries = 165, |
| 84 | RemainingTime = 167, |
| 85 | IssuedCertName = 169, |
| 86 | ErrorCode = 171, |
| 87 | ErrorInfo = 173, |
| 88 | AuthenticationTag = 175, |
| 89 | CertToRevoke = 177, |
| 90 | ProbeRedirect = 179 |
| 91 | }; |
| 92 | |
| 93 | } // namespace tlv |
| 94 | |
| 95 | using boost::noncopyable; |
| 96 | typedef boost::property_tree::ptree JsonSection; |
| 97 | |
| 98 | // NDNCERT error code |
| 99 | enum class ErrorCode : uint64_t { |
| 100 | NO_ERROR = 0, |
| 101 | BAD_INTEREST_FORMAT = 1, |
| 102 | BAD_PARAMETER_FORMAT = 2, |
| 103 | BAD_SIGNATURE = 3, |
| 104 | INVALID_PARAMETER = 4, |
| 105 | NAME_NOT_ALLOWED = 5, |
| 106 | BAD_VALIDITY_PERIOD = 6, |
| 107 | OUT_OF_TRIES = 7, |
| 108 | OUT_OF_TIME = 8, |
| 109 | NO_AVAILABLE_NAMES = 9 |
| 110 | }; |
| 111 | |
| 112 | // Convert error code to string |
| 113 | std::ostream& |
| 114 | operator<<(std::ostream& os, ErrorCode code); |
| 115 | |
| 116 | // NDNCERT request type |
| 117 | enum class RequestType : uint64_t { |
| 118 | NOTINITIALIZED = 0, |
| 119 | NEW = 1, |
| 120 | RENEW = 2, |
| 121 | REVOKE = 3 |
| 122 | }; |
| 123 | |
| 124 | // Convert request type to string |
| 125 | std::ostream& |
| 126 | operator<<(std::ostream& out, RequestType type); |
| 127 | |
| 128 | } // namespace ndncert |
| 129 | } // namespace ndn |
| 130 | |
| 131 | #endif // NDNCERT_DETAIL_NDNCERT_COMMON_HPP |