blob: d9863a5d32890fa7674a2fbc49b83efa1562fd48 [file] [log] [blame]
Zhiyi Zhang8617a792017-01-17 16:45:56 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesaventoe5b43692021-11-15 22:05:03 -05002/*
3 * Copyright (c) 2017-2021, Regents of the University of California.
Zhiyi Zhang8617a792017-01-17 16:45:56 -08004 *
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 Zhangaeab4972020-10-22 22:20:40 -070021#ifndef NDNCERT_DETAIL_NDNCERT_COMMON_HPP
22#define NDNCERT_DETAIL_NDNCERT_COMMON_HPP
Zhiyi Zhang8617a792017-01-17 16:45:56 -080023
Zhiyi Zhang840afd92020-10-21 13:24:08 -070024#include "detail/ndncert-config.hpp"
Zhiyi Zhang8617a792017-01-17 16:45:56 -080025
tylerliudd359912020-10-20 13:05:22 -070026#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
Zhiyi Zhang8617a792017-01-17 16:45:56 -080031#else
tylerliudd359912020-10-20 13:05:22 -070032#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 Zhang8617a792017-01-17 16:45:56 -080036#endif
37
Zhiyi Zhang48f23782020-09-28 12:11:24 -070038#include <cstddef>
39#include <cstdint>
Davide Pesaventoe5b43692021-11-15 22:05:03 -050040#include <string>
41#include <tuple>
42
Zhiyi Zhang48f23782020-09-28 12:11:24 -070043#include <ndn-cxx/data.hpp>
Zhiyi Zhangaeab4972020-10-22 22:20:40 -070044#include <ndn-cxx/encoding/block.hpp>
Davide Pesavento0dc02012021-11-23 22:55:03 -050045#include <ndn-cxx/encoding/block-helpers.hpp>
Zhiyi Zhang48f23782020-09-28 12:11:24 -070046#include <ndn-cxx/interest.hpp>
Zhiyi Zhang48f23782020-09-28 12:11:24 -070047#include <ndn-cxx/name.hpp>
tylerliua7bea662020-10-08 18:51:02 -070048#include <ndn-cxx/security/certificate.hpp>
Davide Pesavento0dc02012021-11-23 22:55:03 -050049#include <ndn-cxx/util/exception.hpp>
Zhiyi Zhang523f0c22020-09-29 14:19:20 -070050#include <ndn-cxx/util/logger.hpp>
Davide Pesaventoe5b43692021-11-15 22:05:03 -050051#include <ndn-cxx/util/optional.hpp>
Davide Pesavento0dc02012021-11-23 22:55:03 -050052#include <ndn-cxx/util/time.hpp>
Davide Pesaventoe5b43692021-11-15 22:05:03 -050053
Zhiyi Zhangc87d52b2020-09-28 22:07:18 -070054#include <boost/algorithm/string.hpp>
55#include <boost/assert.hpp>
56#include <boost/noncopyable.hpp>
Zhiyi Zhanga749f442020-09-29 17:19:51 -070057#include <boost/property_tree/ptree.hpp>
Zhiyi Zhang8617a792017-01-17 16:45:56 -080058
Zhiyi Zhang8617a792017-01-17 16:45:56 -080059namespace ndncert {
60
Davide Pesavento0dc02012021-11-23 22:55:03 -050061using ndn::Block;
62using ndn::Data;
63using ndn::Interest;
64using ndn::Name;
65using ndn::SignatureInfo;
66using ndn::security::Certificate;
67
68using ndn::optional;
69using ndn::nullopt;
70
71namespace time = ndn::time;
72using namespace ndn::time_literals;
73using namespace std::string_literals;
74
Zhiyi Zhang8f1ade32020-10-14 16:42:57 -070075namespace tlv {
76
77enum : uint32_t {
78 CaPrefix = 129,
79 CaInfo = 131,
80 ParameterKey = 133,
81 ParameterValue = 135,
82 CaCertificate = 137,
83 MaxValidityPeriod = 139,
84 ProbeResponse = 141,
85 MaxSuffixLength = 143,
86 EcdhPub = 145,
87 CertRequest = 147,
88 Salt = 149,
89 RequestId = 151,
90 Challenge = 153,
91 Status = 155,
92 InitializationVector = 157,
93 EncryptedPayload = 159,
94 SelectedChallenge = 161,
95 ChallengeStatus = 163,
96 RemainingTries = 165,
97 RemainingTime = 167,
98 IssuedCertName = 169,
99 ErrorCode = 171,
100 ErrorInfo = 173,
101 AuthenticationTag = 175,
102 CertToRevoke = 177,
103 ProbeRedirect = 179
104};
105
106} // namespace tlv
107
Davide Pesaventoe5b43692021-11-15 22:05:03 -0500108using JsonSection = boost::property_tree::ptree;
Zhiyi Zhang8617a792017-01-17 16:45:56 -0800109
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700110// NDNCERT error code
tylerliu96a67e82020-10-15 13:37:12 -0700111enum class ErrorCode : uint64_t {
Zhiyi Zhang46049832020-09-28 17:08:12 -0700112 NO_ERROR = 0,
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700113 BAD_INTEREST_FORMAT = 1,
114 BAD_PARAMETER_FORMAT = 2,
115 BAD_SIGNATURE = 3,
116 INVALID_PARAMETER = 4,
117 NAME_NOT_ALLOWED = 5,
118 BAD_VALIDITY_PERIOD = 6,
119 OUT_OF_TRIES = 7,
120 OUT_OF_TIME = 8,
121 NO_AVAILABLE_NAMES = 9
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700122};
123
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700124// Convert error code to string
tylerliu96a67e82020-10-15 13:37:12 -0700125std::ostream&
126operator<<(std::ostream& os, ErrorCode code);
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700127
128// NDNCERT request type
tylerliu96a67e82020-10-15 13:37:12 -0700129enum class RequestType : uint64_t {
Zhiyi Zhangc87d52b2020-09-28 22:07:18 -0700130 NOTINITIALIZED = 0,
131 NEW = 1,
132 RENEW = 2,
133 REVOKE = 3
134};
135
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700136// Convert request type to string
tylerliu96a67e82020-10-15 13:37:12 -0700137std::ostream&
138operator<<(std::ostream& out, RequestType type);
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700139
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700140} // namespace ndncert
Zhiyi Zhang8617a792017-01-17 16:45:56 -0800141
Zhiyi Zhangaeab4972020-10-22 22:20:40 -0700142#endif // NDNCERT_DETAIL_NDNCERT_COMMON_HPP