blob: 0e1b392958f304865c2d986af3865b135c3e641d [file] [log] [blame]
Zhiyi Zhang8617a792017-01-17 16:45:56 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -07003 * Copyright (c) 2017-2020, 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>
40#include <ndn-cxx/data.hpp>
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070041#include <ndn-cxx/encoding/block-helpers.hpp>
Zhiyi Zhangaeab4972020-10-22 22:20:40 -070042#include <ndn-cxx/encoding/block.hpp>
43#include <ndn-cxx/encoding/tlv.hpp>
Zhiyi Zhang48f23782020-09-28 12:11:24 -070044#include <ndn-cxx/face.hpp>
45#include <ndn-cxx/interest.hpp>
Zhiyi Zhang48f23782020-09-28 12:11:24 -070046#include <ndn-cxx/lp/nack.hpp>
47#include <ndn-cxx/name.hpp>
tylerliua7bea662020-10-08 18:51:02 -070048#include <ndn-cxx/security/certificate.hpp>
Zhiyi Zhangaeab4972020-10-22 22:20:40 -070049#include <ndn-cxx/security/key-chain.hpp>
Zhiyi Zhang523f0c22020-09-29 14:19:20 -070050#include <ndn-cxx/util/logger.hpp>
Zhiyi Zhang997669a2020-10-28 21:15:40 -070051#include <ndn-cxx/util/nonstd/optional.hpp>
Zhiyi Zhangaeab4972020-10-22 22:20:40 -070052#include <tuple>
Zhiyi Zhangc87d52b2020-09-28 22:07:18 -070053#include <boost/algorithm/string.hpp>
54#include <boost/assert.hpp>
55#include <boost/noncopyable.hpp>
Zhiyi Zhanga749f442020-09-29 17:19:51 -070056#include <boost/property_tree/info_parser.hpp>
57#include <boost/property_tree/json_parser.hpp>
58#include <boost/property_tree/ptree.hpp>
Zhiyi Zhang8617a792017-01-17 16:45:56 -080059
60namespace ndn {
61namespace ndncert {
62
Zhiyi Zhang8f1ade32020-10-14 16:42:57 -070063namespace tlv {
64
65enum : uint32_t {
66 CaPrefix = 129,
67 CaInfo = 131,
68 ParameterKey = 133,
69 ParameterValue = 135,
70 CaCertificate = 137,
71 MaxValidityPeriod = 139,
72 ProbeResponse = 141,
73 MaxSuffixLength = 143,
74 EcdhPub = 145,
75 CertRequest = 147,
76 Salt = 149,
77 RequestId = 151,
78 Challenge = 153,
79 Status = 155,
80 InitializationVector = 157,
81 EncryptedPayload = 159,
82 SelectedChallenge = 161,
83 ChallengeStatus = 163,
84 RemainingTries = 165,
85 RemainingTime = 167,
86 IssuedCertName = 169,
87 ErrorCode = 171,
88 ErrorInfo = 173,
89 AuthenticationTag = 175,
90 CertToRevoke = 177,
91 ProbeRedirect = 179
92};
93
94} // namespace tlv
95
Zhiyi Zhang8617a792017-01-17 16:45:56 -080096using boost::noncopyable;
Zhiyi Zhang59812232020-10-12 13:11:35 -070097typedef boost::property_tree::ptree JsonSection;
Zhiyi Zhang8617a792017-01-17 16:45:56 -080098
Zhiyi Zhang4b118092020-10-10 10:28:38 -070099// NDNCERT error code
tylerliu96a67e82020-10-15 13:37:12 -0700100enum class ErrorCode : uint64_t {
Zhiyi Zhang46049832020-09-28 17:08:12 -0700101 NO_ERROR = 0,
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700102 BAD_INTEREST_FORMAT = 1,
103 BAD_PARAMETER_FORMAT = 2,
104 BAD_SIGNATURE = 3,
105 INVALID_PARAMETER = 4,
106 NAME_NOT_ALLOWED = 5,
107 BAD_VALIDITY_PERIOD = 6,
108 OUT_OF_TRIES = 7,
109 OUT_OF_TIME = 8,
110 NO_AVAILABLE_NAMES = 9
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700111};
112
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700113// Convert error code to string
tylerliu96a67e82020-10-15 13:37:12 -0700114std::ostream&
115operator<<(std::ostream& os, ErrorCode code);
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700116
117// NDNCERT request type
tylerliu96a67e82020-10-15 13:37:12 -0700118enum class RequestType : uint64_t {
Zhiyi Zhangc87d52b2020-09-28 22:07:18 -0700119 NOTINITIALIZED = 0,
120 NEW = 1,
121 RENEW = 2,
122 REVOKE = 3
123};
124
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700125// Convert request type to string
tylerliu96a67e82020-10-15 13:37:12 -0700126std::ostream&
127operator<<(std::ostream& out, RequestType type);
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700128
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700129} // namespace ndncert
130} // namespace ndn
Zhiyi Zhang8617a792017-01-17 16:45:56 -0800131
Zhiyi Zhangaeab4972020-10-22 22:20:40 -0700132#endif // NDNCERT_DETAIL_NDNCERT_COMMON_HPP